This section will guide you though the most basic features of Boost.Build V2. We will start with the “Hello, world” example, learn how to use libraries, and finish with testing and installing features.
The simplest project that Boost.Build can construct is stored in
exe hello : hello.cpp ;
Even with this simple setup, you can do some interesting things. First of
all, just invoking bjam will build the bjam release
Note that debug and release variants are created in different directories,
so you can switch between variants or even build multiple variants at
once, without any unnecessary recompilation. Let us extend the example by
adding another line to our project's exe hello2 : hello.cpp ; Now let us build both the debug and release variants of our project again: bjam debug release
Note that two variants of bjam --clean debug release
It is also possible to build or clean specific targets. The following two
commands, respectively, build or clean only the debug version of
bjam hello2 bjam --clean hello2
To portably represent aspects of target configuration such as
debug and release variants, or single- and multi-threaded
builds, Boost.Build uses features with
associated values. For
example, the
There are many built-in features that can be combined to
produce arbitrary build configurations. The following command
builds the project's bjam release inlining=off debug-symbols=on
Properties on the command-line are specified with the syntax:
The bjam variant=release inlining=off debug-symbols=on
A complete description of features can be found in the section called “Features and properties”.
The set of properties specified on the command line constitute
a build request—a description of
the desired properties for building the requested targets (or,
if no targets were explicitly requested, the project in the
current directory). The actual
properties used for building targets are typically a
combination of the build request and properties derived from
the project's exe hello : hello.cpp : <include>boost <threading>multi ;
When
If we want the same requirements for our other target, project : requirements <include>/home/ghost/Work/boost <threading>multi ; exe hello : hello.cpp ; exe hello2 : hello.cpp ;
The effect would be as if we specified the same requirement for both
So far we have only considered examples with one project —a. with
one user-written Boost.Jam file, top/ | +-- Jamroot | +-- app/ | | | +-- Jamfile | `-- app.cpp | `-- util/ | +-- foo/ . | . +-- Jamfile . `-- bar.cpp
the project root is
Projects inherit all attributes (such as requirements)
from their parents. Inherited requirements are combined with
any requirements specified by the subproject.
For example, if <include>/home/ghost/local in its requirements, then all of its subprojects will have it in their requirements, too. Of course, any project can add include paths to those specified by its parents. [12] More details can be found in the section called “Projects”.
Invoking bjam without explicitly specifying
any targets on the command line builds the project rooted in the
current directory. Building a project does not automatically
cause its subprojects to be built unless the parent project's
Jamfile explicitly requests it. In our example,
build-project app ;
which would cause the project in
When a building a target To get a feeling of target dependencies, let's continue the
above example and see how lib bar : bar.cpp ;
then to use this library in exe app : app.cpp ../util/foo//bar ;
While
Suppose we build bjam app optimization=full define=USE_ASM
Which properties will be used to build
Let's improve this project further. The library probably has some headers
that must be used when compiling project : usage-requirements <include>. ; lib foo : foo.cpp ;
Usage requirements are applied not to the target being declared but to its
dependants. In this case,
Another improvement is using symbolic identifiers to refer to the library,
as opposed to use-project /library-example/foo : util/foo ;
Second, we modify exe app : app.cpp /library-example/foo//bar ;
The
Libraries can be either static, which means they are included in executable files that use them, or shared (a.k.a. dynamic), which are only referred to from executables, and must be available at run time. Boost.Build can create and use both kinds.
The kind of library produced from a bjam link=static or in the library's requirements: lib l : l.cpp : <link>static ;
We can also use the exe important : main.cpp helpers/<link>static ;
No matter what arguments are specified on the bjam
command line, Specifying properties in target references is especially useful if you use a library defined in some other project (one you can't change) but you still want static (or dynamic) linking to that library in all cases. If that library is used by many targets, you could use target references everywhere: exe e1 : e1.cpp /other_project//bar/<link>static ; exe e10 : e10.cpp /other_project//bar/<link>static ;
but that's far from being convenient. A better approach is to introduce a
level of indirection. Create a local alias target that refers
to the static (or dynamic) version of alias foo : /other_project//bar/<link>static ; exe e1 : e1.cpp foo ; exe e10 : e10.cpp foo ;
The
Sometimes, particular relationships need to be maintained among a target's
build properties. For example, you might want to set specific
lib network : network.cpp
: <link>shared:<define>NEWORK_LIB_SHARED
<variant>release:<define>EXTRA_FAST
;
In the example above, whenever Sometimes the ways a target is built are so different that describing them using conditional requirements would be hard. For example, imagine that a library actually uses different source files depending on the toolset used to build it. We can express this situation using target alternatives: lib demangler : dummy_demangler.cpp ; # alternative 1 lib demangler : demangler_gcc.cpp : <toolset>gcc ; # alternative 2 lib demangler : demangler_msvc.cpp : <toolset>msvc ; # alternative 3
When building
To link to libraries whose build instructions aren't given in a Jamfile,
you need to create # util/lib2/Jamfile lib lib2 : : <file>lib2_release.a <variant>release ; lib lib2 : : <file>lib2_debug.a <variant>debug ;
This example defines two alternatives for Once a prebuilt target has been declared, it can be used just like any other target: exe app : app.cpp ../util/lib2//lib2 ;
As with any target, the alternative selected depends on the properties
propagated from System libraries—those that are automatically found by the toolset by searching through some set of predetermined paths—should be declared almost like regular ones: lib pythonlib : : <name>python22 ;
We again don't specify any sources, but give a We can also specify where the toolset should look for the library: lib pythonlib : : <name>python22 <search>/opt/lib ; And, of course, target alternatives can be used in the usual way: lib pythonlib : : <name>python22 <variant>release ; lib pythonlib : : <name>python22_d <variant>debug ;
A more advanced use of prebuilt targets is described in the section called “Targets in site-config.jam”. [12] Many features will be overridden, rather than added-to, in subprojects. See the section called “Feature Attributes” for more information |