-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
conanfile.py
103 lines (88 loc) · 4.26 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, collect_libs, copy, export_conandata_patches, get, replace_in_file, rmdir, rm
import glob
import os
required_conan_version = ">=1.53.0"
class ZstdConan(ConanFile):
name = "zstd"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/facebook/zstd"
description = "Zstandard - Fast real-time compression algorithm"
topics = ("zstandard", "compression", "algorithm", "decoder")
license = "BSD-3-Clause"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"threading": [True, False],
"build_programs": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"threading": True,
"build_programs": True,
}
def export_sources(self):
export_conandata_patches(self)
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")
def layout(self):
cmake_layout(self, src_folder="src")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["ZSTD_BUILD_PROGRAMS"] = self.options.build_programs
tc.variables["ZSTD_BUILD_STATIC"] = not self.options.shared or self.options.build_programs
tc.variables["ZSTD_BUILD_SHARED"] = self.options.shared
tc.variables["ZSTD_MULTITHREAD_SUPPORT"] = self.options.threading
tc.generate()
def _patch_sources(self):
apply_conandata_patches(self)
# Don't force PIC
replace_in_file(self, os.path.join(self.source_folder, "build", "cmake", "lib", "CMakeLists.txt"),
"POSITION_INDEPENDENT_CODE On", "")
def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, "build", "cmake"))
cmake.build()
def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))
if self.options.shared and self.options.build_programs:
# If we build programs we have to build static libs (see logic in generate()),
# but if shared is True, we only want shared lib in package folder.
rm(self, "*_static.*", os.path.join(self.package_folder, "lib"))
for lib in glob.glob(os.path.join(self.package_folder, "lib", "*.a")):
if not lib.endswith(".dll.a"):
os.remove(lib)
def package_info(self):
zstd_cmake = "libzstd_shared" if self.options.shared else "libzstd_static"
self.cpp_info.set_property("cmake_file_name", "zstd")
self.cpp_info.set_property("cmake_target_name", f"zstd::{zstd_cmake}")
self.cpp_info.set_property("pkg_config_name", "libzstd")
self.cpp_info.components["zstdlib"].libs = collect_libs(self)
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["zstdlib"].system_libs.append("pthread")
# TODO: Remove after dropping Conan 1.x from ConanCenterIndex
self.cpp_info.components["zstdlib"].names["cmake_find_package"] = zstd_cmake
self.cpp_info.components["zstdlib"].names["cmake_find_package_multi"] = zstd_cmake
self.cpp_info.components["zstdlib"].set_property("cmake_target_name", f"zstd::{zstd_cmake}")
self.cpp_info.components["zstdlib"].set_property("pkg_config_name", "libzstd")
if self.options.build_programs:
bindir = os.path.join(self.package_folder, "bin")
self.env_info.PATH.append(bindir)