boostcpp.jam 20 KB

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