-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
conanfile.py
1610 lines (1403 loc) · 74.6 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
from conans import ConanFile
from conans import tools
from conans.tools import Version, cppstd_flag
from conans.errors import ConanException
from conans.errors import ConanInvalidConfiguration
import glob
import os
import sys
import shlex
import shutil
import yaml
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
required_conan_version = ">=1.33.0"
# When adding (or removing) an option, also add this option to the list in
# `rebuild-dependencies.yml` and re-run that script.
CONFIGURE_OPTIONS = (
"atomic",
"chrono",
"container",
"context",
"contract",
"coroutine",
"date_time",
"exception",
"fiber",
"filesystem",
"graph",
"graph_parallel",
"iostreams",
"json",
"locale",
"log",
"math",
"mpi",
"nowide",
"program_options",
"python",
"random",
"regex",
"serialization",
"stacktrace",
"system",
"test",
"thread",
"timer",
"type_erasure",
"wave",
)
class BoostConan(ConanFile):
name = "boost"
settings = "os", "arch", "compiler", "build_type"
description = "Boost provides free peer-reviewed portable C++ source libraries"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.boost.org"
license = "BSL-1.0"
topics = ("conan", "boost", "libraries", "cpp")
_options = None
options = {
"shared": [True, False],
"header_only": [True, False],
"error_code_header_only": [True, False],
"system_no_deprecated": [True, False],
"asio_no_deprecated": [True, False],
"filesystem_no_deprecated": [True, False],
"fPIC": [True, False],
"layout": ["system", "versioned", "tagged", "b2-default"],
"magic_autolink": [True, False], # enables BOOST_ALL_NO_LIB
"diagnostic_definitions": [True, False], # enables BOOST_LIB_DIAGNOSTIC
"python_executable": "ANY", # system default python installation is used, if None
"python_version": "ANY", # major.minor; computed automatically, if None
"namespace": "ANY", # custom boost namespace for bcp, e.g. myboost
"namespace_alias": [True, False], # enable namespace alias for bcp, boost=myboost
"multithreading": [True, False], # enables multithreading support
"numa": [True, False],
"zlib": [True, False],
"bzip2": [True, False],
"lzma": [True, False],
"zstd": [True, False],
"segmented_stacks": [True, False],
"debug_level": [i for i in range(0, 14)],
"pch": [True, False],
"extra_b2_flags": "ANY", # custom b2 flags
"i18n_backend": ["iconv", "icu", None, "deprecated"],
"i18n_backend_iconv": ["libc", "libiconv", "off"],
"i18n_backend_icu": [True, False],
"visibility": ["global", "protected", "hidden"],
"addr2line_location": "ANY",
"with_stacktrace_backtrace": [True, False],
"buildid": "ANY",
"python_buildid": "ANY",
}
options.update({"without_{}".format(_name): [True, False] for _name in CONFIGURE_OPTIONS})
default_options = {
"shared": False,
"header_only": False,
"error_code_header_only": False,
"system_no_deprecated": False,
"asio_no_deprecated": False,
"filesystem_no_deprecated": False,
"fPIC": True,
"layout": "system",
"magic_autolink": False,
"diagnostic_definitions": False,
"python_executable": "None",
"python_version": "None",
"namespace": "boost",
"namespace_alias": False,
"multithreading": True,
"numa": True,
"zlib": True,
"bzip2": True,
"lzma": False,
"zstd": False,
"segmented_stacks": False,
"debug_level": 0,
"pch": True,
"extra_b2_flags": "None",
"i18n_backend": "deprecated",
"i18n_backend_iconv": "libc",
"i18n_backend_icu": False,
"visibility": "hidden",
"addr2line_location": "/usr/bin/addr2line",
"with_stacktrace_backtrace": True,
"buildid": None,
"python_buildid": None,
}
default_options.update({"without_{}".format(_name): False for _name in CONFIGURE_OPTIONS})
default_options.update({"without_{}".format(_name): True for _name in ("graph_parallel", "mpi", "python")})
short_paths = True
no_copy_source = True
exports_sources = ['patches/*']
_cached_dependencies = None
def export(self):
self.copy(self._dependency_filename, src="dependencies", dst="dependencies")
@property
def _min_compiler_version_default_cxx11(self):
# Minimum compiler version having c++ standard >= 11
if self.settings.compiler == "apple-clang":
# For now, assume apple-clang will enable c++11 in the distant future
return 99
return {
"gcc": 6,
"clang": 6,
"Visual Studio": 14, # guess
}.get(str(self.settings.compiler))
@property
def _min_compiler_version_nowide(self):
# Nowide needs c++11 + swappable std::fstream
return {
"gcc": 5,
"clang": 5,
"Visual Studio": 14, # guess
}.get(str(self.settings.compiler))
@property
def _dependency_filename(self):
return "dependencies-{}.yml".format(self.version)
@property
def _dependencies(self):
if self._cached_dependencies is None:
dependencies_filepath = os.path.join(self.recipe_folder, "dependencies", self._dependency_filename)
if not os.path.isfile(dependencies_filepath):
raise ConanException("Cannot find {}".format(dependencies_filepath))
self._cached_dependencies = yaml.safe_load(open(dependencies_filepath))
return self._cached_dependencies
def _all_dependent_modules(self, name):
dependencies = {name}
while True:
new_dependencies = set()
for dependency in dependencies:
new_dependencies.update(set(self._dependencies["dependencies"][dependency]))
new_dependencies.update(dependencies)
if len(new_dependencies) > len(dependencies):
dependencies = new_dependencies
else:
break
return dependencies
def _all_super_modules(self, name):
dependencies = {name}
while True:
new_dependencies = set(dependencies)
for module in self._dependencies["dependencies"]:
if dependencies.intersection(set(self._dependencies["dependencies"][module])):
new_dependencies.add(module)
if len(new_dependencies) > len(dependencies):
dependencies = new_dependencies
else:
break
return dependencies
@property
def _source_subfolder(self):
return "source_subfolder"
@property
def _bcp_dir(self):
return "custom-boost"
@property
def _is_msvc(self):
return self.settings.compiler == "Visual Studio"
@property
def _is_clang_cl(self):
return self.settings.os == "Windows" and self.settings.compiler == "clang"
@property
def _zip_bzip2_requires_needed(self):
return not self.options.without_iostreams and not self.options.header_only
@property
def _python_executable(self):
"""
obtain full path to the python interpreter executable
:return: path to the python interpreter executable, either set by option, or system default
"""
exe = self.options.python_executable if self.options.python_executable else sys.executable
return str(exe).replace('\\', '/')
@property
def _is_windows_platform(self):
return self.settings.os in ["Windows", "WindowsStore", "WindowsCE"]
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
# Test whether all config_options from the yml are available in CONFIGURE_OPTIONS
for opt_name in self._configure_options:
if "without_{}".format(opt_name) not in self.options:
raise ConanException("{} has the configure options {} which is not available in conanfile.py".format(self._dependency_filename, opt_name))
# stacktrace_backtrace not supported on Windows
if self.settings.os == "Windows":
del self.options.with_stacktrace_backtrace
# nowide requires a c++11-able compiler + movable std::fstream: change default to not build on compiler with too old default c++ standard or too low compiler.cppstd
# json requires a c++11-able compiler: change default to not build on compiler with too old default c++ standard or too low compiler.cppstd
if self.settings.compiler.cppstd:
if not tools.valid_min_cppstd(self, 11):
self.options.without_fiber = True
self.options.without_nowide = True
self.options.without_json = True
else:
version_cxx11_standard_json = self._min_compiler_version_default_cxx11
if version_cxx11_standard_json:
if tools.Version(self.settings.compiler.version) < version_cxx11_standard_json:
self.options.without_fiber = True
self.options.without_json = True
self.options.without_nowide = True
else:
self.options.without_fiber = True
self.options.without_json = True
self.options.without_nowide = True
# iconv is off by default on Windows and Solaris
if self._is_windows_platform or self.settings.os == "SunOS":
self.options.i18n_backend_iconv = "off"
elif tools.is_apple_os(self.settings.os):
self.options.i18n_backend_iconv = "libiconv"
elif self.settings.os == "Android":
# bionic provides iconv since API level 28
api_level = self.settings.get_safe("os.api_level")
if api_level and tools.Version(api_level) < "28":
self.options.i18n_backend_iconv = "libiconv"
# Remove options not supported by this version of boost
for dep_name in CONFIGURE_OPTIONS:
if dep_name not in self._configure_options:
delattr(self.options, "without_{}".format(dep_name))
if self.settings.compiler == "Visual Studio":
# Shared builds of numa do not link on Visual Studio due to missing symbols
self.options.numa = False
if tools.Version(self.version) >= "1.76.0":
# Starting from 1.76.0, Boost.Math requires a c++11 capable compiler
# ==> disable it by default for older compilers or c++ standards
def disable_math():
super_modules = self._all_super_modules("math")
for smod in super_modules:
try:
setattr(self.options, "without_{}".format(smod), True)
except ConanException:
pass
if self.settings.compiler.cppstd:
if not tools.valid_min_cppstd(self, 11):
disable_math()
else:
min_compiler_version = self._min_compiler_version_default_cxx11
if min_compiler_version is None:
self.output.warn("Assuming the compiler supports c++11 by default")
elif tools.Version(self.settings.compiler.version) < min_compiler_version:
disable_math()
@property
def _configure_options(self):
return self._dependencies["configure_options"]
@property
def _fPIC(self):
return self.options.get_safe("fPIC", self.default_options["fPIC"])
@property
def _shared(self):
return self.options.get_safe("shared", self.default_options["shared"])
@property
def _stacktrace_addr2line_available(self):
if (self.settings.os in ["iOS", "watchOS", "tvOS"] or self.settings.get_safe("os.subsystem") == "catalyst"):
# sandboxed environment - cannot launch external processes (like addr2line), system() function is forbidden
return False
return not self.options.header_only and not self.options.without_stacktrace and self.settings.os != "Windows"
def configure(self):
if self.options.header_only:
del self.options.shared
del self.options.fPIC
elif self.options.shared:
del self.options.fPIC
if self.options.i18n_backend != "deprecated":
self.output.warn("i18n_backend option is deprecated, do not use anymore.")
if self.options.i18n_backend == "iconv":
self.options.i18n_backend_iconv = "libiconv"
self.options.i18n_backend_icu = False
if self.options.i18n_backend == "icu":
self.options.i18n_backend_iconv = "off"
self.options.i18n_backend_icu = True
if self.options.i18n_backend == "None":
self.options.i18n_backend_iconv = "off"
self.options.i18n_backend_icu = False
if self.options.without_locale:
del self.options.i18n_backend_iconv
del self.options.i18n_backend_icu
else:
if self.options.i18n_backend_iconv == "off" and not self.options.i18n_backend_icu and not self._is_windows_platform:
raise ConanInvalidConfiguration("Boost.Locale library needs either iconv or ICU library to be built on non windows platforms")
if not self.options.without_python:
if not self.options.python_version:
self.options.python_version = self._detect_python_version()
self.options.python_executable = self._python_executable
else:
del self.options.python_buildid
if self._stacktrace_addr2line_available:
if os.path.abspath(str(self.options.addr2line_location)) != str(self.options.addr2line_location):
raise ConanInvalidConfiguration("addr2line_location must be an absolute path to addr2line")
else:
del self.options.addr2line_location
if self.options.get_safe("without_stacktrace", True):
del self.options.with_stacktrace_backtrace
if self.options.layout == "b2-default":
self.options.layout = "versioned" if self.settings.os == "Windows" else "system"
if self.options.without_fiber:
del self.options.numa
def validate(self):
if not self.options.multithreading:
# * For the reason 'thread' is deactivate look at https://stackoverflow.com/a/20991533
# Look also on the comments of the answer for more details
# * Although the 'context' and 'atomic' library does not mention anything about threading,
# when being build the compiler uses the -pthread flag, which makes it quite dangerous
for lib in ['locale', 'coroutine', 'wave', 'type_erasure', 'fiber', 'thread', 'context', 'atomic']:
if not self.options.get_safe('without_%s' % lib):
raise ConanInvalidConfiguration("Boost '%s' library requires multi threading" % lib)
if self.settings.compiler == "Visual Studio" and self._shared:
if "MT" in str(self.settings.compiler.runtime):
raise ConanInvalidConfiguration("Boost can not be built as shared library with MT runtime.")
if self.options.get_safe("numa"):
raise ConanInvalidConfiguration("Cannot build a shared boost with numa support on Visual Studio")
# Check, when a boost module is enabled, whether the boost modules it depends on are enabled as well.
for mod_name, mod_deps in self._dependencies["dependencies"].items():
if not self.options.get_safe("without_{}".format(mod_name), True):
for mod_dep in mod_deps:
if self.options.get_safe("without_{}".format(mod_dep), False):
raise ConanInvalidConfiguration("{} requires {}: {} is disabled".format(mod_name, mod_deps, mod_dep))
if not self.options.get_safe("without_nowide", True):
# nowide require a c++11-able compiler with movable std::fstream
mincompiler_version = self._min_compiler_version_nowide
if mincompiler_version:
if tools.Version(self.settings.compiler.version) < mincompiler_version:
raise ConanInvalidConfiguration("This compiler is too old to build Boost.nowide.")
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 11)
else:
version_cxx11_standard = self._min_compiler_version_default_cxx11
if version_cxx11_standard:
if tools.Version(self.settings.compiler.version) < version_cxx11_standard:
raise ConanInvalidConfiguration("Boost.{fiber,json} require a c++11 compiler (please set compiler.cppstd or use a newer compiler)")
else:
self.output.warn("I don't know what the default c++ standard of this compiler is. I suppose it supports c++11 by default.\n"
"This might cause some boost libraries not being built and conan components to fail.")
if not all((self.options.without_fiber, self.options.get_safe("without_json", True))):
# fiber/json require a c++11-able compiler.
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 11)
else:
version_cxx11_standard = self._min_compiler_version_default_cxx11
if version_cxx11_standard:
if tools.Version(self.settings.compiler.version) < version_cxx11_standard:
raise ConanInvalidConfiguration("Boost.{fiber,json} requires a c++11 compiler (please set compiler.cppstd or use a newer compiler)")
else:
self.output.warn("I don't know what the default c++ standard of this compiler is. I suppose it supports c++11 by default.\n"
"This might cause some boost libraries not being built and conan components to fail.")
if tools.Version(self.version) >= "1.76.0":
# Starting from 1.76.0, Boost.Math requires a c++11 capable compiler
if not self.options.without_math:
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 11)
else:
min_compiler_version = self._min_compiler_version_default_cxx11
if min_compiler_version is not None:
if tools.Version(self.settings.compiler.version) < min_compiler_version:
raise ConanInvalidConfiguration("Boost.Math requires a C++11 capable compiler")
def build_requirements(self):
if not self.options.header_only:
self.build_requires("b2/4.5.0")
def _with_dependency(self, dependency):
"""
Return true when dependency is required according to the dependencies-x.y.z.yml file
"""
for name, reqs in self._dependencies["requirements"].items():
if dependency in reqs:
if not self.options.get_safe("without_{}".format(name), True):
return True
return False
@property
def _with_zlib(self):
return not self.options.header_only and self._with_dependency("zlib") and self.options.zlib
@property
def _with_bzip2(self):
return not self.options.header_only and self._with_dependency("bzip2") and self.options.bzip2
@property
def _with_lzma(self):
return not self.options.header_only and self._with_dependency("lzma") and self.options.lzma
@property
def _with_zstd(self):
return not self.options.header_only and self._with_dependency("zstd") and self.options.zstd
@property
def _with_icu(self):
return not self.options.header_only and self._with_dependency("icu") and self.options.get_safe("i18n_backend_icu")
@property
def _with_iconv(self):
return not self.options.header_only and self._with_dependency("iconv") and self.options.get_safe("i18n_backend_iconv") == "libiconv"
@property
def _with_stacktrace_backtrace(self):
return not self.options.header_only and self.options.get_safe("with_stacktrace_backtrace", False)
def requirements(self):
if self._with_zlib:
self.requires("zlib/1.2.11")
if self._with_bzip2:
self.requires("bzip2/1.0.8")
if self._with_lzma:
self.requires("xz_utils/5.2.5")
if self._with_zstd:
self.requires("zstd/1.5.0")
if self._with_stacktrace_backtrace:
self.requires("libbacktrace/cci.20210118")
if self._with_icu:
self.requires("icu/68.2")
if self._with_iconv:
self.requires("libiconv/1.16")
def package_id(self):
del self.info.options.i18n_backend
if self.options.header_only:
self.info.header_only()
self.info.options.header_only = True
else:
del self.info.options.debug_level
del self.info.options.pch
del self.info.options.python_executable # PATH to the interpreter is not important, only version matters
if self.options.without_python:
del self.info.options.python_version
else:
self.info.options.python_version = self._python_version
def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
##################### BUILDING METHODS ###########################
def _run_python_script(self, script):
"""
execute python one-liner script and return its output
:param script: string containing python script to be executed
:return: output of the python script execution, or None, if script has failed
"""
output = StringIO()
command = '"%s" -c "%s"' % (self._python_executable, script)
self.output.info('running %s' % command)
try:
self.run(command=command, output=output)
except ConanException:
self.output.info("(failed)")
return None
output = output.getvalue()
# Conan is broken when run_to_output = True
if "\n-----------------\n" in output:
output = output.split("\n-----------------\n", 1)[1]
output = output.strip()
return output if output != "None" else None
def _get_python_path(self, name):
"""
obtain path entry for the python installation
:param name: name of the python config entry for path to be queried (such as "include", "platinclude", etc.)
:return: path entry from the sysconfig
"""
# https://docs.python.org/3/library/sysconfig.html
# https://docs.python.org/2.7/library/sysconfig.html
return self._run_python_script("from __future__ import print_function; "
"import sysconfig; "
"print(sysconfig.get_path('%s'))" % name)
def _get_python_sc_var(self, name):
"""
obtain value of python sysconfig variable
:param name: name of variable to be queried (such as LIBRARY or LDLIBRARY)
:return: value of python sysconfig variable
"""
return self._run_python_script("from __future__ import print_function; "
"import sysconfig; "
"print(sysconfig.get_config_var('%s'))" % name)
def _get_python_du_var(self, name):
"""
obtain value of python distutils sysconfig variable
(sometimes sysconfig returns empty values, while python.sysconfig provides correct values)
:param name: name of variable to be queried (such as LIBRARY or LDLIBRARY)
:return: value of python sysconfig variable
"""
return self._run_python_script("from __future__ import print_function; "
"import distutils.sysconfig as du_sysconfig; "
"print(du_sysconfig.get_config_var('%s'))" % name)
def _get_python_var(self, name):
"""
obtain value of python variable, either by sysconfig, or by distutils.sysconfig
:param name: name of variable to be queried (such as LIBRARY or LDLIBRARY)
:return: value of python sysconfig variable
"""
return self._get_python_sc_var(name) or self._get_python_du_var(name)
def _detect_python_version(self):
"""
obtain version of python interpreter
:return: python interpreter version, in format major.minor
"""
return self._run_python_script("from __future__ import print_function; "
"import sys; "
"print('%s.%s' % (sys.version_info[0], sys.version_info[1]))")
@property
def _python_version(self):
version = self._detect_python_version()
if self.options.python_version and version != self.options.python_version:
raise ConanInvalidConfiguration("detected python version %s doesn't match conan option %s" % (version,
self.options.python_version))
return version
@property
def _python_inc(self):
"""
obtain the result of the "sysconfig.get_python_inc()" call
:return: result of the "sysconfig.get_python_inc()" execution
"""
return self._run_python_script("from __future__ import print_function; "
"import sysconfig; "
"print(sysconfig.get_python_inc())")
@property
def _python_abiflags(self):
"""
obtain python ABI flags, see https://www.python.org/dev/peps/pep-3149/ for the details
:return: the value of python ABI flags
"""
return self._run_python_script("from __future__ import print_function; "
"import sys; "
"print(getattr(sys, 'abiflags', ''))")
@property
def _python_includes(self):
"""
attempt to find directory containing Python.h header file
:return: the directory with python includes
"""
include = self._get_python_path('include')
plat_include = self._get_python_path('platinclude')
include_py = self._get_python_var('INCLUDEPY')
include_dir = self._get_python_var('INCLUDEDIR')
python_inc = self._python_inc
candidates = [include,
plat_include,
include_py,
include_dir,
python_inc]
for candidate in candidates:
if candidate:
python_h = os.path.join(candidate, 'Python.h')
self.output.info('checking %s' % python_h)
if os.path.isfile(python_h):
self.output.info('found Python.h: %s' % python_h)
return candidate.replace('\\', '/')
raise Exception("couldn't locate Python.h - make sure you have installed python development files")
@property
def _python_libraries(self):
"""
attempt to find python development library
:return: the full path to the python library to be linked with
"""
library = self._get_python_var("LIBRARY")
ldlibrary = self._get_python_var("LDLIBRARY")
libdir = self._get_python_var("LIBDIR")
multiarch = self._get_python_var("MULTIARCH")
masd = self._get_python_var("multiarchsubdir")
with_dyld = self._get_python_var("WITH_DYLD")
if libdir and multiarch and masd:
if masd.startswith(os.sep):
masd = masd[len(os.sep):]
libdir = os.path.join(libdir, masd)
if not libdir:
libdest = self._get_python_var("LIBDEST")
libdir = os.path.join(os.path.dirname(libdest), "libs")
candidates = [ldlibrary, library]
library_prefixes = [""] if self._is_msvc else ["", "lib"]
library_suffixes = [".lib"] if self._is_msvc else [".so", ".dll.a", ".a"]
if with_dyld:
library_suffixes.insert(0, ".dylib")
python_version = self._python_version
python_version_no_dot = python_version.replace(".", "")
versions = ["", python_version, python_version_no_dot]
abiflags = self._python_abiflags
for prefix in library_prefixes:
for suffix in library_suffixes:
for version in versions:
candidates.append("%spython%s%s%s" % (prefix, version, abiflags, suffix))
for candidate in candidates:
if candidate:
python_lib = os.path.join(libdir, candidate)
self.output.info('checking %s' % python_lib)
if os.path.isfile(python_lib):
self.output.info('found python library: %s' % python_lib)
return python_lib.replace('\\', '/')
raise ConanInvalidConfiguration("couldn't locate python libraries - make sure you have installed python development files")
def _clean(self):
src = os.path.join(self.source_folder, self._source_subfolder)
clean_dirs = [os.path.join(self.build_folder, "bin.v2"),
os.path.join(self.build_folder, "architecture"),
os.path.join(self.source_folder, self._bcp_dir),
os.path.join(src, "dist", "bin"),
os.path.join(src, "stage"),
os.path.join(src, "tools", "build", "src", "engine", "bootstrap"),
os.path.join(src, "tools", "build", "src", "engine", "bin.ntx86"),
os.path.join(src, "tools", "build", "src", "engine", "bin.ntx86_64")]
for d in clean_dirs:
if os.path.isdir(d):
self.output.warn('removing "%s"' % d)
shutil.rmtree(d)
@property
def _b2_exe(self):
return "b2.exe" if tools.os_info.is_windows else "b2"
@property
def _bcp_exe(self):
folder = os.path.join(self.source_folder, self._source_subfolder, "dist", "bin")
return os.path.join(folder, "bcp.exe" if tools.os_info.is_windows else "bcp")
@property
def _use_bcp(self):
return self.options.namespace != "boost"
@property
def _boost_dir(self):
return self._bcp_dir if self._use_bcp else self._source_subfolder
@property
def _boost_build_dir(self):
return os.path.join(self.source_folder, self._source_subfolder, "tools", "build")
def _build_bcp(self):
folder = os.path.join(self.source_folder, self._source_subfolder, 'tools', 'bcp')
with tools.vcvars(self.settings) if self._is_msvc else tools.no_op():
with tools.chdir(folder):
command = "%s -j%s --abbreviate-paths toolset=%s" % (self._b2_exe, tools.cpu_count(), self._toolset)
command += " -d%d" % self.options.debug_level
self.output.warn(command)
self.run(command, run_environment=True)
def _run_bcp(self):
with tools.vcvars(self.settings) if self._is_msvc or self._is_clang_cl else tools.no_op():
with tools.chdir(self.source_folder):
os.mkdir(self._bcp_dir)
namespace = "--namespace=%s" % self.options.namespace
alias = "--namespace-alias" if self.options.namespace_alias else ""
boostdir = "--boost=%s" % self._source_subfolder
libraries = {"build", "boost-build.jam", "boostcpp.jam", "boost_install", "headers"}
for d in os.listdir(os.path.join(self._source_subfolder, "boost")):
if os.path.isdir(os.path.join(self._source_subfolder, "boost", d)):
libraries.add(d)
for d in os.listdir(os.path.join(self._source_subfolder, "libs")):
if os.path.isdir(os.path.join(self._source_subfolder, "libs", d)):
libraries.add(d)
libraries = ' '.join(libraries)
command = "{bcp} {namespace} {alias} " \
"{boostdir} {libraries} {outdir}".format(bcp=self._bcp_exe,
namespace=namespace,
alias=alias,
libraries=libraries,
boostdir=boostdir,
outdir=self._bcp_dir)
self.output.warn(command)
self.run(command)
def build(self):
if tools.cross_building(self.settings, skip_x64_x86=True):
# When cross building, do not attempt to run the test-executable (assume they work)
tools.replace_in_file(os.path.join(self.source_folder, self._source_subfolder, "libs", "stacktrace", "build", "Jamfile.v2"),
"$(>) > $(<)",
"echo \"\" > $(<)", strict=False)
# Older clang releases require a thread_local variable to be initialized by a constant value
tools.replace_in_file(os.path.join(self.source_folder, self._source_subfolder, "boost", "stacktrace", "detail", "libbacktrace_impls.hpp"),
"/* thread_local */", "thread_local", strict=False)
tools.replace_in_file(os.path.join(self.source_folder, self._source_subfolder, "boost", "stacktrace", "detail", "libbacktrace_impls.hpp"),
"/* static __thread */", "static __thread", strict=False)
if self.settings.compiler == "apple-clang" or (self.settings.compiler == "clang" and tools.Version(self.settings.compiler.version) < 6):
tools.replace_in_file(os.path.join(self.source_folder, self._source_subfolder, "boost", "stacktrace", "detail", "libbacktrace_impls.hpp"),
"thread_local", "/* thread_local */")
tools.replace_in_file(os.path.join(self.source_folder, self._source_subfolder, "boost", "stacktrace", "detail", "libbacktrace_impls.hpp"),
"static __thread", "/* static __thread */")
tools.replace_in_file(os.path.join(self.source_folder, self._source_subfolder, "tools", "build", "src", "tools", "gcc.jam"),
"local generic-os = [ set.difference $(all-os) : aix darwin vxworks solaris osf hpux ] ;",
"local generic-os = [ set.difference $(all-os) : aix darwin vxworks solaris osf hpux iphone appletv ] ;",
strict=False)
tools.replace_in_file(os.path.join(self.source_folder, self._source_subfolder, "tools", "build", "src", "tools", "gcc.jam"),
"local no-threading = android beos haiku sgi darwin vxworks ;",
"local no-threading = android beos haiku sgi darwin vxworks iphone appletv ;",
strict=False)
if self.options.header_only:
self.output.warn("Header only package, skipping build")
return
self._clean()
if self._use_bcp:
self._build_bcp()
self._run_bcp()
# Help locating bzip2 and zlib
self._create_user_config_jam(self._boost_build_dir)
# JOIN ALL FLAGS
b2_flags = " ".join(self._build_flags)
full_command = "%s %s" % (self._b2_exe, b2_flags)
# -d2 is to print more debug info and avoid travis timing out without output
sources = os.path.join(self.source_folder, self._boost_dir)
full_command += ' --debug-configuration --build-dir="%s"' % self.build_folder
self.output.warn(full_command)
with tools.vcvars(self.settings) if self._is_msvc else tools.no_op():
with tools.chdir(sources):
# To show the libraries *1
# self.run("%s --show-libraries" % b2_exe)
self.run(full_command, run_environment=True)
@property
def _b2_os(self):
return {"Windows": "windows",
"WindowsStore": "windows",
"Linux": "linux",
"Android": "android",
"Macos": "darwin",
"iOS": "iphone",
"watchOS": "iphone",
"tvOS": "appletv",
"FreeBSD": "freebsd",
"SunOS": "solaris"}.get(str(self.settings.os))
@property
def _b2_address_model(self):
if self.settings.arch in ("x86_64", "ppc64", "ppc64le", "mips64", "armv8", "armv8.3", "sparcv9"):
return "64"
else:
return "32"
@property
def _b2_binary_format(self):
return {"Windows": "pe",
"WindowsStore": "pe",
"Linux": "elf",
"Android": "elf",
"Macos": "mach-o",
"iOS": "mach-o",
"watchOS": "mach-o",
"tvOS": "mach-o",
"FreeBSD": "elf",
"SunOS": "elf"}.get(str(self.settings.os))
@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'
elif str(self.settings.arch).startswith('sparc'):
return 'sparc'
elif str(self.settings.arch).startswith('mips64'):
return 'mips64'
elif str(self.settings.arch).startswith('mips'):
return 'mips1'
else:
return None
@property
def _b2_abi(self):
if str(self.settings.arch).startswith('x86'):
return "ms" if str(self.settings.os) in ["Windows", "WindowsStore"] else "sysv"
elif str(self.settings.arch).startswith('ppc'):
return "sysv"
elif str(self.settings.arch).startswith('arm'):
return "aapcs"
elif str(self.settings.arch).startswith('mips'):
return "o32"
else:
return None
@property
def _gnu_cxx11_abi(self):
"""Checks libcxx setting and returns value for the GNU C++11 ABI flag
_GLIBCXX_USE_CXX11_ABI= . Returns None if C++ library cannot be
determined.
"""
try:
if str(self.settings.compiler.libcxx) == "libstdc++":
return "0"
elif str(self.settings.compiler.libcxx) == "libstdc++11":
return "1"
except:
pass
return None
@property
def _build_flags(self):
flags = self._build_cross_flags
# Stop at the first error. No need to continue building.
flags.append("-q")
if self.options.get_safe("numa"):
flags.append("numa=on")
# https://www.boost.org/doc/libs/1_70_0/libs/context/doc/html/context/architectures.html
if self._b2_os:
flags.append("target-os=%s" % self._b2_os)
if self._b2_architecture:
flags.append("architecture=%s" % self._b2_architecture)
if self._b2_address_model:
flags.append("address-model=%s" % self._b2_address_model)
if self._b2_binary_format:
flags.append("binary-format=%s" % self._b2_binary_format)
if self._b2_abi:
flags.append("abi=%s" % self._b2_abi)
flags.append("--layout=%s" % self.options.layout)
flags.append("--user-config=%s" % os.path.join(self._boost_build_dir, 'user-config.jam'))
flags.append("-sNO_ZLIB=%s" % ("0" if self._with_zlib else "1"))
flags.append("-sNO_BZIP2=%s" % ("0" if self._with_bzip2 else "1"))
flags.append("-sNO_LZMA=%s" % ("0" if self._with_lzma else "1"))
flags.append("-sNO_ZSTD=%s" % ("0" if self._with_zstd else "1"))
if self.options.get_safe("i18n_backend_icu"):
flags.append("boost.locale.icu=on")
else:
flags.append("boost.locale.icu=off")
flags.append("--disable-icu")
if self.options.get_safe("i18n_backend_iconv") in ["libc", "libiconv"]:
flags.append("boost.locale.iconv=on")
if self.options.get_safe("i18n_backend_iconv") == "libc":
flags.append("boost.locale.iconv.lib=libc")
else:
flags.append("boost.locale.iconv.lib=libiconv")
else:
flags.append("boost.locale.iconv=off")
flags.append("--disable-iconv")
def add_defines(library):
for define in self.deps_cpp_info[library].defines:
flags.append("define=%s" % define)
if self._with_zlib:
add_defines("zlib")
if self._with_bzip2:
add_defines("bzip2")
if self._with_lzma:
add_defines("xz_utils")
if self._with_zstd:
add_defines("zstd")
if self._is_msvc:
flags.append("runtime-link=%s" % ("static" if "MT" in str(self.settings.compiler.runtime) else "shared"))
flags.append("runtime-debugging=%s" % ("on" if "d" in str(self.settings.compiler.runtime) else "off"))
# For details https://boostorg.github.io/build/manual/master/index.html
flags.append("threading=%s" % ("single" if not self.options.multithreading else "multi" ))
flags.append("visibility=%s" % self.options.visibility)
flags.append("link=%s" % ("shared" if self._shared else "static"))
if self.settings.build_type == "Debug":
flags.append("variant=debug")
else:
flags.append("variant=release")
for libname in self._configure_options:
if not getattr(self.options, "without_%s" % libname):
flags.append("--with-%s" % libname)
flags.append("toolset=%s" % self._toolset)
if self.settings.get_safe("compiler.cppstd"):
flags.append("cxxflags=%s" % cppstd_flag(self.settings))
# LDFLAGS
link_flags = []
# CXX FLAGS
cxx_flags = []
# fPIC DEFINITION
if self._fPIC:
cxx_flags.append("-fPIC")
if self.settings.build_type == "RelWithDebInfo":
if self.settings.compiler == "gcc" or "clang" in str(self.settings.compiler):
cxx_flags.append("-g")
elif self.settings.compiler == "Visual Studio":
cxx_flags.append("/Z7")
# Standalone toolchain fails when declare the std lib
if self.settings.os not in ("Android", "Emscripten"):
try: