boostcpp.jam 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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) 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. alias install-proper : libs/$(libraries)/build//install ;
  235. $(p).mark-target-as-explicit install-proper ;
  236. alias stage-proper : libs/$(libraries)/build//stage ;
  237. $(p).mark-target-as-explicit stage-proper ;
  238. }
  239. ################################################################################
  240. #
  241. # 3. Declare top-level targets 'stage' and 'install'. These examine the
  242. # --build-type option and, in case it is 'complete', build the 'install-proper'
  243. # and 'stage-proper' targets with a number of property sets.
  244. #
  245. ################################################################################
  246. rule emit-shared-static-warning ( )
  247. {
  248. if ! $(.shared-static-warning-emitted)
  249. {
  250. ECHO "" ;
  251. ECHO "warning: The configuration link=shared, runtime-link=static is disabled" ;
  252. ECHO "warning: by default as being too dangerous to use, and will not be built." ;
  253. ECHO "warning: To enable it, use --allow-shared-static." ;
  254. ECHO "" ;
  255. .shared-static-warning-emitted = 1 ;
  256. }
  257. }
  258. class top-level-target : alias-target-class
  259. {
  260. import modules ;
  261. import boostcpp ;
  262. rule __init__ ( name : project : sources * : requirements *
  263. : default-build * : usage-requirements * )
  264. {
  265. alias-target-class.__init__ $(name) : $(project) : $(sources) :
  266. $(requirements) : $(default-build) : $(usage-requirements) ;
  267. self.build-type = [ modules.peek boostcpp : build-type ] ;
  268. # On Linux, we build the release variant by default, since few users
  269. # will ever want to debug C++ Boost libraries, and there is no ABI
  270. # incompatibility between debug and release variants. We build shared
  271. # and static libraries since that is what most packages seem to provide
  272. # (.so in libfoo and .a in libfoo-dev).
  273. self.minimal-properties = [ property-set.create <variant>release
  274. <threading>multi <link>shared <link>static <runtime-link>shared ] ;
  275. # On Windows, new IDE projects use:
  276. #
  277. # runtime-link=dynamic, threading=multi, variant=(debug|release)
  278. #
  279. # and in addition, C++ Boost's autolink defaults to static linking.
  280. self.minimal-properties-win = [ property-set.create <variant>debug
  281. <variant>release <threading>multi <link>static <runtime-link>shared
  282. <address-model>32 <address-model>64 ] ;
  283. self.complete-properties = [ property-set.create
  284. <variant>debug <variant>release
  285. <threading>multi
  286. <link>shared <link>static
  287. <runtime-link>shared <runtime-link>static ] ;
  288. self.complete-properties-win = [ property-set.create
  289. <variant>debug <variant>release
  290. <threading>multi
  291. <link>shared <link>static
  292. <runtime-link>shared <runtime-link>static
  293. <address-model>32 <address-model>64 ] ;
  294. }
  295. rule generate ( property-set )
  296. {
  297. modules.poke : top-level-targets : [ modules.peek : top-level-targets ]
  298. $(self.name) ;
  299. local os = [ $(property-set).get <target-os> ] ;
  300. # Because we completely override the parent's 'generate' we need to
  301. # check for default feature values ourselves.
  302. if ! $(os)
  303. {
  304. os = [ feature.defaults <target-os> ] ;
  305. os = $(os:G=) ;
  306. }
  307. local build-type-set ;
  308. if $(self.build-type) = minimal
  309. {
  310. if $(os) = windows
  311. {
  312. build-type-set = $(self.minimal-properties-win) ;
  313. }
  314. else
  315. {
  316. build-type-set = $(self.minimal-properties) ;
  317. }
  318. }
  319. else if $(self.build-type) = complete
  320. {
  321. if $(os) = windows
  322. {
  323. build-type-set = $(self.complete-properties-win) ;
  324. }
  325. else
  326. {
  327. build-type-set = $(self.complete-properties) ;
  328. }
  329. }
  330. else
  331. {
  332. import errors ;
  333. errors.error "Unknown build type" ;
  334. }
  335. if $(build-type-set)
  336. {
  337. local expanded = [ targets.apply-default-build $(property-set)
  338. : $(build-type-set) ] ;
  339. # Filter inappropriate combinations.
  340. local filtered ;
  341. local skipped ;
  342. local argv = [ modules.peek : ARGV ] ;
  343. for local p in $(expanded)
  344. {
  345. # See comment in handle-static-runtime regarding this logic.
  346. if [ $(p).get <link> ] = shared
  347. && [ $(p).get <runtime-link> ] = static
  348. && [ $(p).get <toolset> ] != cw
  349. && ! --allow-shared-static in $(argv)
  350. {
  351. # Skip this.
  352. skipped += $(p) ;
  353. }
  354. else
  355. {
  356. filtered += $(p) ;
  357. }
  358. }
  359. if $(expanded) = $(skipped)
  360. {
  361. boostcpp.emit-shared-static-warning ;
  362. }
  363. return [ build-multiple $(filtered) ] ;
  364. }
  365. }
  366. rule build-multiple ( property-sets * )
  367. {
  368. local usage-requirements = [ property-set.empty ] ;
  369. local result ;
  370. for local p in $(property-sets)
  371. {
  372. local r = [ alias-target-class.generate $(p) ] ;
  373. if $(r)
  374. {
  375. usage-requirements = [ $(usage-requirements).add $(r[1]) ] ;
  376. result += $(r[2-]) ;
  377. }
  378. }
  379. return $(usage-requirements) [ sequence.unique $(result) ] ;
  380. }
  381. }
  382. rule declare_top_level_targets ( libraries * )
  383. {
  384. declare_install_and_stage_proper_targets $(libraries) ;
  385. targets.create-metatarget top-level-target : [ project.current ]
  386. : install
  387. : install-proper
  388. ;
  389. targets.create-metatarget top-level-target : [ project.current ]
  390. : stage
  391. : stage-proper headers
  392. ;
  393. p = [ project.current ] ;
  394. $(p).mark-target-as-explicit install stage ;
  395. # This target is built by default, and will forward to 'stage' after
  396. # producing some explanations.
  397. targets.create-metatarget top-level-target : [ project.current ]
  398. : forward
  399. : explain stage
  400. ;
  401. }
  402. ################################################################################
  403. #
  404. # 4. Add hook to report configuration before the build, and confirmation with
  405. # setup instructions after the build.
  406. #
  407. ################################################################################
  408. message explain : "\nBuilding the Boost C++ Libraries.\n\n" ;
  409. local p = [ project.current ] ;
  410. $(p).mark-target-as-explicit explain ;
  411. rule pre-build ( )
  412. {
  413. local tl = [ modules.peek : top-level-targets ] ;
  414. if stage in $(tl) || install in $(tl)
  415. {
  416. # FIXME: Remove 'if' when Boost regression tests start using trunk bjam.
  417. if PAD in [ RULENAMES ]
  418. {
  419. configure.print-component-configuration ;
  420. }
  421. }
  422. }
  423. IMPORT $(__name__) : pre-build : : $(__name__).pre-build ;
  424. build-system.set-pre-build-hook $(__name__).pre-build ;
  425. rule post-build ( ok ? )
  426. {
  427. if forward in [ modules.peek : top-level-targets ]
  428. {
  429. if $(ok)
  430. {
  431. local include-path = [ path.native $(BOOST_ROOT) ] ;
  432. local stage-abs = [ path.native $(stage-locate)/lib ] ;
  433. ECHO "
  434. The Boost C++ Libraries were successfully built!
  435. The following directory should be added to compiler include paths:
  436. $(include-path)
  437. The following directory should be added to linker library paths:
  438. $(stage-abs)
  439. " ;
  440. }
  441. }
  442. }
  443. IMPORT $(__name__) : post-build : : $(__name__).post-build ;
  444. build-system.set-post-build-hook $(__name__).post-build ;
  445. ################################################################################
  446. #
  447. # 5. Top-level setup.
  448. #
  449. ################################################################################
  450. # Decides which libraries are to be installed by looking at --with-<library>
  451. # --without-<library> arguments. Returns the list of directories under "libs"
  452. # which must be built and installed.
  453. #
  454. rule libraries-to-install ( existing-libs * )
  455. {
  456. local argv = [ modules.peek : ARGV ] ;
  457. local with-parameter = [ MATCH ^--with-(.*) : $(argv) ] ;
  458. local without-parameter = [ MATCH ^--without-(.*) : $(argv) ] ;
  459. if ! $(with-parameter) && ! $(without-parameter)
  460. {
  461. # Nothing is specified on command line. See if maybe project-config.jam
  462. # has some choices.
  463. local libs = [ modules.peek project-config : libraries ] ;
  464. with-parameter = [ MATCH ^--with-(.*) : $(libs) ] ;
  465. without-parameter = [ MATCH ^--without-(.*) : $(libs) ] ;
  466. }
  467. # Do some checks.
  468. if $(with-parameter) && $(without-parameter)
  469. {
  470. EXIT error\: both --with-<library> and --without-<library> specified ;
  471. }
  472. local wrong = [ set.difference $(with-parameter) : $(existing-libs) ] ;
  473. if $(wrong)
  474. {
  475. EXIT error\: wrong library name '$(wrong[1])' in the --with-<library>
  476. option. ;
  477. }
  478. local wrong = [ set.difference $(without-parameter) : $(existing-libs) ] ;
  479. if $(wrong)
  480. {
  481. EXIT error\: wrong library name '$(wrong[1])' in the --without-<library>
  482. option. ;
  483. }
  484. if $(with-parameter)
  485. {
  486. return [ set.intersection $(existing-libs) : $(with-parameter) ] ;
  487. }
  488. else
  489. {
  490. return [ set.difference $(existing-libs) : $(without-parameter) ] ;
  491. }
  492. }
  493. rule declare-targets ( all-libraries * )
  494. {
  495. configure.register-components $(all-libraries) ;
  496. # Select the libraries to install.
  497. libraries = [ libraries-to-install $(all-libraries) ] ;
  498. configure.components-building $(libraries) ;
  499. if [ option.get "show-libraries" : : true ]
  500. {
  501. ECHO The following libraries require building\: ;
  502. for local l in $(libraries)
  503. {
  504. ECHO " - $(l)" ;
  505. }
  506. EXIT ;
  507. }
  508. declare_top_level_targets $(libraries) ;
  509. }
  510. # Returns the properties identifying the toolset. We'll use them
  511. # below to configure checks. These are essentially same as in
  512. # configure.builds, except we don't use address-model and
  513. # architecture - as we're trying to detect them here.
  514. #
  515. rule toolset-properties ( properties * )
  516. {
  517. local toolset = [ property.select <toolset> : $(properties) ] ;
  518. local toolset-version-property = "<toolset-$(toolset:G=):version>" ;
  519. return [ property.select <target-os> <toolset> $(toolset-version-property) : $(properties) ] ;
  520. }
  521. feature.feature deduced-address-model : 32 64 : propagated optional composite hidden ;
  522. feature.compose <deduced-address-model>32 : <address-model>32 ;
  523. feature.compose <deduced-address-model>64 : <address-model>64 ;
  524. rule deduce-address-model ( properties * )
  525. {
  526. local result ;
  527. local filtered = [ toolset-properties $(properties) ] ;
  528. local names = 32 64 ;
  529. local idx = [ configure.find-builds "default address-model" : $(filtered)
  530. : /boost/architecture//32 "32-bit"
  531. : /boost/architecture//64 "64-bit" ] ;
  532. result = $(names[$(idx)]) ;
  533. local am = [ property.select <address-model> : $(properties) ] ;
  534. if ! $(am)
  535. {
  536. return <deduced-address-model>$(result) ;
  537. }
  538. if $(am:G=) = $(result)
  539. {
  540. return <deduced-address-model>$(result) $(am) ;
  541. }
  542. return ;
  543. }
  544. rule address-model ( )
  545. {
  546. return <conditional>@boostcpp.deduce-address-model ;
  547. }
  548. local deducable-architectures = arm loongarch mips power riscv s390x sparc x86 combined ;
  549. feature.feature deduced-architecture : $(deducable-architectures) : propagated optional composite hidden ;
  550. for a in $(deducable-architectures)
  551. {
  552. feature.compose <deduced-architecture>$(a) : <architecture>$(a) ;
  553. }
  554. rule deduce-architecture ( properties * )
  555. {
  556. local result ;
  557. local filtered = [ toolset-properties $(properties) ] ;
  558. local names = arm loongarch mips power riscv s390x sparc x86 combined ;
  559. local idx = [ configure.find-builds "default architecture" : $(filtered)
  560. : /boost/architecture//arm
  561. : /boost/architecture//loongarch
  562. : /boost/architecture//mips
  563. : /boost/architecture//power
  564. : /boost/architecture//riscv
  565. : /boost/architecture//s390x
  566. : /boost/architecture//sparc
  567. : /boost/architecture//x86
  568. : /boost/architecture//combined ] ;
  569. result = $(names[$(idx)]) ;
  570. local arch = [ property.select <architecture> : $(properties) ] ;
  571. if ! $(arch)
  572. {
  573. return <deduced-architecture>$(result) ;
  574. }
  575. if $(arch:G=) = $(result)
  576. {
  577. return <deduced-architecture>$(result) $(arch) ;
  578. }
  579. return ;
  580. }
  581. rule architecture ( )
  582. {
  583. return <conditional>@boostcpp.deduce-architecture ;
  584. }
粤ICP备19079148号