• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[/
2Copyright 2004 Vladimir Prus
3Copyright 2017 Rene Rivera
4Distributed under the Boost Software License, Version 1.0.
5(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6/]
7
8[section Build Variants]
9
10This example shows how user can create his own build variants. Two variants are
11defined: "crazy", which is just a random combination of properties, and
12"super-release", which is inherited from "release", and differs by a single
13define.
14
15Files:
16
17* [@../../example/variant/a.cpp a.cpp]
18* [@../../example/variant/jamroot.jam jamroot.jam]
19* [@../../example/variant/jamfile.jam jamfile.jam]
20* [@../../example/variant/libs/jamfile.jam libs/jamfile.jam]
21* [@../../example/variant/libs/l.cpp libs/l.cpp]
22
23[import jamroot.jam]
24[import jamfile.jam]
25[import libs/jamfile.jam]
26
27In this project the `jamroot.jam` specifies the custom build variants and the
28targets are specified in the two `jamfile.jam` files.
29
30[jamroot]
31
32The top-level `jamfile.jam`:
33
34[jamfile]
35
36And the library `jamfile.jam` that the top-level `jamfile.jam` refers to:
37
38[libs_jamfile]
39
40Building the example yields:
41
42[teletype]
43```
44> cd /example/variant
45> b2
46...found 20 targets...
47...updating 16 targets...
48common.mkdir bin
49common.mkdir bin/clang-darwin-4.2.1
50common.mkdir bin/clang-darwin-4.2.1/crazy
51clang-darwin.compile.c++ bin/clang-darwin-4.2.1/crazy/a.o
52common.mkdir libs/bin
53common.mkdir libs/bin/clang-darwin-4.2.1
54common.mkdir libs/bin/clang-darwin-4.2.1/crazy
55clang-darwin.compile.c++ libs/bin/clang-darwin-4.2.1/crazy/l.o
56clang-darwin.link.dll libs/bin/clang-darwin-4.2.1/crazy/libl.dylib
57clang-darwin.link bin/clang-darwin-4.2.1/crazy/a
58common.mkdir bin/clang-darwin-4.2.1/super_release
59clang-darwin.compile.c++ bin/clang-darwin-4.2.1/super_release/a.o
60common.mkdir libs/bin/clang-darwin-4.2.1/super_release
61clang-darwin.compile.c++ libs/bin/clang-darwin-4.2.1/super_release/l.o
62clang-darwin.link.dll libs/bin/clang-darwin-4.2.1/super_release/libl.dylib
63clang-darwin.link bin/clang-darwin-4.2.1/super_release/a
64...updated 16 targets...
65```
66
67As specified in the top-level `jamfile.jam` both custom variants where built
68by default. Once can override that by specifying the variant one wants to
69build directly on the command line with a `variant=super_release`. Or just
70with a `super_release` as variants can be referred to by their name only.
71For example using that argument yields:
72
73```
74> cd /example/variant
75> b2 super_release
76...found 14 targets...
77...updating 10 targets...
78common.mkdir bin
79common.mkdir bin/clang-darwin-4.2.1
80common.mkdir bin/clang-darwin-4.2.1/super_release
81clang-darwin.compile.c++ bin/clang-darwin-4.2.1/super_release/a.o
82common.mkdir libs/bin
83common.mkdir libs/bin/clang-darwin-4.2.1
84common.mkdir libs/bin/clang-darwin-4.2.1/super_release
85clang-darwin.compile.c++ libs/bin/clang-darwin-4.2.1/super_release/l.o
86clang-darwin.link.dll libs/bin/clang-darwin-4.2.1/super_release/libl.dylib
87clang-darwin.link bin/clang-darwin-4.2.1/super_release/a
88...updated 10 targets...
89```
90
91[note The actual paths in the `bin` sub-directory will depend on your
92toolset.]
93
94[endsect]
95