boostcpp.jam 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. # Boost.Build support specific for the Boost C++ Libraries.
  2. # Copyright Vladimir Prus 2002-2010.
  3. # Copyright Dave Abrahams 2005-2006.
  4. # Copyright Rene Rivera 2005-2007.
  5. # Copyright Douglas Gregor 2005.
  6. #
  7. # Distributed under the Boost Software License, Version 1.0.
  8. # (See accompanying file LICENSE_1_0.txt or copy at
  9. # http://www.boost.org/LICENSE_1_0.txt)
  10. import "class" : new ;
  11. import common ;
  12. import configure ;
  13. import build-system ;
  14. import generate ;
  15. import modules ;
  16. import option ;
  17. import os ;
  18. import package ;
  19. import path ;
  20. import project ;
  21. import regex ;
  22. import sequence ;
  23. import set ;
  24. import targets ;
  25. import feature ;
  26. import property ;
  27. import version : version-less ;
  28. ##############################################################################
  29. #
  30. # 0. General setup. Parse options, check them.
  31. #
  32. ##############################################################################
  33. BOOST_ROOT = [ modules.binding $(__name__) ] ;
  34. BOOST_ROOT = $(BOOST_ROOT:D) ;
  35. rule set-version ( version )
  36. {
  37. BOOST_VERSION = $(version) ;
  38. local version-tag =
  39. [ MATCH "^([^.]+)[.]([^.]+)[.]([^.]+)" : $(BOOST_VERSION) ] ;
  40. if $(version-tag[3]) = 0
  41. {
  42. version-tag = $(version-tag[1-2]) ;
  43. }
  44. BOOST_VERSION_TAG = $(version-tag:J=_) ;
  45. }
  46. # Option to choose how many variants to build. The default is "minimal".
  47. build-type = [ option.get build-type ] ;
  48. build-type ?= minimal ;
  49. if ! ( $(build-type) in complete minimal )
  50. {
  51. EXIT The value of the --build-type option should be either 'complete' or
  52. 'minimal' ;
  53. }
  54. # What kind of layout are we doing?
  55. layout = [ option.get layout : "" ] ;
  56. layout = [ MATCH (versioned|tagged|system)(-(.+))? : $(layout) ] ;
  57. if $(layout[3])
  58. {
  59. layout-version = $(layout[3]) ;
  60. layout = $(layout[1]) ;
  61. if [ version-less [ regex.split $(layout-version) "[.]" ] : 1 66 ]
  62. {
  63. layout-version = 1.40 ;
  64. }
  65. else if [ version-less [ regex.split $(layout-version) "[.]" ] : 1 69 ]
  66. {
  67. layout-version = 1.66 ;
  68. }
  69. }
  70. layout-version ?= 1.69 ;
  71. # On Windows, we used versioned layout by default in order to be compatible with
  72. # autolink. On other systems, we use system layout which is what every other
  73. # program uses. Note that the Windows check is static, and will not be affected
  74. # by specific build properties used.
  75. if ! $(layout)
  76. {
  77. if [ os.name ] = NT
  78. {
  79. layout = versioned ;
  80. }
  81. else
  82. {
  83. layout = system ;
  84. }
  85. }
  86. layout-$(layout) = true ;
  87. if $(layout) = system && $(build-type) = complete
  88. {
  89. ECHO error\: Cannot use --layout=system with --build-type complete. ;
  90. ECHO error\: Please use either --layout=versioned or --layout=tagged ;
  91. ECHO error\: if you wish to build multiple variants. ;
  92. if [ os.name ] != NT
  93. {
  94. ECHO error\: Note that --layout=system is used by default on Unix
  95. starting with Boost 1.40. ;
  96. }
  97. EXIT ;
  98. }
  99. # Possible stage only location.
  100. stage-locate = [ option.get stagedir ] ;
  101. if $(stage-locate)
  102. {
  103. stage-locate = [ path.root [ path.make $(stage-locate) ] [ path.pwd ] ] ;
  104. }
  105. else
  106. {
  107. stage-locate = $(BOOST_ROOT)/stage ;
  108. }
  109. BOOST_STAGE_LOCATE = $(stage-locate) ;
  110. # Custom build ID.
  111. build-id = [ option.get buildid ] ;
  112. if $(build-id)
  113. {
  114. BUILD_ID = [ regex.replace $(build-id) "[*\\/:.\"\' ]" _ ] ;
  115. }
  116. # Python build id (for Python libraries only).
  117. python-id = [ option.get "python-buildid" ] ;
  118. if $(python-id)
  119. {
  120. PYTHON_ID = [ regex.replace $(python-id) "[*\\/:.\"\']" _ ] ;
  121. }
  122. if $(layout) = versioned
  123. {
  124. switch $(layout-version)
  125. {
  126. case 1.40 :
  127. .format-name-args =
  128. <base> <toolset> <threading> <runtime> ;
  129. case 1.66 :
  130. .format-name-args =
  131. <base> <toolset> <threading> <runtime> <arch-and-model> ;
  132. case 1.69 :
  133. .format-name-args =
  134. <base> <toolset> <threading> <runtime> <arch-and-model> ;
  135. }
  136. }
  137. else if $(layout) = tagged
  138. {
  139. switch $(layout-version)
  140. {
  141. case 1.40 :
  142. .format-name-args =
  143. <base> <threading> <runtime> ;
  144. case 1.66 :
  145. .format-name-args =
  146. <base> <threading> <runtime> ;
  147. case 1.69 :
  148. .format-name-args =
  149. <base> <threading> <runtime> <arch-and-model> ;
  150. }
  151. }
  152. else if $(layout) = system
  153. {
  154. .format-name-args = <base> ;
  155. }
  156. else
  157. {
  158. .format-name-error = true ;
  159. }
  160. ################################################################################
  161. #
  162. # 1. 'tag' function adding decorations suitable to the properties if versioned
  163. # or tagged layout is requested. Called from Jamroot.
  164. #
  165. ################################################################################
  166. rule tag ( name : type ? : property-set )
  167. {
  168. if $(type:E=x) in STATIC_LIB SHARED_LIB IMPORT_LIB
  169. {
  170. local args = $(.format-name-args) ;
  171. if $(layout) = versioned
  172. {
  173. args += -$(BOOST_VERSION_TAG) ;
  174. }
  175. local result = [ common.format-name
  176. $(args) -$(BUILD_ID)
  177. : $(name) : $(type) : $(property-set) ] ;
  178. if $(.format-name-error)
  179. {
  180. EXIT error\: invalid layout '$(layout:E=)' ;
  181. }
  182. # Optionally add version suffix. On NT, library with version suffix will
  183. # not be recognized by linkers. On CYGWIN, we get strage duplicate
  184. # symbol errors when library is generated with version suffix. On OSX,
  185. # version suffix is not needed -- the linker expects the
  186. # libFoo.1.2.3.dylib format. AIX linkers do not accept version suffixes
  187. # either. Pgi compilers can not accept a library with version suffix.
  188. # For android, if we link to libFoo.so, which is a soft link to libFoo.so.1.2.3,
  189. # the android studio will only pack the former into the final apk.
  190. if $(type) = SHARED_LIB &&
  191. ! [ $(property-set).get <target-os> ] in windows cygwin darwin aix android &&
  192. ! [ $(property-set).get <toolset> ] in pgi
  193. {
  194. result = $(result).$(BOOST_VERSION) ;
  195. }
  196. return $(result) ;
  197. }
  198. }
  199. # Specialized tag function to use for libraries linking to Python.
  200. # Appends value of --python-buildid if provided.
  201. rule python-tag ( name : type ? : property-set )
  202. {
  203. local result = $(name) ;
  204. if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB
  205. {
  206. # Add Python version suffix
  207. local version = [ $(property-set).get <python> ] ;
  208. local major-minor = [ MATCH "^([0-9]+)\.([0-9]+)" : $(version) ] ;
  209. local suffix = $(major-minor:J="") ;
  210. if $(suffix)
  211. {
  212. result = $(result)$(suffix) ;
  213. }
  214. # Add PYTHON_ID if supplied
  215. if $(PYTHON_ID)
  216. {
  217. result = $(result)-$(PYTHON_ID) ;
  218. }
  219. }
  220. # forward to the boost tagging rule
  221. return [ tag $(result) : $(type) : $(property-set) ] ;
  222. }
  223. ################################################################################
  224. #
  225. # 2. Declare targets that build and install all libraries. Specifically:
  226. #
  227. # - 'stage-proper' that puts all libraries in stage/lib
  228. # - 'install-proper' that install libraries and headers to system location
  229. #
  230. ################################################################################
  231. rule declare_install_and_stage_proper_targets ( libraries * )
  232. {
  233. local p = [ project.current ] ;
  234. local install-targets ;
  235. local stage-targets ;
  236. for local library in $(libraries)
  237. {
  238. local mp = [ project.search /boost/$(library) ] ;
  239. if $(mp)
  240. {
  241. install-targets += /boost/$(library)//install ;
  242. stage-targets += /boost/$(library)//stage ;
  243. }
  244. else
  245. {
  246. install-targets += libs/$(library)/build//install ;
  247. stage-targets += libs/$(library)/build//stage ;
  248. }
  249. }
  250. alias install-proper : $(install-targets) ;
  251. $(p).mark-target-as-explicit install-proper ;
  252. alias stage-proper : $(stage-targets) ;
  253. $(p).mark-target-as-explicit stage-proper ;
  254. }
  255. ################################################################################
  256. #
  257. # 3. Declare top-level targets 'stage' and 'install'. These examine the
  258. # --build-type option and, in case it is 'complete', build the 'install-proper'
  259. # and 'stage-proper' targets with a number of property sets.
  260. #
  261. ################################################################################
  262. rule emit-shared-static-warning ( )
  263. {
  264. if ! $(.shared-static-warning-emitted)
  265. {
  266. ECHO "" ;
  267. ECHO "warning: The configuration link=shared, runtime-link=static is disabled" ;
  268. ECHO "warning: by default as being too dangerous to use, and will not be built." ;
  269. ECHO "warning: To enable it, use --allow-shared-static." ;
  270. ECHO "" ;
  271. .shared-static-warning-emitted = 1 ;
  272. }
  273. }
  274. class top-level-target : alias-target-class
  275. {
  276. import modules ;
  277. import boostcpp ;
  278. rule __init__ ( name : project : sources * : requirements *
  279. : default-build * : usage-requirements * )
  280. {
  281. alias-target-class.__init__ $(name) : $(project) : $(sources) :
  282. $(requirements) : $(default-build) : $(usage-requirements) ;
  283. self.build-type = [ modules.peek boostcpp : build-type ] ;
  284. # On Linux, we build the release variant by default, since few users
  285. # will ever want to debug C++ Boost libraries, and there is no ABI
  286. # incompatibility between debug and release variants. We build shared
  287. # and static libraries since that is what most packages seem to provide
  288. # (.so in libfoo and .a in libfoo-dev).
  289. self.minimal-properties = [ property-set.create <variant>release
  290. <threading>multi <link>shared <link>static <runtime-link>shared ] ;
  291. # On Windows, new IDE projects use:
  292. #
  293. # runtime-link=dynamic, threading=multi, variant=(debug|release)
  294. #
  295. # and in addition, C++ Boost's autolink defaults to static linking.
  296. self.minimal-properties-win = [ property-set.create <variant>debug
  297. <variant>release <threading>multi <link>static <runtime-link>shared
  298. <address-model>32 <address-model>64 ] ;
  299. self.complete-properties = [ property-set.create
  300. <variant>debug <variant>release
  301. <threading>multi
  302. <link>shared <link>static
  303. <runtime-link>shared <runtime-link>static ] ;
  304. self.complete-properties-win = [ property-set.create
  305. <variant>debug <variant>release
  306. <threading>multi
  307. <link>shared <link>static
  308. <runtime-link>shared <runtime-link>static
  309. <address-model>32 <address-model>64 ] ;
  310. }
  311. rule generate ( property-set )
  312. {
  313. modules.poke : top-level-targets : [ modules.peek : top-level-targets ]
  314. $(self.name) ;
  315. local os = [ $(property-set).get <target-os> ] ;
  316. # Because we completely override the parent's 'generate' we need to
  317. # check for default feature values ourselves.
  318. if ! $(os)
  319. {
  320. os = [ feature.defaults <target-os> ] ;
  321. os = $(os:G=) ;
  322. }
  323. local build-type-set ;
  324. if $(self.build-type) = minimal
  325. {
  326. if $(os) = windows
  327. {
  328. build-type-set = $(self.minimal-properties-win) ;
  329. }
  330. else
  331. {
  332. build-type-set = $(self.minimal-properties) ;
  333. }
  334. }
  335. else if $(self.build-type) = complete
  336. {
  337. if $(os) = windows
  338. {
  339. build-type-set = $(self.complete-properties-win) ;
  340. }
  341. else
  342. {
  343. build-type-set = $(self.complete-properties) ;
  344. }
  345. }
  346. else
  347. {
  348. import errors ;
  349. errors.error "Unknown build type" ;
  350. }
  351. if $(build-type-set)
  352. {
  353. local expanded = [ targets.apply-default-build $(property-set)
  354. : $(build-type-set) ] ;
  355. # Filter inappropriate combinations.
  356. local filtered ;
  357. local skipped ;
  358. local argv = [ modules.peek : ARGV ] ;
  359. for local p in $(expanded)
  360. {
  361. # See comment in handle-static-runtime regarding this logic.
  362. if [ $(p).get <link> ] = shared
  363. && [ $(p).get <runtime-link> ] = static
  364. && [ $(p).get <toolset> ] != cw
  365. && ! --allow-shared-static in $(argv)
  366. {
  367. # Skip this.
  368. skipped += $(p) ;
  369. }
  370. else
  371. {
  372. filtered += $(p) ;
  373. }
  374. }
  375. if $(expanded) = $(skipped)
  376. {
  377. boostcpp.emit-shared-static-warning ;
  378. }
  379. return [ build-multiple $(filtered) ] ;
  380. }
  381. }
  382. rule build-multiple ( property-sets * )
  383. {
  384. local usage-requirements = [ property-set.empty ] ;
  385. local result ;
  386. for local p in $(property-sets)
  387. {
  388. local r = [ alias-target-class.generate $(p) ] ;
  389. if $(r)
  390. {
  391. usage-requirements = [ $(usage-requirements).add $(r[1]) ] ;
  392. result += $(r[2-]) ;
  393. }
  394. }
  395. return $(usage-requirements) [ sequence.unique $(result) ] ;
  396. }
  397. }
  398. rule declare_top_level_targets ( libraries * )
  399. {
  400. declare_install_and_stage_proper_targets $(libraries) ;
  401. targets.create-metatarget top-level-target : [ project.current ]
  402. : install
  403. : install-proper
  404. ;
  405. targets.create-metatarget top-level-target : [ project.current ]
  406. : stage
  407. : stage-proper headers
  408. ;
  409. p = [ project.current ] ;
  410. $(p).mark-target-as-explicit install stage ;
  411. # This target is built by default, and will forward to 'stage' after
  412. # producing some explanations.
  413. targets.create-metatarget top-level-target : [ project.current ]
  414. : forward
  415. : explain stage
  416. ;
  417. }
  418. ################################################################################
  419. #
  420. # 4. Add hook to report configuration before the build, and confirmation with
  421. # setup instructions after the build.
  422. #
  423. ################################################################################
  424. message explain : "\nBuilding the Boost C++ Libraries.\n\n" ;
  425. local p = [ project.current ] ;
  426. $(p).mark-target-as-explicit explain ;
  427. rule pre-build ( )
  428. {
  429. local tl = [ modules.peek : top-level-targets ] ;
  430. if stage in $(tl) || install in $(tl)
  431. {
  432. # FIXME: Remove 'if' when Boost regression tests start using trunk bjam.
  433. if PAD in [ RULENAMES ]
  434. {
  435. configure.print-component-configuration ;
  436. }
  437. }
  438. }
  439. IMPORT $(__name__) : pre-build : : $(__name__).pre-build ;
  440. build-system.set-pre-build-hook $(__name__).pre-build ;
  441. rule post-build ( ok ? )
  442. {
  443. if forward in [ modules.peek : top-level-targets ]
  444. {
  445. if $(ok)
  446. {
  447. local include-path = [ path.native $(BOOST_ROOT) ] ;
  448. local stage-abs = [ path.native $(stage-locate)/lib ] ;
  449. ECHO "
  450. The Boost C++ Libraries were successfully built!
  451. The following directory should be added to compiler include paths:
  452. $(include-path)
  453. The following directory should be added to linker library paths:
  454. $(stage-abs)
  455. " ;
  456. }
  457. }
  458. }
  459. IMPORT $(__name__) : post-build : : $(__name__).post-build ;
  460. build-system.set-post-build-hook $(__name__).post-build ;
  461. ################################################################################
  462. #
  463. # 5. Top-level setup.
  464. #
  465. ################################################################################
  466. # Decides which libraries are to be installed by looking at --with-<library>
  467. # --without-<library> arguments. Returns the list of directories under "libs"
  468. # which must be built and installed.
  469. #
  470. rule libraries-to-install ( existing-libs * )
  471. {
  472. local argv = [ modules.peek : ARGV ] ;
  473. local with-parameter = [ MATCH ^--with-(.*) : $(argv) ] ;
  474. local without-parameter = [ MATCH ^--without-(.*) : $(argv) ] ;
  475. if ! $(with-parameter) && ! $(without-parameter)
  476. {
  477. # Nothing is specified on command line. See if maybe project-config.jam
  478. # has some choices.
  479. local libs = [ modules.peek project-config : libraries ] ;
  480. with-parameter = [ MATCH ^--with-(.*) : $(libs) ] ;
  481. without-parameter = [ MATCH ^--without-(.*) : $(libs) ] ;
  482. }
  483. # Do some checks.
  484. if $(with-parameter) && $(without-parameter)
  485. {
  486. EXIT error\: both --with-<library> and --without-<library> specified ;
  487. }
  488. local wrong = [ set.difference $(with-parameter) : $(existing-libs) ] ;
  489. if $(wrong)
  490. {
  491. EXIT error\: wrong library name '$(wrong[1])' in the --with-<library>
  492. option. ;
  493. }
  494. local wrong = [ set.difference $(without-parameter) : $(existing-libs) ] ;
  495. if $(wrong)
  496. {
  497. EXIT error\: wrong library name '$(wrong[1])' in the --without-<library>
  498. option. ;
  499. }
  500. if $(with-parameter)
  501. {
  502. return [ set.intersection $(existing-libs) : $(with-parameter) ] ;
  503. }
  504. else
  505. {
  506. return [ set.difference $(existing-libs) : $(without-parameter) ] ;
  507. }
  508. }
  509. rule declare-targets ( all-libraries * )
  510. {
  511. configure.register-components $(all-libraries) ;
  512. # Select the libraries to install.
  513. libraries = [ libraries-to-install $(all-libraries) ] ;
  514. configure.components-building $(libraries) ;
  515. if [ option.get "show-libraries" : : true ]
  516. {
  517. ECHO The following libraries require building\: ;
  518. for local l in $(libraries)
  519. {
  520. if $(l) = function_types
  521. {
  522. continue ;
  523. }
  524. if [ path.glob $(BOOST_ROOT)/libs/$(l)/build : Jamfile Jamfile.v2 ]
  525. {
  526. echo " - $(l)" ;
  527. }
  528. }
  529. EXIT ;
  530. }
  531. declare_top_level_targets $(libraries) ;
  532. }
  533. # Returns the properties identifying the toolset. We'll use them
  534. # below to configure checks. These are essentially same as in
  535. # configure.builds, except we don't use address-model and
  536. # architecture - as we're trying to detect them here.
  537. #
  538. rule toolset-properties ( properties * )
  539. {
  540. local toolset = [ property.select <toolset> : $(properties) ] ;
  541. local toolset-version-property = "<toolset-$(toolset:G=):version>" ;
  542. return [ property.select <target-os> <toolset> $(toolset-version-property) : $(properties) ] ;
  543. }
  544. .deducible-architectures = arm loongarch mips power riscv s390x sparc x86 combined ;
  545. feature.feature x-deduced-platform
  546. : $(.deducible-architectures)_32 $(.deducible-architectures)_64
  547. : composite implicit optional propagated ;
  548. for a in $(.deducible-architectures)
  549. {
  550. feature.compose <x-deduced-platform>$(a)_32 : <architecture>$(a) <address-model>32 ;
  551. feature.compose <x-deduced-platform>$(a)_64 : <architecture>$(a) <address-model>64 ;
  552. }
  553. rule deduce-architecture ( properties * )
  554. {
  555. local deduced-pl = [ property.select <x-deduced-platform> : $(properties) ] ;
  556. if $(deduced-pl)
  557. {
  558. return $(deduced-pl) ;
  559. }
  560. local filtered = [ toolset-properties $(properties) ] ;
  561. local names = 32 64 ;
  562. local idx = [ configure.find-builds "default address-model" : $(filtered)
  563. : /boost/architecture//32 "32-bit"
  564. : /boost/architecture//64 "64-bit" ] ;
  565. local deduced-am = $(names[$(idx)]) ;
  566. if ! $(deduced-am)
  567. {
  568. return ;
  569. }
  570. names = $(.deducible-architectures) ;
  571. idx = [ configure.find-builds "default architecture" : $(filtered)
  572. : /boost/architecture//arm
  573. : /boost/architecture//loongarch
  574. : /boost/architecture//mips
  575. : /boost/architecture//power
  576. : /boost/architecture//riscv
  577. : /boost/architecture//s390x
  578. : /boost/architecture//sparc
  579. : /boost/architecture//x86
  580. : /boost/architecture//combined ] ;
  581. local deduced-arch = $(names[$(idx)]) ;
  582. if ! $(deduced-arch)
  583. {
  584. return ;
  585. }
  586. local requested-am = [ property.select <address-model> : $(properties) ] ;
  587. requested-am ?= <address-model>$(deduced-am) ;
  588. local requested-arch = [ property.select <architecture> : $(properties) ] ;
  589. requested-arch ?= <architecture>$(deduced-arch) ;
  590. deduced-pl = $(requested-arch:G=<x-deduced-platform>)_$(requested-am:G=) ;
  591. if ! $(deduced-pl:G=) in [ feature.values <x-deduced-platform> ]
  592. {
  593. deduced-pl = ;
  594. }
  595. return $(deduced-pl) ;
  596. }
  597. rule deduce-address-model ( properties * )
  598. {
  599. # this rule is a noop and exists for legacy reasons
  600. }
  601. rule platform ( )
  602. {
  603. return <conditional>@boostcpp.deduce-architecture
  604. <conditional>@boostcpp.deduce-address-model ;
  605. }
粤ICP备19079148号