-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconanfile.py
1588 lines (1404 loc) · 54.7 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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from conans import ConanFile, tools, load
from conans.util.files import save
from conans.model.conan_file import create_options
import os
import json
import glob
import locale
import subprocess
import sys
boost_conan_mixins = []
class BoostBaseConan(ConanFile):
'''
This is the base class to all the Boost moduler packages. It combines
what used to be multiple utility packages and generators into a single
centralized script. It's main duties include: using the Boost library
data for depdency information, uniform settings, uniform options,
generate B2 scripts for building, generate B2 scripts for inter-package
consumption, mapping Conan settings to B2 features, configuring common
package options, and costomization mixins. It is used in the individual
Boost packages with the use of `python_requires`.
'''
# These are the base definitions for this base packages.
name = "boost_base"
version = "2.0.0"
description = "Shared python code used in other Conan recipes for the" + \
"Boost libraries"
exports_sources = [
"LICENSE.md"]
# We export some source files that are used during building each library.
exports = [
# These contain general package information, like dependencies, for
# each release version we understand.
"src/data/package-data-boost-*.json",
# This is a utility to compute the Windows short path from a full path.
"src/script/short_path.cmd",
# B2 template files for per library building.
"src/template/*.jam"]
# These are the definitions common to all Boost packages.
website = "https://github.com/boostorg"
license = "MIT"
short_paths = True
settings = "os", "arch", "compiler", "build_type"
boost_source_repo = {}
#
# Redefinitions for ConanFile package properties. These are dynamically
# computed from the Boost libraries meta-data.
#
@property
def url(self):
return "https://github.com/bincrafters/conan-" + self.name
@property
def no_copy_source(self):
return self.is_base
#
# Information on this base class, irrespective of the instance class.
#
@property
def is_base(self):
return self.__class__.__name__ == "BoostBaseConan"
@property
def base_source_path(self):
'''
This is the path to the sources for this base package. When we are
building a subclassed package we need this to get access to the
exported data and template files.
'''
if not hasattr(self, '_base_source_path_'):
self._base_source_path_ = os.path.dirname(
os.path.abspath(__file__))
return self._base_source_path_
def boost_init(self):
'''
Prepares the instance with all information needed for the various Conan
steps. Mostly provides default, empty, values for the Boost custom
information. For member values the subclass can provide a "get_<name>"
method to dynamically compute the value.
'''
if self.is_base:
return
if self.__class__.__name__ == "TestPackageConan":
self._boost_data_ = {
"test_package_conan": {
"b2_requires": [],
"cycle_group": None,
"header_only_libs": ["test_package_conan"],
"lib_short_names": ["test_package_conan"],
"name": "test_package_conan",
"source_only_deps": []
}
}
if not hasattr(self, '_boost_data_'):
json_file = os.path.join(
self.base_source_path,
'src', 'data',
'package-data-boost-{0}.json'.format(self.version))
with open(json_file, "r") as f:
self._boost_data_ = json.load(f)
#
# Properties for the Boost package instance. These generally correspond
# to the Conan properties but for the Boost specific data.
#
@property
def boost_name(self):
'''
Basename of the Boost library this package contains. I.e. the name
of the package without the "boost_" prefix.
'''
if not hasattr(self, '_boost_name_'):
self._boost_name_ = self.name.replace('boost_', '')
return self._boost_name_
@property
def boost_requires(self):
'''
What other Boost libraries we require as dependencies. Empty list if
none.
'''
self.boost_init()
return self._boost_data_[self.boost_name]['b2_requires']
@property
def boost_build_requires(self):
'''
What other Boost libraries we require as dependencies for building
only. Empty list if none.
'''
return []
@property
def boost_build_defines(self):
'''
Preprocessor definitions to use during building only.
'''
result = set()
for mixin in self.boost_mixins:
result.union(set(mixin.boost_build_defines))
return list(sorted(result))
@property
def boost_build_options(self):
'''
Dictionary of B2 "key=value" arguments to use when building
the package library(ies).
'''
result = {}
for mixin in self.boost_mixins:
result.update(mixin.boost_build_options)
return result
@property
def boost_cycle_group(self):
'''
The name of the cycle group, if this is a cycle group. Otherwise
"None".
'''
self.boost_init()
return self._boost_data_[self.boost_name]['cycle_group']
@property
def boost_libs(self):
'''
The libraries making up this package. For cycle groups this is two or
more, otherwise just the one.
'''
self.boost_init()
return self._boost_data_[self.boost_name]['lib_short_names']
@property
def boost_header_only_libs(self):
'''
The subset of libraries in the package that do not need to be built.
'''
self.boost_init()
return self._boost_data_[self.boost_name]['header_only_libs']
@property
def boost_libs_to_build(self):
'''
The libraries that need building with B2. I.e. non-header only libs.
'''
if not hasattr(self, '_boost_libs_to_build_'):
self._boost_libs_to_build_ = list(
set(self.boost_libs)-set(self.boost_header_only_libs))
return self._boost_libs_to_build_
@property
def boost_source_only_deps(self):
'''
Libraries that we need their source only for building.
'''
self.boost_init()
return self._boost_data_[self.boost_name]['source_only_deps']
@property
def is_cycle_group(self):
'''
Returns true if the package is a container for a group of packages
that have a circular dependency.
'''
return "cycle_group" in self.name
def get_b2_options(self):
'''
The default for b2_options is an empty dictionary, i.e. no key=value's.
'''
return {}
def is_header_only(self, lib_name):
'''
Return true if the given lib_name library is header only and doesn't
need building.
'''
return (lib_name in self.boost_header_only_libs)
#
# ConanFile packaging methods..
#
def initialize(self, settings, env):
'''
Initializes information about the libraries we are building, except
when we are packaging this base class.
'''
if self.is_base:
super(BoostBaseConan, self).initialize(settings, env)
else:
# Save our initial unmodified properties.
base_options = BoostConanMixin(self, base_options=self)
# The base can now muck with them.
super(BoostBaseConan, self).initialize(settings, env)
# Load up the Boost data for the mixins to interrogate.
self.boost_init()
# We create all the mixins we know about and register the ones
# that are pretinent, i.e. match, our package.
self.boost_mixins = []
for mixin_class in boost_conan_mixins:
mixin = mixin_class(self)
if mixin.matches:
self.boost_mixins.append(mixin)
# We copy the options from the mixins and use that to reset our
# options.
for mixin in self.boost_mixins:
base_options.options.update(mixin.options)
base_options.default_options.update(
mixin.default_options)
self.options = create_options(base_options)
def configure(self):
'''
Automatic configuration. Takes care to apply options specified in a
cycle group member to that cycle group.
'''
if self.is_base:
return
if self.boost_cycle_group:
class_options = getattr(self.__class__, 'options')
if class_options:
for option in getattr(self.__class__, 'options').keys():
value = getattr(self.options, option)
setattr(
self.options[self.boost_cycle_group], option, value)
def config_options(self):
'''
Gives the mixins a chance to edit package build options.
'''
if self.is_base:
pass
else:
for mixin in self.boost_mixins:
mixin.config_options()
def requirements(self):
'''
Calculates dependency requirements to other Boost packages.
'''
if self.is_base:
pass
else:
self.boost_init()
# Expand out references to Boost inter-package (library)
# dependencies.
for lib in self.boost_requires:
self.requires("{dep}/{ver}@{user}/{channel}".format(
dep='boost_'+lib,
ver=self.version,
user=self.user,
channel=self.channel,
))
# We need B2 if we are building any libraries in the package.
if len(self.boost_libs_to_build) > 0:
self.requires("{dep}/{ver}@{user}/{channel}".format(
dep='boost_build',
ver=self.version,
user=self.user,
channel=self.channel,
))
for mixin in self.boost_mixins:
mixin.requirements()
def build_requirements(self):
'''
Applies build only requirements from `b2_build_requires` to the
package.
'''
if self.is_base:
pass
else:
self.boost_init()
# Expand out references to Boost inter-package (library)
# dependencies.
for lib in self.boost_build_requires:
self.build_requires("{dep}/{ver}@{user}/{channel}".format(
dep='boost_'+lib,
ver=self.version,
user=self.user,
channel=self.channel,
))
for mixin in self.boost_mixins:
mixin.build_requirements()
def source(self):
'''
Depending on the kind of package it is downloads the Boost library
sources. For a library in a cycle group we do nothing. Otherwise
it downloads the individual libraries .
'''
if self.is_base:
return
self.boost_init()
if not self.boost_cycle_group:
# It's a regular library, i.e. not a cycle group alias, set up the
# sources, including generated ones.
archive_name = "boost-" + self.version
# Download the source directly from GitHub each library source.
libs_to_get = self.boost_libs + self.boost_source_only_deps
for lib in libs_to_get:
lib_repo = lib
if lib in self.boost_source_repo:
lib_repo = self.boost_source_repo[lib]
tools.get(
"{0}/{1}/archive/{2}.tar.gz".format(
self.website, lib_repo, archive_name))
os.rename(lib_repo + "-" + archive_name, lib)
# If we are going to build something we need to get the matching
# boostcpp.jam build file from the Boost super-project.
if len(self.boost_libs_to_build) > 0:
bootcpp_raw_url = \
"https://raw.githubusercontent.com/" + \
"boostorg/boost/boost-{0}/boostcpp.jam"
tools.download(
bootcpp_raw_url.format(self.version),
"boostcpp.jam")
for mixin in self.boost_mixins:
mixin.source()
def build(self):
'''
Build any buildable, i.e. not header only, libraries in the package.
Building is done for any package that is not in a cycle group. As cycle
group members just steal the produced builds from the cycle group.
The main build procedure iterates for each library building them as
needed and creating the export structure and files.
'''
if self.is_base:
return
self.boost_init()
# Libraries that are in a cycle group are not built directly. Instead
# the results are taken from the cycle group. Hence there's nothing
# to do here.
if self.boost_cycle_group:
return
if len(self.boost_libs_to_build) > 0:
# Create local jamroot for build that defines magic rules,
# hooks, variables and targets to control the build for Conan.
self._write_jamroot_jam()
# Create local project-config.jam for setting up B2.
self._write_project_config_jam()
# Also write out the utility Windows short path script.
self._write_short_path_cmd()
# Build each library.
for lib in self.boost_libs:
self._build_lib(lib)
def _write_jamroot_jam(self):
'''
Generates the `jamroot.jam` file at the root of the package build tree.
This jamfile contains most of the configuration, and patching magic,
to build the individual libraries.
'''
# TODO: Rewrite to use a less kludgy template system.
content = load(os.path.join(
self.base_source_path, 'src', 'template', 'jamroot.jam'))
jam_include_paths = ' '.join(
'"' + path + '"' for path in self.deps_cpp_info.includedirs
).replace('\\', '/')
content = content \
.replace("{{{toolset}}}", self.b2_toolset) \
.replace("{{{libraries}}}", " ".join(self.boost_libs)) \
.replace("{{{boost_version}}}", self.version) \
.replace("{{{deps.include_paths}}}", jam_include_paths) \
.replace("{{{os}}}", self.b2_os) \
.replace("{{{address_model}}}", self.b2_address_model) \
.replace("{{{architecture}}}", self.b2_architecture) \
.replace(
"{{{deps_info}}}", self._b2_dependencies_for_jamroot_jam) \
.replace("{{{variant}}}", self.b2_variant) \
.replace("{{{name}}}", self.name) \
.replace("{{{link}}}", self.b2_link) \
.replace("{{{runtime_link}}}", self.b2_runtime_link) \
.replace("{{{toolset_version}}}", self.b2_toolset_version) \
.replace("{{{toolset_exec}}}", self.b2_toolset_exec) \
.replace("{{{libcxx}}}", self.b2_libcxx) \
.replace("{{{cxxstd}}}", self.b2_cxxstd) \
.replace("{{{cxxabi}}}", self.b2_cxxabi) \
.replace("{{{libpath}}}", self.b2_icu_lib_paths) \
.replace("{{{arch_flags}}}", self.b2_arch_flags) \
.replace("{{{isysroot}}}", self.b2_isysroot) \
.replace("{{{os_version}}}", self.b2_os_version) \
.replace("{{{fpic}}}", self.b2_fpic) \
.replace("{{{threading}}}", self.b2_threading) \
.replace("{{{threadapi}}}", self.b2_threadapi) \
.replace("{{{profile_flags}}}", self.b2_profile_flags)
save(os.path.join(self.build_folder, 'jamroot.jam'), content)
def _write_project_config_jam(self):
'''
Generates the `project-config.jam` file at the root of the build tree.
This file contains the configuration that maps from the Conan provided
tool and packaged libraries to the B2 equivalent.
'''
# TODO: Rewrite to use a less kludgy template system.
content = load(os.path.join(
self.base_source_path, 'src', 'template', 'project-config.jam'))
content = content \
.replace("{{{toolset}}}", self.b2_toolset) \
.replace("{{{toolset_version}}}", self.b2_toolset_version) \
.replace("{{{toolset_exec}}}", self.b2_toolset_exec) \
.replace("{{{zlib_lib_paths}}}", self.zlib_lib_paths) \
.replace("{{{zlib_include_paths}}}", self.zlib_include_paths) \
.replace("{{{zlib_name}}}", self.zlib_lib_name) \
.replace("{{{bzip2_lib_paths}}}", self.bzip2_lib_paths) \
.replace("{{{bzip2_include_paths}}}", self.bzip2_include_paths) \
.replace("{{{bzip2_name}}}", self.bzip2_lib_name) \
.replace("{{{lzma_lib_paths}}}", self.lzma_lib_paths) \
.replace("{{{lzma_include_paths}}}", self.lzma_include_paths) \
.replace("{{{lzma_name}}}", self.lzma_lib_name) \
.replace("{{{zstd_lib_paths}}}", self.zstd_lib_paths) \
.replace("{{{zstd_include_paths}}}", self.zstd_include_paths) \
.replace("{{{zstd_name}}}", self.zstd_lib_name) \
.replace("{{{python_exec}}}", self.b2_python_exec) \
.replace("{{{python_version}}}", self.b2_python_version) \
.replace("{{{python_include}}}", self.b2_python_include) \
.replace("{{{python_lib}}}", self.b2_python_lib) \
.replace("{{{mpicxx}}}", self.b2_mpicxx) \
.replace("{{{profile_tools}}}", self.b2_profile_tools)
save(os.path.join(self.build_folder, 'project-config.jam'), content)
def _write_short_path_cmd(self):
'''
Copy the `short_path.cmd` script to where the B2 build script, the
`jamroot.jam` file, expects it during the build, i.e. to the root
of the build tree.
'''
content = load(os.path.join(
self.base_source_path, 'src', 'script', 'short_path.cmd'))
save(os.path.join(self.build_folder, 'short_path.cmd'), content)
@property
def _b2_dependencies_for_jamroot_jam(self):
'''
Computes dependency declarations for the package jamroot.
'''
deps_info = []
for dep_name, dep_cpp_info in self.deps_cpp_info.dependencies:
for libdir in dep_cpp_info.libdirs:
dep_libdir = os.path.join(dep_cpp_info.rootpath, libdir)
if os.path.isfile(os.path.join(dep_libdir, "jamroot.jam")):
lib_short_name = \
os.path.basename(os.path.dirname(dep_libdir))
lib_project_name = \
"\"/" + dep_name + "," + lib_short_name + "\""
deps_info.append('use-project %s : "%s" ;' % (
lib_project_name, dep_libdir.replace('\\', '/')))
deps_info.append('alias "%s" : %s ;' % (
lib_short_name, lib_project_name))
dep_libs = \
self._boost_data_[lib_short_name]['lib_short_names']
for dep_lib in dep_libs:
deps_info.append('"LIBRARY_DIR(%s)" = "%s" ;' % (
dep_lib, dep_libdir.replace('\\', '/')))
deps_info = "\n".join(deps_info)
return deps_info
def _build_lib(self, lib):
# We put all files needed to use the library in the lib dir.
lib_dir = os.path.join(lib, "lib")
# Each lib gets a jamroot.jam that is used to import it when
# building downstream packages. This jamroot.jam is nly used
# for further building and not for consumers of the packages.
jam_file = os.path.join(lib_dir, "jamroot.jam")
if self.is_header_only(lib):
# Header only libs only get the jamroot.jam file in the lib
# exported dir.
jamroot_content = self.jamroot_header_only_content.format(
lib=lib)
tools.save(jam_file, jamroot_content, append=True)
else:
# Construct the B2 build command:
b2_command = [
# B2 executable, which comes in a a dependency.
"b2",
# Use all available for parallel build.
"-j%s" % (tools.cpu_count()),
# Optionally add debug output information. Default of +d1
# just shows the actions executed.
"-d+%s" % (os.getenv('CONAN_B2_DEBUG', '1')),
# We need to do full rebuilds.
"-a",
# Avoid long intermediate paths by using hashed variant
# dirs.
"--hash=yes",
# We always print out configuration info to aid in build
# debugging.
"--debug-configuration",
# We use the bare "system" naming that avoids extra
# tagging. This simplifies the logic for finding and using
# specific libraries. And we don't need the extended
# tagging as Conan segregates variants simiarly like B2.
"--layout=system"
]
# Add the B2 features needed as defined by the package.
b2_command += [
key + "=" + value
for key, value in self.boost_build_options.items()]
# Add cpp defines as needed.
b2_command += [
"define=" + define
for define in self.boost_build_defines]
# Add include dirs of source only dependencies nneded for
# building.
b2_command += [
"include=" + lib + '/include'
for lib in self.boost_source_only_deps]
# Finally, add the target we build. This is a special target
# that build just the library we need.
b2_command += [lib + "-build"]
# Lets now do the build, but first debug output what we are
# about to run.
self.output.info(
"%s: %s" % (os.getcwd(), " ".join(b2_command)))
# TODO: Why do we add ${MPI_BIN} to PATH?
with tools.environment_append({
'PATH': [os.getenv('MPI_BIN', '')]
}):
self.run(" ".join(b2_command))
# For each library built add to the exported jamroot.jam
# information about that library.
libs = self._collect_build_libs(lib_dir)
for lib_link_name in libs:
search_content = self.jamroot_search_content.format(
lib_link_name=lib_link_name)
tools.save(jam_file, search_content, append=True)
# If we didn't build a "canonical" boost_<name> library we add
# an alias target to point to all the built libraries to the
# exported jamroot.jam.
if "boost_" + lib not in libs:
alias_content = self.jamroot_alias_content.format(
lib=lib,
space_joined_libs=" ".join(libs))
tools.save(jam_file, alias_content, append=True)
# Jamroot.jam for header only libs. It declares:
# ROOT({lib}) -- path to the root of the exported package.
# /conan/{lib} -- project requirements.
# /boost/{lib} -- global ID to mirror Boost project IDs.
jamroot_header_only_content = """\
import project ;
import path ;
import modules ;
ROOT({lib}) = [ path.parent [ path.parent [ path.make
[ modules.binding $(__name__) ] ] ] ] ;
project /conan/{lib} : requirements <include>$(ROOT({lib}))/include ;
project.register-id /boost/{lib} : $(__name__) ;
"""
# Jamroot.jam content for built libraries that adds the lib target(s) that
# other Boost packages will use to link in their dependencies.
jamroot_search_content = """\
lib {lib_link_name} : : <name>{lib_link_name} <search>. : : $(usage) ;
"""
# Jamroot.jam content for built libraries that aliases the one or more
# built libraries as a single symbolic target for use as a single name
# build dependency.
jamroot_alias_content = """\
alias boost_{lib} : {space_joined_libs} : : : $(usage) ;
"""
def _collect_build_libs(self, lib_folder):
'''
Searches the build output for any libraries built and returns the
simple basename of those libraries.
'''
libs = []
if not os.path.exists(lib_folder):
self.output.warn(
"Lib folder doesn't exist, can't collect libraries: " +
lib_folder)
else:
files = os.listdir(lib_folder)
for f in files:
name, ext = os.path.splitext(f)
if ext in (".so", ".lib", ".a", ".dylib"):
if ext != ".lib" and name.startswith("lib"):
name = name[3:]
libs.append(name)
return libs
def package(self):
'''
Package the exported files from all the libraries we built.
'''
if self.is_base:
pass
else:
self.boost_init()
for lib in self.boost_libs:
self.copy(pattern="*LICENSE*", dst="license", src=lib)
for subdir in ["lib", "include"]:
copydir = os.path.join(lib, subdir)
self.copy(pattern="*", dst=copydir, src=copydir)
def package_info(self):
'''
Generate the meta information about the libraries in the package.
'''
if self.is_base:
return
self.boost_init()
# We publish a single comma separated list of the libraries in the
# package user info.
self.user_info.boost_libs = ",".join(self.boost_libs)
self.cpp_info.includedirs = []
self.cpp_info.libdirs = []
self.cpp_info.bindirs = []
self.cpp_info.libs = []
if self.is_cycle_group:
# For a group of circular dependent libs we publish the aggregation
# of the lib and include dirs.
for lib in self.boost_libs:
lib_dir = os.path.join(lib, "lib")
self.cpp_info.libdirs.append(lib_dir)
include_dir = os.path.join(lib, "include")
self.cpp_info.includedirs.append(include_dir)
elif self.boost_cycle_group:
# For a library in a cycle group we steal some info from the cycle
# group. Hence this ends up "aliasing" the group content.
group = self.deps_cpp_info['boost_'+self.boost_cycle_group]
# Point the include dir to the group sublib include dir.
include_dir = os.path.join(
group.rootpath, self.boost_libs[0], "include")
self.cpp_info.includedirs.append(include_dir)
# Point the lib dir to the group sublib lib dir.
lib_dir = os.path.join(
group.rootpath, self.boost_libs[0], "lib")
self.cpp_info.libdirs.append(lib_dir)
# And if this lib had built files, we add all the found libs from
# the group sublib lib dir to this package. This has the effect
# of consumer linking to the sublib specific targets only.
if not self.is_header_only(self.boost_libs[0]):
self.cpp_info.libs.extend(tools.collect_libs(self, lib_dir))
else:
# Otherwise we are a regular built lib and can add include dir,
# lib dir, and libs directly in this package.
include_dir = os.path.join(self.boost_libs[0], "include")
self.cpp_info.includedirs.append(include_dir)
lib_dir = os.path.join(self.boost_libs[0], "lib")
self.cpp_info.libdirs.append(lib_dir)
if not self.is_header_only(self.boost_libs[0]):
self.cpp_info.libs.extend(tools.collect_libs(self, lib_dir))
# Since we explicitly specify all the libs we need to use we turn off
# the Boost built-in mechanism for automatic linking of libraries on
# some platforms (i.e. MSVC)
self.cpp_info.defines.append("BOOST_ALL_NO_LIB=1")
self.cpp_info.bindirs.extend(self.cpp_info.libdirs)
# Avoid duplicate entries in the libs.
self.cpp_info.libs = list(set(self.cpp_info.libs))
for mixin in self.boost_mixins:
mixin.package_info()
def package_id(self):
'''
We need to account for the package ID being different if it's just the
base or library package.
'''
if self.is_base:
# This base is simply a shell, that doesn't build anything for
# itself.
self.info.header_only()
else:
self.boost_init()
# We can only be header only when all the sub parts are header
# only.
all_header_only = True
for lib in self.boost_libs:
all_header_only = all_header_only and self.is_header_only(lib)
if all_header_only:
self.info.header_only()
# For all the package requirements that are Boost packages we
# indicate that the version matching can't use partial versions
# as acceptable. This avoids having one Boost library package
# accidentally depend on a different version. I.e. that all the
# Boost libraries advance versions in lockstep.
# Revisit if Boost ever supports cross-version dependencies.
boost_deps_only = [
dep_name
for dep_name in self.info.requires.pkg_names
if dep_name.startswith("boost_")]
for dep_name in boost_deps_only:
self.info.requires[dep_name].full_version_mode()
for mixin in self.boost_mixins:
mixin.package_id()
#
# Translation of Conan to B2 equivalents..
#
_b2_os = {
'Windows': 'windows',
'Linux': 'linux',
'Macos': 'darwin',
'Android': 'android',
'iOS': 'iphone',
'FreeBSD': 'freebsd',
'SunOS': 'solaris'}
@property
def b2_os(self):
return self._b2_os[str(self.settings.os)]
_b2_address_model = {
'x86': '32',
'x86_64': '64',
'ppc64le': '64',
'ppc64': '64',
'armv6': '32',
'armv7': '32',
'armv7hf': '32',
'armv8': '64'}
@property
def b2_address_model(self):
return self._b2_address_model[str(self.settings.arch)]
@property
def b2_architecture(self):
if str(self.settings.arch).startswith('x86'):
return 'x86'
elif str(self.settings.arch).startswith('ppc'):
return 'power'
elif str(self.settings.arch).startswith('arm'):
return 'arm'
else:
return ""
@property
def b2_variant(self):
if str(self.settings.build_type) == "Debug":
return "debug"
else:
return "release"
_b2_toolsets = {
'gcc': 'gcc',
'Visual Studio': 'msvc',
'clang': 'clang',
'apple-clang': 'clang'}
@property
def b2_toolset(self):
return self._b2_toolsets[str(self.settings.compiler)]
_b2_msvc_version = {
'8': '8.0',
'9': '9.0',
'10': '10.0',
'11': '11.0',
'12': '12.0',
'15': '14.1',
'16': '14.2'
}
@property
def b2_toolset_version(self):
if self.settings.compiler == "Visual Studio":
return self._b2_msvc_version[str(self.settings.compiler.version)]
else:
return "$(DEFAULT)"
@property
def b2_toolset_exec(self):
class dev_null(object):
def write(self, message):
pass
if bool(
(self.b2_os in [
'linux', 'freebsd', 'solaris', 'darwin', 'android']) or
(self.b2_os == 'windows' and self.b2_toolset == 'gcc')
):
if 'CXX' in os.environ:
try:
self.run(
os.environ['CXX'] + ' --version',
output=dev_null())
return os.environ['CXX']
except:
pass
version = str(self.settings.compiler.version).split('.')
result_x = self.b2_toolset.replace('gcc', 'g++') + "-" + version[0]
result_xy = result_x
if len(version) > 1:
result_xy += version[1] if version[1] != '0' else ''
try:
self.run(result_xy + " --version", output=dev_null())
return result_xy
except:
pass
try:
self.run(result_x + " --version", output=dev_null())
return result_x
except:
pass
return "$(DEFAULT)"
elif self.b2_os == "windows":
return self.b2_win_cl_exe or "$(DEFAULT)"
else:
return "$(DEFAULT)"
@property
def b2_win_cl_exe(self):
vs_root = tools.vs_installation_path(
str(self.settings.compiler.version))
if vs_root:
cl_exe = \
glob.glob(os.path.join(
vs_root, "VC", "Tools", "MSVC", "*", "bin", "*", "*",
"cl.exe")) + \
glob.glob(os.path.join(vs_root, "VC", "bin", "cl.exe"))
if cl_exe:
return cl_exe[0].replace("\\", "/")
@property
def b2_link(self):
try:
return "shared" if self.options.shared else "static"
except:
return "static"
@property
def b2_runtime_link(self):
if bool(
self.settings.compiler == "Visual Studio" and
self.settings.compiler.runtime
):
return "static" if "MT" in str(self.settings.compiler.runtime) \
else "$(DEFAULT)"
return "$(DEFAULT)"
@property
def b2_cxxstd(self):
# for now, we use C++11 as default, unless we're targeting libstdc++
# (not 11)
if self.b2_toolset in ['gcc', 'clang'] and self.b2_os != 'android':
if str(self.settings.compiler.libcxx) != 'libstdc++':
return '<cxxflags>-std=c++11 <linkflags>-std=c++11'
return ''
@property
def b2_cxxabi(self):
if self.b2_toolset in ['gcc', 'clang'] and self.b2_os != 'android':
if str(self.settings.compiler.libcxx) == 'libstdc++11':
return '<define>_GLIBCXX_USE_CXX11_ABI=1'
elif str(self.settings.compiler.libcxx) == 'libstdc++':
return '<define>_GLIBCXX_USE_CXX11_ABI=0'
return ''
@property
def b2_libcxx(self):
if self.b2_toolset == 'clang' and self.b2_os != 'android':
if str(self.settings.compiler.libcxx) == 'libc++':
return '<cxxflags>-stdlib=libc++ <linkflags>-stdlib=libc++'
elif str(self.settings.compiler.libcxx) in [
'libstdc++11', 'libstdc++'
]:
return \
'<cxxflags>-stdlib=libstdc++ <linkflags>-stdlib=libstdc++'
return ''
_python_dep = "python_dev_config"
@property
def b2_python_exec(self):
try:
return self.deps_user_info[
self._python_dep].python_exec.replace('\\', '/')
except:
return ""
@property
def b2_python_version(self):
try:
return self.deps_user_info[
self._python_dep].python_version.replace('\\', '/')
except:
return ""
@property
def b2_python_include(self):
try:
return self.deps_user_info[
self._python_dep].python_include_dir.replace('\\', '/')
except:
return ""
@property
def b2_python_lib(self):
try:
if self.settings.compiler == "Visual Studio":
return self.deps_user_info[
self._python_dep].python_lib_dir.replace('\\', '/')
else:
return self.deps_user_info[
self._python_dep].python_lib.replace('\\', '/')
except:
return ""
@property
def b2_icu_lib_paths(self):
try:
if self.options.use_icu:
return '"{0}"'.format('" "'.join(
self.deps_cpp_info["icu"].lib_paths)).replace('\\', '/')
except:
pass
return ""
@property
def b2_apple_arch(self):
return {
"armv7": "armv7",
"armv8": "arm64",
"x86": "i386",
"x86_64": "x86_64"
}.get(str(self.settings.arch))
@property
def b2_apple_sdk(self):
if self.settings.os == "Macos":
return "macosx"
elif self.settings.os == "iOS":
if str(self.settings.arch).startswith('x86'):
return "iphonesimulator"
elif str(self.settings.arch).startswith('arm'):
return "iphoneos"
else:
return None
return None