Skip to content

Commit 8d59878

Browse files
authored
Merge pull request #466 from madebr/brotli
Add brotli/1.0.7 recipe
2 parents 7e521d4 + 3cd4028 commit 8d59878

File tree

8 files changed

+225
-0
lines changed

8 files changed

+225
-0
lines changed

recipes/brotli/all/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 2.8.12)
2+
project(cmake_wrapper)
3+
4+
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
5+
conan_basic_setup()
6+
7+
add_subdirectory(source_subfolder)

recipes/brotli/all/conandata.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sources:
2+
"1.0.7":
3+
url: https://github.com/google/brotli/archive/v1.0.7.tar.gz
4+
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

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from conans import CMake, ConanFile, tools
2+
import os
3+
4+
5+
class BrotliConan(ConanFile):
6+
name = "brotli"
7+
description = "Brotli compression format"
8+
url = "https://github.com/conan-io/conan-center-index"
9+
homepage = "https://github.com/google/brotli"
10+
license = "MIT",
11+
exports_sources = ["CMakeLists.txt", "patches/*"]
12+
generators = "cmake",
13+
settings = "os", "arch", "compiler", "build_type"
14+
options = {
15+
"shared": [True, False],
16+
"fPIC": [True, False],
17+
}
18+
default_options = {
19+
"shared": False,
20+
"fPIC": True,
21+
}
22+
_source_subfolder = "source_subfolder"
23+
24+
def config_options(self):
25+
if self.settings.os == "Windows":
26+
del self.options.fPIC
27+
28+
def configure(self):
29+
if self.options.shared:
30+
del self.options.fPIC
31+
del self.settings.compiler.cppstd
32+
del self.settings.compiler.libcxx
33+
34+
def source(self):
35+
tools.get(**self.conan_data["sources"][self.version])
36+
extracted_folder = "brotli-{}".format(self.version)
37+
os.rename(extracted_folder, self._source_subfolder)
38+
39+
def _configure_cmake(self):
40+
cmake = CMake(self)
41+
cmake.definitions["BROTLI_BUNDLED_MODE"] = False
42+
cmake.definitions["BROTLI_DISABLE_TESTS"] = True
43+
cmake.configure()
44+
return cmake
45+
46+
def build(self):
47+
for patch in self.conan_data["patches"][self.version]:
48+
tools.patch(**patch)
49+
cmake = self._configure_cmake()
50+
cmake.build()
51+
52+
def package(self):
53+
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
54+
cmake = self._configure_cmake()
55+
cmake.install()
56+
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
57+
58+
def _get_libraries(self, shared):
59+
libs = ["brotlienc", "brotlidec", "brotlicommon"]
60+
if not shared:
61+
libs = ["{}-static".format(l) for l in libs]
62+
return libs
63+
64+
def package_info(self):
65+
self.cpp_info.names["cmake_find_package"] = "Brotli"
66+
self.cpp_info.names["cmake_find_package_multi"] = "Brotli"
67+
self.cpp_info.libs = self._get_libraries(self.options.shared)
68+
self.cpp_info.includedirs = ["include", os.path.join("include", "brotli")]
69+
if self.options.shared:
70+
self.cpp_info.defines.append("BROTLI_SHARED_COMPILATION")
71+
if self.settings.os == "Linux":
72+
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 2.8.12)
2+
project(test_package)
3+
4+
set(CMAKE_VERBOSE_MAKEFILE TRUE)
5+
6+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
7+
conan_basic_setup()
8+
9+
add_executable(${PROJECT_NAME} test_package.cpp)
10+
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from conans import ConanFile, CMake, tools
2+
import os
3+
4+
5+
class TestPackageConan(ConanFile):
6+
settings = "os", "compiler", "build_type", "arch"
7+
generators = "cmake"
8+
9+
def build(self):
10+
cmake = CMake(self)
11+
cmake.configure()
12+
cmake.build()
13+
14+
def test(self):
15+
if not tools.cross_building(self.settings):
16+
bin_path = os.path.join("bin", "test_package")
17+
self.run(bin_path, run_environment=True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <brotli/encode.h>
2+
#include <brotli/decode.h>
3+
4+
#include <cstdlib>
5+
#include <cstring>
6+
#include <string>
7+
#include <iostream>
8+
9+
int main() {
10+
std::string input = "some long text that we would like to compress if possible....";
11+
uint8_t buffer[128];
12+
size_t outputsize = sizeof(buffer);
13+
BROTLI_BOOL result = BrotliEncoderCompress(
14+
BROTLI_DEFAULT_QUALITY,
15+
BROTLI_DEFAULT_WINDOW,
16+
BROTLI_DEFAULT_MODE,
17+
input.size(),
18+
reinterpret_cast<const uint8_t*>(input.c_str()),
19+
&outputsize,
20+
buffer);
21+
if (result != BROTLI_TRUE) {
22+
std::cout << "BrotliEncoderCompress failed\n";
23+
return EXIT_FAILURE;
24+
}
25+
std::cout << "string went from " << input.size() << " bytes to " << outputsize << " bytes.\n";
26+
27+
char buffer2[128];
28+
size_t reconstructedSize = sizeof(buffer2);
29+
result = BrotliDecoderDecompress(
30+
outputsize,
31+
buffer,
32+
&reconstructedSize,
33+
reinterpret_cast<uint8_t*>(buffer2));
34+
if (result != BROTLI_TRUE) {
35+
std::cout << "BrotliDecoderDecompress failed\n";
36+
return EXIT_FAILURE;
37+
}
38+
if (reconstructedSize != input.size()) {
39+
std::cout << "Size of input (" << input.size() << ") and output (" << reconstructedSize << ") do not match\n";
40+
return EXIT_FAILURE;
41+
}
42+
if (strncmp(input.c_str(), buffer2, input.size())) {
43+
std::cout << "The original string could not be reconstructed\n";
44+
return EXIT_FAILURE;
45+
}
46+
std::cout << "String was correctly reconstructed\n";
47+
std::cout << "Input: \"" << input << "\"\n";
48+
std::cout << "Output: \"" << buffer2 << "\"\n";
49+
50+
return EXIT_SUCCESS;
51+
}

recipes/brotli/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions:
2+
1.0.7:
3+
folder: all

0 commit comments

Comments
 (0)