-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
conanfile.py
337 lines (291 loc) · 16.1 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
from conan import ConanFile
from conan.tools.apple import is_apple_os
from conan.tools.build import cross_building
from conan.tools.env import Environment, VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, mkdir, rename, replace_in_file, rm, rmdir, save
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, unix_path
from conan.tools.scm import Version
from conans.tools import get_gnu_triplet, sha256sum, stdcpp_library
import glob
import os
import shutil
required_conan_version = ">=1.53.0"
class ICUConan(ConanFile):
name = "icu"
homepage = "http://site.icu-project.org"
license = "ICU"
description = "ICU is a mature, widely used set of C/C++ and Java libraries " \
"providing Unicode and Globalization support for software applications."
url = "https://github.com/conan-io/conan-center-index"
topics = ("icu", "icu4c", "i see you", "unicode")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"data_packaging": ["files", "archive", "library", "static"],
"with_dyload": [True, False],
"dat_package_file": [None, "ANY"],
"with_icuio": [True, False],
"with_extras": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"data_packaging": "archive",
"with_dyload": True,
"dat_package_file": None,
"with_icuio": True,
"with_extras": False,
}
@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
@property
def _enable_icu_tools(self):
return self.settings.os not in ["iOS", "tvOS", "watchOS", "Emscripten"]
@property
def _with_unit_tests(self):
return not self.conf.get("tools.build:skip_test", default=True, check_type=bool)
def export_sources(self):
export_conandata_patches(self)
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
del self.options.data_packaging
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
def layout(self):
basic_layout(self, src_folder="src")
def package_id(self):
if self.options.dat_package_file:
dat_package_file_sha256 = sha256sum(str(self.options.dat_package_file))
self.info.options.dat_package_file = dat_package_file_sha256
def build_requirements(self):
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")
if cross_building(self) and hasattr(self, "settings_build"):
self.tool_requires(self.ref)
def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)
def generate(self):
env = VirtualBuildEnv(self)
env.generate()
tc = AutotoolsToolchain(self)
if (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler.version) >= "12") or \
(self.settings.compiler == "msvc" and Version(self.settings.compiler.version) >= "180"):
tc.extra_cflags.append("-FS")
tc.extra_cxxflags.append("-FS")
if not self.options.shared:
tc.extra_defines.append("U_STATIC_IMPLEMENTATION")
if is_apple_os(self):
tc.extra_defines.append("_DARWIN_C_SOURCE")
yes_no = lambda v: "yes" if v else "no"
tc.configure_args.extend([
"--datarootdir=${prefix}/lib", # do not use share
f"--enable-release={yes_no(self.settings.build_type != 'Debug')}",
f"--enable-debug={yes_no(self.settings.build_type == 'Debug')}",
f"--enable-dyload={yes_no(self.options.with_dyload)}",
f"--enable-extras={yes_no(self.options.with_extras)}",
f"--enable-icuio={yes_no(self.options.with_icuio)}",
"--disable-layoutex",
"--disable-layout",
f"--enable-tools={yes_no(self._enable_icu_tools)}",
f"--enable-tests={yes_no(self._with_unit_tests)}",
"--disable-samples",
])
if cross_building(self):
base_path = unix_path(self, self.dependencies.build["icu"].package_folder)
tc.configure_args.append(f"--with-cross-build={base_path}")
if self.settings.os in ["iOS", "tvOS", "watchOS"]:
gnu_triplet = get_gnu_triplet("Macos", str(self.settings.arch))
tc.configure_args.append(f"--host={gnu_triplet}")
elif is_msvc(self):
# ICU doesn't like GNU triplet of conan for msvc (see https://github.com/conan-io/conan/issues/12546)
host = get_gnu_triplet(str(self.settings.os), str(self.settings.arch), "gcc")
build = get_gnu_triplet(str(self._settings_build.os), str(self._settings_build.arch), "gcc")
tc.configure_args.extend([
f"--host={host}",
f"--build={build}",
])
else:
arch64 = ["x86_64", "sparcv9", "ppc64", "ppc64le", "armv8", "armv8.3", "mips64"]
bits = "64" if self.settings.arch in arch64 else "32"
tc.configure_args.append(f"--with-library-bits={bits}")
if self.settings.os != "Windows":
# http://userguide.icu-project.org/icudata
# This is the only directly supported behavior on Windows builds.
tc.configure_args.append(f"--with-data-packaging={self.options.data_packaging}")
tc.generate()
if is_msvc(self):
env = Environment()
env.define("CC", "cl -nologo")
env.define("CXX", "cl -nologo")
env.vars(self).save_script("conanbuild_icu_msvc")
def _patch_sources(self):
apply_conandata_patches(self)
if not self._with_unit_tests:
# Prevent any call to python during configuration, it's only needed for unit tests
replace_in_file(
self,
os.path.join(self.source_folder, "source", "configure"),
"if test -z \"$PYTHON\"",
"if true",
)
if self._settings_build.os == "Windows":
# https://unicode-org.atlassian.net/projects/ICU/issues/ICU-20545
makeconv_cpp = os.path.join(self.source_folder, "source", "tools", "makeconv", "makeconv.cpp")
replace_in_file(self, makeconv_cpp,
"pathBuf.appendPathPart(arg, localError);",
"pathBuf.append(\"/\", localError); pathBuf.append(arg, localError);")
# relocatable shared libs on macOS
mh_darwin = os.path.join(self.source_folder, "source", "config", "mh-darwin")
replace_in_file(self, mh_darwin, "-install_name $(libdir)/$(notdir", "-install_name @rpath/$(notdir")
replace_in_file(self,
mh_darwin,
"-install_name $(notdir $(MIDDLE_SO_TARGET)) $(PKGDATA_TRAILING_SPACE)",
"-install_name @rpath/$(notdir $(MIDDLE_SO_TARGET))",
)
# workaround for https://unicode-org.atlassian.net/browse/ICU-20531
mkdir(self, os.path.join(self.build_folder, "data", "out", "tmp"))
# workaround for "No rule to make target 'out/tmp/dirs.timestamp'"
save(self, os.path.join(self.build_folder, "data", "out", "tmp", "dirs.timestamp"), "")
def build(self):
self._patch_sources()
if self.options.dat_package_file:
dat_package_file = glob.glob(os.path.join(self.source_folder, "source", "data", "in", "*.dat"))
if dat_package_file:
shutil.copy(str(self.options.dat_package_file), dat_package_file[0])
autotools = Autotools(self)
autotools.configure(build_script_folder=os.path.join(self.source_folder, "source"))
autotools.make()
if self._with_unit_tests:
autotools.make(target="check")
@property
def _data_filename(self):
vtag = self.version.split(".")[0]
return f"icudt{vtag}l.dat"
@property
def _data_path(self):
data_dir_name = "icu"
if self.settings.os == "Windows" and self.settings.build_type == "Debug":
data_dir_name += "d"
data_dir = os.path.join(self.package_folder, "lib", data_dir_name, self.version)
return os.path.join(data_dir, self._data_filename)
def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
autotools = Autotools(self)
# TODO: replace by autotools.install() once https://github.com/conan-io/conan/issues/12153 fixed
autotools.install(args=[f"DESTDIR={unix_path(self, self.package_folder)}"])
dll_files = glob.glob(os.path.join(self.package_folder, "lib", "*.dll"))
if dll_files:
bin_dir = os.path.join(self.package_folder, "bin")
mkdir(self, bin_dir)
for dll in dll_files:
dll_name = os.path.basename(dll)
rm(self, dll_name, bin_dir)
rename(self, src=dll, dst=os.path.join(bin_dir, dll_name))
if self.settings.os != "Windows" and self.options.data_packaging in ["files", "archive"]:
mkdir(self, os.path.join(self.package_folder, "res"))
rename(self, src=self._data_path, dst=os.path.join(self.package_folder, "res", self._data_filename))
# Copy some files required for cross-compiling
config_dir = os.path.join(self.package_folder, "config")
copy(self, "icucross.mk", src=os.path.join(self.build_folder, "config"), dst=config_dir)
copy(self, "icucross.inc", src=os.path.join(self.build_folder, "config"), dst=config_dir)
rmdir(self, os.path.join(self.package_folder, "lib", "icu"))
rmdir(self, os.path.join(self.package_folder, "lib", "man"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))
def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "ICU")
prefix = "s" if self.settings.os == "Windows" and not self.options.shared else ""
suffix = "d" if self.settings.os == "Windows" and self.settings.build_type == "Debug" else ""
# icudata
self.cpp_info.components["icu-data"].set_property("cmake_target_name", "ICU::data")
icudata_libname = "icudt" if self.settings.os == "Windows" else "icudata"
self.cpp_info.components["icu-data"].libs = [f"{prefix}{icudata_libname}{suffix}"]
if not self.options.shared:
self.cpp_info.components["icu-data"].defines.append("U_STATIC_IMPLEMENTATION")
# icu uses c++, so add the c++ runtime
libcxx = stdcpp_library(self)
if libcxx:
self.cpp_info.components["icu-data"].system_libs.append(libcxx)
# Alias of data CMake component
self.cpp_info.components["icu-data-alias"].set_property("cmake_target_name", "ICU::dt")
self.cpp_info.components["icu-data-alias"].requires = ["icu-data"]
# icuuc
self.cpp_info.components["icu-uc"].set_property("cmake_target_name", "ICU::uc")
self.cpp_info.components["icu-uc"].set_property("pkg_config_name", "icu-uc")
self.cpp_info.components["icu-uc"].libs = [f"{prefix}icuuc{suffix}"]
self.cpp_info.components["icu-uc"].requires = ["icu-data"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["icu-uc"].system_libs = ["m", "pthread"]
if self.options.with_dyload:
self.cpp_info.components["icu-uc"].system_libs.append("dl")
elif self.settings.os == "Windows":
self.cpp_info.components["icu-uc"].system_libs = ["advapi32"]
# icui18n
self.cpp_info.components["icu-i18n"].set_property("cmake_target_name", "ICU::i18n")
self.cpp_info.components["icu-i18n"].set_property("pkg_config_name", "icu-i18n")
icui18n_libname = "icuin" if self.settings.os == "Windows" else "icui18n"
self.cpp_info.components["icu-i18n"].libs = [f"{prefix}{icui18n_libname}{suffix}"]
self.cpp_info.components["icu-i18n"].requires = ["icu-uc"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["icu-i18n"].system_libs = ["m"]
# Alias of i18n CMake component
self.cpp_info.components["icu-i18n-alias"].set_property("cmake_target_name", "ICU::in")
self.cpp_info.components["icu-i18n-alias"].requires = ["icu-i18n"]
# icuio
if self.options.with_icuio:
self.cpp_info.components["icu-io"].set_property("cmake_target_name", "ICU::io")
self.cpp_info.components["icu-io"].set_property("pkg_config_name", "icu-io")
self.cpp_info.components["icu-io"].libs = [f"{prefix}icuio{suffix}"]
self.cpp_info.components["icu-io"].requires = ["icu-i18n", "icu-uc"]
if self.settings.os != "Windows" and self.options.data_packaging in ["files", "archive"]:
self.cpp_info.components["icu-data"].resdirs = ["res"]
data_path = os.path.join(self.package_folder, "res", self._data_filename).replace("\\", "/")
self.runenv_info.prepend_path("ICU_DATA", data_path)
if self._enable_icu_tools or self.options.with_extras:
self.buildenv_info.prepend_path("ICU_DATA", data_path)
if self._enable_icu_tools:
# icutu
self.cpp_info.components["icu-tu"].set_property("cmake_target_name", "ICU::tu")
self.cpp_info.components["icu-tu"].libs = [f"{prefix}icutu{suffix}"]
self.cpp_info.components["icu-tu"].requires = ["icu-i18n", "icu-uc"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["icu-tu"].system_libs = ["pthread"]
# icutest
self.cpp_info.components["icu-test"].set_property("cmake_target_name", "ICU::test")
self.cpp_info.components["icu-test"].libs = [f"{prefix}icutest{suffix}"]
self.cpp_info.components["icu-test"].requires = ["icu-tu", "icu-uc"]
# TODO: to remove after conan v2
self.cpp_info.names["cmake_find_package"] = "ICU"
self.cpp_info.names["cmake_find_package_multi"] = "ICU"
self.cpp_info.components["icu-data"].names["cmake_find_package"] = "data"
self.cpp_info.components["icu-data"].names["cmake_find_package_multi"] = "data"
self.cpp_info.components["icu-data-alias"].names["cmake_find_package"] = "dt"
self.cpp_info.components["icu-data-alias"].names["cmake_find_package_multi"] = "dt"
self.cpp_info.components["icu-uc"].names["cmake_find_package"] = "uc"
self.cpp_info.components["icu-uc"].names["cmake_find_package_multi"] = "uc"
self.cpp_info.components["icu-i18n"].names["cmake_find_package"] = "i18n"
self.cpp_info.components["icu-i18n"].names["cmake_find_package_multi"] = "i18n"
self.cpp_info.components["icu-i18n-alias"].names["cmake_find_package"] = "in"
self.cpp_info.components["icu-i18n-alias"].names["cmake_find_package_multi"] = "in"
if self.options.with_icuio:
self.cpp_info.components["icu-io"].names["cmake_find_package"] = "io"
self.cpp_info.components["icu-io"].names["cmake_find_package_multi"] = "io"
if self.settings.os != "Windows" and self.options.data_packaging in ["files", "archive"]:
self.env_info.ICU_DATA.append(data_path)
if self._enable_icu_tools:
self.cpp_info.components["icu-tu"].names["cmake_find_package"] = "tu"
self.cpp_info.components["icu-tu"].names["cmake_find_package_multi"] = "tu"
self.cpp_info.components["icu-test"].names["cmake_find_package"] = "test"
self.cpp_info.components["icu-test"].names["cmake_find_package_multi"] = "test"
if self._enable_icu_tools or self.options.with_extras:
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))