boostcpp.jam 19 KB

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