Skip to content

Commit 170f416

Browse files
uilianriesmadebr
authored andcommitted
Add external patch
Signed-off-by: Uilian Ries <uilianries@gmail.com>
1 parent 774d6b5 commit 170f416

File tree

3 files changed

+68
-24
lines changed

3 files changed

+68
-24
lines changed

recipes/brotli/all/conandata.yml

+4
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ sources:
22
"1.0.7":
33
url: https://github.com/google/brotli/archive/v1.0.7.tar.gz
44
sha256: 4c61bfb0faca87219ea587326c467b95acb25555b53d1a421ffa3c8a9296ee2c
5+
patches:
6+
"1.0.7":
7+
- base_path: "source_subfolder"
8+
patch_file: "patches/0001-target-props.patch"

recipes/brotli/all/conanfile.py

+7-24
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
class BrotliConan(ConanFile):
66
name = "brotli"
7-
description = "Brotli is a generic-purpose lossless compression algorithm that compresses data using a combination of a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling, with a compression ratio comparable to the best currently available general-purpose compression methods. It is similar in speed with deflate but offers more dense compression."
8-
topics = ("conan", "snappy", "google", "compressor", "decompressor")
7+
description = "Brotli compression format"
98
url = "https://github.com/conan-io/conan-center-index"
109
homepage = "https://github.com/google/brotli"
1110
license = "MIT",
12-
exports_sources = "CMakeLists.txt",
11+
exports_sources = ["CMakeLists.txt", "patches/*"]
1312
generators = "cmake",
1413
settings = "os", "arch", "compiler", "build_type"
1514
options = {
@@ -37,23 +36,6 @@ def source(self):
3736
extracted_folder = "brotli-{}".format(self.version)
3837
os.rename(extracted_folder, self._source_subfolder)
3938

40-
def _patch_sources(self):
41-
# avoid building and installing static libraries if shared build and vice versa
42-
cmakefile = os.path.join(self._source_subfolder, "CMakeLists.txt")
43-
tools.save(cmakefile,
44-
"set_target_properties(brotli PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT ON)\n", append=True)
45-
for lib in self._get_libraries(not self.options.shared):
46-
tools.save(cmakefile,
47-
"set_target_properties({} PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT ON)\n".format(lib), append=True)
48-
shared_libraries_cmake = "${BROTLI_LIBRARIES_CORE}"
49-
static_libraries_cmake = "${BROTLI_LIBRARIES_CORE_STATIC}"
50-
tools.replace_in_file(cmakefile,
51-
"TARGETS {}".format(static_libraries_cmake if self.options.shared else shared_libraries_cmake),
52-
"TARGETS {}".format(shared_libraries_cmake if self.options.shared else static_libraries_cmake),)
53-
tools.replace_in_file(cmakefile,
54-
"TARGETS brotli",
55-
"TARGETS {}".format(shared_libraries_cmake if self.options.shared else static_libraries_cmake),)
56-
5739
def _configure_cmake(self):
5840
cmake = CMake(self)
5941
cmake.definitions["BROTLI_BUNDLED_MODE"] = False
@@ -62,15 +44,15 @@ def _configure_cmake(self):
6244
return cmake
6345

6446
def build(self):
65-
self._patch_sources()
47+
for patch in self.conan_data["patches"][self.version]:
48+
tools.patch(**patch)
6649
cmake = self._configure_cmake()
6750
cmake.build()
6851

6952
def package(self):
7053
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
7154
cmake = self._configure_cmake()
7255
cmake.install()
73-
7456
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
7557

7658
def _get_libraries(self, shared):
@@ -82,7 +64,8 @@ def _get_libraries(self, shared):
8264
def package_info(self):
8365
self.cpp_info.name = "Brotli"
8466
self.cpp_info.libs = self._get_libraries(self.options.shared)
85-
self.cpp_info.includedirs = [os.path.join(self.package_folder, "include"),
86-
os.path.join(self.package_folder, "include", "brotli")]
67+
self.cpp_info.includedirs = ["include", os.path.join("include", "brotli")]
8768
if self.options.shared:
8869
self.cpp_info.defines.append("BROTLI_SHARED_COMPILATION")
70+
if self.settings.os == "Linux":
71+
self.cpp_info.system_libs = ["m"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index fc45f80..d6b69f3 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -152,8 +152,17 @@ foreach(lib brotlicommon brotlidec brotlienc)
6+
target_compile_definitions(${lib} PUBLIC "BROTLI_SHARED_COMPILATION" )
7+
string(TOUPPER "${lib}" LIB)
8+
set_target_properties (${lib} PROPERTIES DEFINE_SYMBOL "${LIB}_SHARED_COMPILATION" )
9+
+ if (NOT BUILD_SHARED_LIBS)
10+
+ set_target_properties(${lib} PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT ON)
11+
+ endif()
12+
endforeach()
13+
14+
+if (BUILD_SHARED_LIBS)
15+
+ foreach(lib brotlienc-static brotlidec-static brotlicommon-static)
16+
+ set_target_properties(${lib} PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT ON)
17+
+ endforeach()
18+
+endif()
19+
+
20+
foreach(lib brotlicommon brotlidec brotlienc brotlicommon-static brotlidec-static brotlienc-static)
21+
target_link_libraries(${lib} ${LIBM_LIBRARY})
22+
set_property(TARGET ${lib} APPEND PROPERTY INCLUDE_DIRECTORIES ${BROTLI_INCLUDE_DIRS})
23+
@@ -184,27 +193,33 @@ endif()
24+
# Build the brotli executable
25+
add_executable(brotli ${BROTLI_CLI_C})
26+
target_link_libraries(brotli ${BROTLI_LIBRARIES_STATIC})
27+
+set_target_properties(brotli PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT ON)
28+
+
29+
30+
# Installation
31+
if(NOT BROTLI_BUNDLED_MODE)
32+
+ if (NOT)
33+
install(
34+
TARGETS brotli
35+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
36+
)
37+
+ endif()
38+
39+
+ if (BUILD_SHARED_LIBS)
40+
install(
41+
TARGETS ${BROTLI_LIBRARIES_CORE}
42+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
43+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
44+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
45+
)
46+
-
47+
+ else()
48+
install(
49+
TARGETS ${BROTLI_LIBRARIES_CORE_STATIC}
50+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
51+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
52+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
53+
)
54+
+ endif()
55+
56+
install(
57+
DIRECTORY ${BROTLI_INCLUDE_DIRS}/brotli

0 commit comments

Comments
 (0)