User documentationThis section will provide the information necessary to create your own
projects using Boost.Build. The information provided here is relatively
high-level, and as
well as the on-line help system must be used to obtain
low-level documentation (see ).Boost.Build actually consists of two parts - Boost.Jam, a
build engine with its own interpreted language, and Boost.Build itself,
implemented in Boost.Jam's language. The chain of events when
you type bjam on the command line is:
Boost.Jam tries to find Boost.Build and loads the top-level
module. The exact process is described in The top-level module loads user-defined configuration
files, user-config.jam and site-config.jam, which define
available toolsets.The Jamfile in the current directory is read. That in turn
might cause reading of further Jamfiles. As a result, a tree of
projects is created, with targets inside projects.Finally, using the build request specified on the command line,
Boost.Build decides which targets should be built, and how. That
information is passed back to Boost.Jam, which takes care of
actually running commands.So, to be able to successfully use Boost.Build, you need to know only
four things:
How to configure Boost.Build
How to write Jamfiles
How the build process worksSome Basics about the Boost.Jam language. See also the
Boost.Jam
documentation.
Boost.Jam languageThis section will describe the basics of the Boost.Jam
language—just enough for writing Jamfiles. For more information,
please see the Boost.Jam
documentation.Boost.Jam has an interpreted, procedural language.
On the lowest level, a Boost.Jam program consists of variables and
rulerules (the Jam term for function). They are grouped
in modules—there's one global module and a number of named
modules. Besides that, a Boost.Jam program contains classes and class
instances.
Syntantically, a Boost.Jam program consists of two kind of
elements—keywords (which have a special meaning to Boost.Jam) and
literals.
Consider this code:
a = b ;
which assigns the value b to the variable
a. Here, = and
; are keywords, while a and
b are literals.
All syntax elements, even keywords, must be separated by
spaces. For example, omitting the space character before
; will lead to a syntax error.
If you want to use a literal value that is the same as some keyword, the
value can be quoted:
a = "=" ;All variables in Boost.Jam have the same type—list of
strings. To define a variable one assigns a value to it, like in the
previous example. An undefined variable is the same as a variable with
an empty value. Variables can be accessed with the
$(variable) syntax. For example:
a = $(b) $(c) ;
Rules are defined by specifying the rule name, the parameter names,
and the allowed size of the list value for each parameter.
rule example
(
parameter1 :
parameter2 ? :
parameter3 + :
parameter4 *
)
{
// body
}
When this rule is called, the list passed as the first argument must
have exactly one value. The list passed as the second argument can
either have one value of be empty. The two remaining arguments can
be arbitrary long, but the third argument may not be empty.
The overview of Boost.Jam language statements is given below:
helper 1 : 2 : 3 ;
x = [ helper 1 : 2 : 3 ] ;
This code calls the named rule with the specified arguments. When the
result of the call must be used inside some expression, you need to add
brackets around the call, like shown on the second line.
if cond { statements } [ else { statements } ]
This is a regular if-statement. The condition is composed of:
Literals (true if at least one string is not empty)Comparisons: a
operator b where
operator is one of =,
!=, <, >,
<=, >=. The comparison is done
pairwise between each string in the left and the right arguments.
Logical operations: ! a, a &&
b, a || bGrouping: ( cond )
for var in list { statements }
Executes statements for each element in list, setting the variable
var to the element value.
while cond { statements }
Repeatedly execute statements while cond remains true upon entry.
return values ;
This statement should be used only inside a
rule and assigns values to the return value of the
rule.
The return statement does not exit the rule. For example:
rule test ( )
{
if 1 = 1 {
return "reasonable" ;
}
return "strange" ;
} will return strange, not
reasonable.
import module ;
import module : rule ;
The first form imports the specified bjam module. All rules from
that module are made available using the qualified name:
module.rule.
The second form imports the specified rules only, and they can be called
using unqualified names.
Sometimes, you'd need to specify the actual command lines to be used
when creating targets. In jam language, you use named actions to do this.
For example:
actions create-file-from-another
{
create-file-from-another $(<) $(>)
}
This specifies a named action called
create-file-from-another. The text inside braces is the
command to invoke. The $(<) variable will be expanded to list of
generated files, and the $(>) variable will be expanded
to the list of source files.
To flexibly adjust command line, you can define a rule with the
same name as the action, and taking three parameters -- targets, sources
and properties. For example:
rule create-file-from-another ( targets * : sources * : properties * )
{
if <variant>debug in $(properties)
{
OPTIONS on $(targets) = --debug ;
}
}
actions create-file-from-another
{
create-file-from-another $(OPTIONS) $(<) $(>)
}
In this example, the rule checks if certain build property is specified.
If so, it sets variable OPIONS that's used inside
action. Note that the variable is set "on targets" -- the value will
be only visible inside action, not globally. Were it set globally,
using variable named OPTIONS in two unrelated
actions would be impossible.
More details can be found in Jam reference, ConfigurationThe Boost.Build configuration is specified in the file
user-config.jam. You can edit the one in the top-level
directory of Boost.Build installation or create a copy in your home directory
and edit that. (See for the
exact search paths.) The primary function of that file is to declare which
compilers and other tools are available. The simplest syntax to configure
a tool is:
using tool-name ;
The using rule is given a name of tool, and will make that tool
available to Boost.Build. For example, using gcc ; will make the gcc compiler
available.
Since nothing but a tool name is specified, Boost.Build will
pick some default settings. For example, it will use the
gcc executable found in the
PATH, or look in some known installation
locations. In most cases, this strategy works automatically. In
case you have several versions of a compiler, it's installed in
some unusual location, or you need to tweak its configuration,
you'll need to pass additional parameters to the
using rule. The parameters to
using can be different for each
tool. You can obtain specific documentation for any tool's
configuration parameters by invoking
bjam --help tool-name.init
That said, for all the compiler toolsets Boost.Build supports
out-of-the-box, the list of parameters to
using is the same: toolset-name, version, invocation-command, and options.
The version
parameter identifies the toolset version, in case you have
several installed. It can have any form you like, but
it's recommended that you use a numeric identifier like
7.1.
The invocation-command
parameter is the command that must be executed to run the
compiler. This parameter can usually be omitted if the compiler
executable
has its “usual
name” and is in the PATH,
orwas installed in a standard
“installation directory”,
orcan be found through a global mechanism like the
Windows registry.
For example:
using msvc : 7.1 ;
using gcc ;
If the compiler can be found in the PATH but only by a
nonstandard name, you can just supply that name:
using gcc : : g++-3.2 ;
Otherwise, it might be necessary to supply the complete path to the
compiler executable:
using msvc : : "Z:/Programs/Microsoft Visual Studio/vc98/bin/cl" ;
Some Boost.Build toolsets will use that path to take additional
actions required before invoking the compiler, such as calling
vendor-supplied scripts to set up its required environment variables.
When compiler executables for C and C++ are different, path to the C++
compiler executable must be specified. The “invocation command”
can be any command allowed by the operating system. For example:
using msvc : : echo Compiling && foo/bar/baz/cl ;
will work.
To configure several versions of a toolset, simply invoke
the using rule multiple times:
using gcc : 3.3 ;
using gcc : 3.4 : g++-3.4 ;
using gcc : 3.2 : g++-3.2 ;
Note that in the first call to
using, the compiler found in the
PATH will be used, and there's no need to
explicitly specify the command.
As shown above, both the version and invocation-command parameters are
optional, but there's an important restriction: if you configure
the same toolset more than once, you must pass the version
parameter every time. For example, the following is not allowed:
using gcc ;
using gcc : 3.4 : g++-3.4 ;
because the first using call does
not specify a version.
The options
parameter is used to fine-tune the configuration. All of
Boost.Build's standard compiler toolsets accept properties of the
four builtin features cflags,
cxxflags, compileflags and
linkflags as options specifying flags that will be
always passed to the corresponding tools. Values of the
cflags feature are passed directly to the C
compiler, values of the cxxflags feature are
passed directly to the C++ compiler, and values of the
compileflags feature are passed to both. For
example, to configure a gcc toolset so that it
always generates 64-bit code you could write:
using gcc : 3.4 : : <compileflags>-m64 <linkflags>-m64 ;
InvocationThis section describes how invoke Boost.Build from the command lineTo build all targets defined in Jamfile in the current directory with default properties, run:
bjam
To build specific targets, specify them on the command line:
bjam lib1 subproject//lib2
To request a certain value for some property, add property=value to the command line:
bjam toolset=gcc variant=debug optimization=space
For often used features, like toolset and variant you can
omit the feature name, so the above can be written as:
bjam optimization=space
Boost.Build recognizes the following command line options.Cleans all targets in the current directory and
in any subprojects. Note that unlike the clean
target in make, you can use --clean
together with target names to clean specific targets.Cleans all targets,
no matter where they are defined. In particular, it will clean targets
in parent Jamfiles, and targets defined under other project roots.
Changes build directories for all project roots being built. When
this option is specified, all Jamroot files should declare project name.
The build directory for the project root will be computed by concatanating
the value of the option, the project name
specified in Jamroot, and the build dir specified in Jamroot
(or bin, if none is specified).
The option is primarily useful when building from read-only
media, when you can't modify Jamroot.
Prints information on Boost.Build and Boost.Jam
versions.
Invokes the online help system. This prints general
information on how to use the help system with additional
--help* options.
Produces debug information about loading of Boost.Build
and toolset files.Prints what targets are being built and with what properties.
Produces debug output from generator search process.
Useful for debugging custom generators.
Do not load site-config.jam and
user-config.jam configuration files.
Enables internal checks.
For complete specification of command line syntax, see
Declaring targets
A Main target is a user-defined named
entity that can be built, for example an executable file.
Declaring a main target is usually done using one of the main
target rules described in . The user can also declare
custom main target rules as shown in .
main targetdeclaration
syntaxMost main target rules in Boost.Build have the same common
signature:common signature
rule rule-name (
main-target-name :
sources + :
requirements * :
default-build * :
usage-requirements * )
main-target-name is the name used
to request the target on command line and to use it from
other main targets. A main target name may contain
alphanumeric characters, dashes
(‘-’), and underscores
(‘_’).
sources is the list of source files and other main
targets that must be combined.
requirements is the list of properties that must always
be present when this main target is built.
default-build is the list of properties that will be used
unless some other value of the same feature is already
specified, e.g. on the command line or by propogation from a dependent target.
usage-requirements is the list of properties that will be
propagated to all main targets that use this one, i.e. to all its
dependents.
Some main target rules have a different list of parameters, their
documentation explicitly says so.
The actual requirements for a target are obtained by refining
requirements of the project where a target is declared with the
explicitly specified requirements. The same is true for
usage-requirements. More details can be found in
NameThe name of main target has two purposes. First, it's used to refer to this target from
other targets and from command line. Second, it's used to compute the names of the generated files.
Typically, filenames are obtained from main target name by appending system-dependent suffixes and
prefixes.
Name of main target can contain alphanumeral characters, dash, undescore and dot. The entire
name is significant when resolving references from other targets. For determining filenames, only the
part before the first dot is taken. For example:
obj test.release : test.cpp : <variant>release ;
obj test.debug : test.cpp : <variant>debug ;
will generate two files named test.obj (in two different directories), not
two files named test.release.obj and test.debug.obj.
SourcesThe list of sources specifies what should be processed to
get the resulting targets. Most of the time, it's just a list of
files. Sometimes, you'll want to automatically construct the
list of source files rather than having to spell it out
manually, in which case you can use the
glob rule. Here are two examples:
exe a : a.cpp ; # a.cpp is the only source file
exe b : [ glob *.cpp ] ; # all .cpp files in this directory are sources
Unless you specify a file with an absolute path, the name is
considered relative to the source directory—which is typically
the directory where the Jamfile is located, but can be changed as
described in .
The list of sources can also refer to other main targets.
Targets in the same project can be referred to by name, while
targets in other projects must be qualified with a directory or a
symbolic project name. The directory/project name is separated from
the target name by double slash. There's no special syntax to
distinguish directory name from project name—the part before
double slash is first looked up as project name, and then as directory
name. For example:
lib helper : helper.cpp ;
exe a : a.cpp helper ;
# Since all project ids start with slash, ".." is directory name.
exe b : b.cpp ..//utils ;
exe c : c.cpp /boost/program_options//program_options ;
The first exe uses the library defined in the same
project. The second one uses some target (most likely library)
defined by Jamfile one level higher. Finally, the third target
uses some C++ Boost
library, referring to it by absolute symbolic name. More
information about target references can be found in and .
RequirementsRequirements are the properties that should always be present when
building a target. Typically, they are includes and defines:
exe hello : hello.cpp : <include>/opt/boost <define>MY_DEBUG ;
There is a number of other features, listed in
. For example if
a library can only be built statically, or a file can't be compiled
with optimization due to a compiler bug, one can use
lib util : util.cpp : <link>static ;
obj main : main.cpp : <optimization>off ;
Sometimes, particular relationships need to be maintained
among a target's build properties. This can be achieved with
conditional
requirements. For example, you might want to set
specific #defines when a library is built as shared,
or when a target's release variant is built in
release mode.
lib network : network.cpp
: <link>shared:<define>NEWORK_LIB_SHARED
<variant>release:<define>EXTRA_FAST
;
In the example above, whenever network is
built with <link>shared,
<define>NEWORK_LIB_SHARED will be in its
properties, too.
You can use several properties in the condition, for example:
lib network : network.cpp
: <toolset>gcc,<optimization>speed:<define>USE_INLINE_ASSEMBLER
;
More powerfull variant of conditional requirements is indirect conditional requiremens.
You can provide a rule that will be called with the current build properties and can compute additional properties
to be added. For example:
lib network : network.cpp
: <conditional>@my-rule
;
rule my-rule ( properties * )
{
local result ;
if <toolset>gcc <optimization>speed in $(properties)
{
result += <define>USE_INLINE_ASSEMBLER ;
}
return $(result) ;
}
This example is equivalent to the previous one, but for complex cases, indirect conditional
requirements can be easier to write and understand.
Default buildThe default-build parameter
is a set of properties to be used if the build request does
not otherwise specify a value for features in the set. For example:
exe hello : hello.cpp : : <threading>multi ;
would build a multi-threaded target in unless the user
explicitly requests a single-threaded version. The difference between
requirements and default-build is that requirements cannot be
overriden in any way.
Additional information
The ways a target is built can be 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
In the example above, when built with gcc
or msvc, demangler
will use a source file specific to the toolset. Otherwise, it
will use a generic source file,
dummy_demangler.cpp.
It is possible to declare a target inline, i.e. the "sources"
parameter may include calls to other main rules. For example:
exe hello : hello.cpp
[ obj helpers : helpers.cpp : <optimization>off ] ;
Will cause "helpers.cpp" to be always compiled without
optimization. When referring to an inline main target, its declared
name must be prefixed by its parent target's name and two dots. In
the example above, to build only helpers, one should run
bjam hello..helpers.
When no target is requested on the command line, all targets in the
current project will be built. If a target should be built only by
explicit request, this can be expressed by the
explicit rule:
explicit install_programs ;ProjectsAs mentioned before, targets are grouped into projects,
and each Jamfile is a separate project. Projects are useful
because they allow us to group related targets together, define
properties common to all those targets, and assign a symbolic
name to the project that can be used in referring to its
targets.
Projects are named using the
project rule, which has the
following syntax:
project id : attributes ;
Here, attributes is a sequence of
rule arguments, each of which begins with an attribute-name
and is followed by any number of build properties. The list
of attribute names along with its handling is also shown in
the table below. For example, it is possible to write:
project tennis
: requirements <threading>multi
: default-build release
;
The possible attributes are listed below.Project id is a short way to denote a project, as
opposed to the Jamfile's pathname. It is a hierarchical path,
unrelated to filesystem, such as "boost/thread". Target references make use of project ids to
specify a target.Source location specifies the directory where sources
for the project are located.Project requirements are requirements that apply to
all the targets in the projects as well as all subprojects.Default build is the build request that should be
used when no build request is specified explicitly.
The default values for those attributes are
given in the table below.
AttributeNameDefault valueHandling by the project
ruleProject idnonenoneAssigned from the first parameter of the 'project' rule.
It is assumed to denote absolute project id.Source locationsource-locationThe location of jamfile for the projectSets to the passed valueRequirementsrequirementsThe parent's requirementsThe parent's requirements are refined with the passed
requirement and the result is used as the project
requirements.Default builddefault-buildnoneSets to the passed valueBuild directorybuild-dirEmpty if the parent has no build directory set.
Otherwise, the parent's build directory with the
relative path from parent to the current project
appended to it.
Sets to the passed value, interpreted as relative to the
project's location.
Besides defining projects and main targets, Jamfiles
commonly invoke utility rules such as
constant and
path-constant, which inject a
specified Boost.Jam variable setting into this project's Jamfile
module and those of all its subprojects. See for a complete description
of these utility rules. Jamfiles are regular Boost.Jam source
files and Boost.Build modules, so naturally they can contain any kind of Boost.Jam code,
including rule definitions.
Each subproject inherits attributes, constants and rules
from its parent project, which is defined by the nearest
Jamfile in an ancestor directory above
the subproject. The top-level project is declared in a file
called Jamroot rather than
Jamfile. When loading a project,
Boost.Build looks for either Jamroot or
Jamfile. They are handled identically, except
that if the file is called Jamroot, the
search for a parent project is not performed.
Even when building in a subproject directory, parent
project files are always loaded before those of their
subprojects, so that every definition made in a parent project
is always available to its children. The loading order of any
other projects is unspecified. Even if one project refers to
another via use-project,
or a target reference, no specific order should be assumed.
Giving the root project the special name
“Jamroot” ensures that
Boost.Build won't misinterpret a directory above it as the
project root just because the directory contains a Jamfile.
Jamfile Utility RulesThe following table describes utility rules that can be
used in Jamfiles. Detailed information for any of these rules can
be obtained by running:
bjam --help project.rulename
RuleSemanticsproject
Define this project's symbolic ID or attributes.use-projectMake another project known so that it can be referred to by symbolic ID.build-projectCause another project to be built when this one is built.explicitState that a target should be built only by explicit
request.globTranslate a list of shell-style wildcards into a
corresponding list of files.constantInjects a variable setting into this project's
Jamfile module and those of all its subprojects.path-constantInjects a variable set to a path value into
this project's Jamfile module and those of all its subprojects.
If the value is a relative path it will be adjusted for
each subproject so that it refers to the same
directory.
The Build ProcessWhen you've described your targets, you want Boost.Build to run the
right tools and create the needed targets.
This section will describe
two things: how you specify what to build, and how the main targets are
actually constructed.
The most important thing to note is that in Boost.Build, unlike
other build tools, the targets you declare do not correspond to specific
files. What you declare in a Jamfile is more like a “metatarget.”
Depending on the properties you specify on the command line,
each metatarget will produce a set of real targets corresponding
to the requested properties. It is quite possible that the same
metatarget is built several times with different properties,
producing different files.
This means that for Boost.Build, you cannot directly obtain a build
variant from a Jamfile. There could be several variants requested by the
user, and each target can be built with different properties.
Build request
The command line specifies which targets to build and with which
properties. For example:
bjam app1 lib1//lib1 toolset=gcc variant=debug optimization=full
would build two targets, "app1" and "lib1//lib1" with the specified
properties. You can refer to any targets, using
target id and specify arbitrary
properties. Some of the properties are very common, and for them the name
of the property can be omitted. For example, the above can be written as:
bjam app1 lib1//lib1 gcc debug optimization=full
The complete syntax, which has some additional shortcuts, is
described in .
Building a main targetWhen you request, directly or indirectly, a build of a main target
with specific requirements, the following steps are done. Some brief
explanation is provided, and more details are given in .
Applying default build. If the default-build
property of a target specifies a value of a feature that is not
present in the build request, that value is added.Selecting the main target alternative to use. For
each alternative we look how many properties are present both in
alternative's requirements, and in build request. The
alternative with large number of matching properties is selected.
Determining "common" properties.
The build request
is refined
with target's requirements.
The conditional properties in
requirements are handled as well. Finally, default values of
features are added.
Building targets referred by the sources list and
dependency properties. The list of sources and the properties
can refer to other target using target references. For each
reference, we take all propagated
properties, refine them by explicit properties specified in the
target reference, and pass the resulting properties as build
request to the other target.
Adding the usage requirements produced when building
dependencies to the "common" properties. When dependencies are
built in the previous step, they return
both the set of created
"real" targets, and usage requirements. The usage requirements
are added to the common properties and the resulting property
set will be used for building the current target.
Building the target using generators. To convert the
sources to the desired type, Boost.Build uses "generators" ---
objects that correspond to tools like compilers and
linkers. Each generator declares what type of targets it
can
produce and what type of sources it requires. Using this
information, Boost.Build determines which generators must be run
to produce a specific target from specific sources. When
generators are run, they return the "real" targets.
Computing the usage requirements to be returned. The
conditional properties in usage requirements are expanded
and the
result is returned.Building a projectOften, a user builds a complete project, not just one main
target. In fact, invoking bjam without
arguments
builds the project defined in the current
directory.When a project is built, the build request is passed without
modification to all main targets in that project.
It's is possible to
prevent implicit building of a target in a project with the
explicit rule:
explicit hello_test ;
would cause the hello_test target to be built only if
explicitly requested by the user or by some other target.
The Jamfile for a project can include a number of
build-project rule calls
that specify additional projects
to be built.
Builtin target typesThis section describes main targets types that Boost.Build supports
of-of-the-box. Unless otherwise noted, all mentioned main target rules
have the common signature, described in .
ProgramsBuiltin
rulesexePrograms are created using the exe rule, which
follows the common
syntax. For example:
exe hello : hello.cpp some_library.lib /some_project//library
: <threading>multi
;
This will create an executable file from the sources -- in this case,
one C++ file, one library file present in the same directory, and
another library that is created by Boost.Build. Generally, sources
can include C and C++ files, object files and libraries. Boost.Build
will automatically try to convert targets of other types.
On Windows, if an application uses dynamic libraries, and both
the application and the libraries are built by Boost.Build, its not
possible to immediately run the application, because the
PATH environment variable should include the path
to the libraries. It means you have to either add the paths
manually, or place the application and the libraries to the same
directory, for example using the
stage rule.
LibrariesLibraries are created using the lib rule, which
follows the common
syntax. For example:
lib helpers : helpers.cpp : <include>boost : : <include>. ;
In the most common case, the lib creates a library
from the specified sources. Depending on the value of
<link> feature the library will be either static or
shared. There are two other cases. First is when the library is
installed somewhere in compiler's search paths, and should be
searched by the compiler (typically, using the
option). The second case is where the library is available as a
prebuilt file and the full path is known.
The syntax for these case is given below:
lib z : : <name>z <search>/home/ghost ;
lib compress : : <file>/opt/libs/compress.a ;
The name property specifies the name that should be
passed to the option, and the file
property specifies the file location. The search feature
specifies paths in which to search for the library. That feature can
be specified several times, or it can be omitted, in which case only
default compiler paths will be searched.
The difference between using the file feature as
opposed to the name feature together with the
search feature is that file is more
precise. A specific file will be used. On the other hand, the
search feature only adds a library path, and the
name feature gives the basic name of the library. The
search rules are specific to the linker. For example, given these
definition:
lib a : : <variant>release <file>/pool/release/a.so ;
lib a : : <variant>debug <file>/pool/debug/a.so ;
lib b : : <variant>release <file>/pool/release/b.so ;
lib b : : <variant>debug <file>/pool/debug/b.so ;
It's possible to use release version of a and debug
version of b. Had we used the name and
search features, the linker would always pick either
release or debug versions.
For convenience, the following syntax is allowed:
lib z ;
lib gui db aux ;
and is does exactly the same as:
lib z : : <name>z ;
lib gui : : <name>gui ;
lib db : : <name>db ;
lib aux : : <name>aux ;
When a library uses another library you should put that other
library in the list of sources. This will do the right thing in all
cases. For portability, you should specify library dependencies even
for searched and prebuilt libraries, othewise, static linking on
Unix won't work. For example:
lib z ;
lib png : z : <name>png ;
When a library (say, a), that has another
library, (say, b)
is linked dynamically, the b
library will be incorporated
in a. (If b
is dynamic library as well, then a will only refer to
it, and not include any extra code.)
When the a
library is linked statically, Boost.Build will assure that all
executables that link to a will also link to
b.
One feature of Boost.Build that is very important for libraries
is usage requirements.
For example, if you write:
lib helpers : helpers.cpp : : : <include>. ;
then the compiler include path for all targets that use
helpers will contain the directory
where the target is defined.path to "helpers.cpp". The user
only needs to add helpers to the list of sources,
and needn't consider the requirements its use imposes on a
dependent target. This feature greatly simplifies Jamfiles.
If you don't want shared libraries to include all libraries
that are specified in sources (especially statically linked ones),
you'd need to use the following:
lib b : a.cpp ;
lib a : a.cpp : <use>b : : <library>b ;
This specifies that a uses b, and causes
all executables that link to a also link to
b. In this case, even for shared linking, the
a library won't even refer to b.
Alias
The alias rule gives alternative name to
a group of targets. For example, to give the name
core to a group of three other targets with the
following code:
alias core : im reader writer ;
Using core on the command line, or in the source list
of any other target is the same as explicitly using
im, reader, and
writer, but it is just more convenient.
Another use of the alias rule is to change build
properties. For example, if you always want static linking for a
specific C++ Boost library, you can write the following:
alias threads : /boost/thread//boost_thread : <link>static ;
and use only the threads alias in your Jamfiles.
You can also specify usage requirements for the
alias target. If you write the following:
alias header_only_library : : : : <include>/usr/include/header_only_library ;
then using header_only_library in sources will only add an
include path. Also note that when there are some sources, their usage
requirements are propagated, too. For example:
lib lib : lib.cpp : : : <include>. ;
alias lib_alias ;
exe main : main.cpp lib_alias ;
will compile main.cpp with the additional include.
InstallingFor installing a built target you should use the
install rule, which follows the common syntax. For
example:
install dist : hello helpers ;
will cause the targets hello and helpers to
be moved to the dist directory, relative to
Jamfile's directory. The directory can
be changed with the location property:
install dist : hello helpers : <location>/usr/bin ;
While you can achieve the same effect by changing the target name to
/usr/bin, using the location
property is better, because it allows you to use a mnemonic target
name.
The location property is especially handy when the location
is not fixed, but depends on build variant or environment variables:
install dist : hello helpers : <variant>release:<location>dist/release
<variant>debug:<location>dist/debug ;
install dist2 : hello helpers : <location>$(DIST) ;
See also conditional
properties and environment variables
Specifying the names of all libraries to install can be boring. The
install allows you to specify only the top-level executable
targets to install, and automatically install all dependencies:
install dist : hello
: <install-dependencies>on <install-type>EXE
<install-type>LIB
;
will find all targets that hello depends on, and install
all of those which are either executables or libraries. More
specifically, for each target, other targets that were specified as
sources or as dependency properties, will be recursively found. One
exception is that targets referred with the use feature
are not considered, because that feature is typically used to refer to
header-only libraries.
If the set of target types is specified, only targets of that type
will be installed, otherwise, all found target will be installed.
The alias
rule can be used when targets must be installed into several
directories:
alias install : install-bin install-lib ;
install install-bin : applications : /usr/bin ;
install install-lib : helper : /usr/lib ;
Because the install rule just copies targets, most
free features see the definition of "free" in .
have no effect when used in requirements of the install rule.
The only two which matter are
dependency and, on Unix,
dll-path.
(Unix specific). On Unix, executables built with Boost.Build typically
contain the list of paths to all used dynamic libraries. For
installing, this is not desired, so Boost.Build relinks the executable
with an empty list of paths. You can also specify additional paths for
installed executables with the dll-path feature.
TestingBoost.Build has convenient support for running unit tests. The
simplest way is the unit-test rule, which follows the
common syntax. For
example:
unit-test helpers_test : helpers_test.cpp helpers ;
The unit-test rule behaves like the
exe rule, but after the executable is created it is
run. If the executable returns an error code, the build system will also
return an error and will try running the executable on the next
invocation until it runs successfully. This behaviour ensures that you
can't miss a unit test failure.
By default, the executable is run directly. Sometimes, it's
desirable to run the executable using some helper command. You should use the
testing.launcher property to specify the name of the
helper command. For example, if you write:
unit-test helpers_test
: helpers_test.cpp helpers
: <testing.launcher>valgrind
;
The command used to run the executable will be:valgrind bin/$toolset/debug/helpers_test
There are rules for more elaborate testing: compile,
compile-fail, run and
run-fail. They are more suitable for automated testing, and
are not covered here.
Raw commands: 'make' and 'notfile'Sometimes, the builtin target types are not enough, and you
want Boost.Build to just run specific commands. There are two main
target rules that make it possible: make
and notfile.
The make rule is used when you want to
create one file from a number of sources using some specific command.
The notfile is used to unconditionally run
a command.
Suppose you want to create file file.out from
file file.in by running command
in2out. Here's how you'd do this in Boost.Build:
actions in2out
{
in2out $(<) $(>)
}
make file.out : file.in : @in2out ;
If you run bjam and file.out
does not exist, Boost.Build will run the in2out
command to create that file. For more details on specifying actions,
see .
The make rule is useful to express custom
transformation that are used just once or twice in your project. For
transformations that are used often, you are advised to declare
new generator, as described in .
It could be that you just want to run some command unconditionally,
and that command does not create any specific files. The, you can use
the notfile rule. For example:
notfile echo_something : @echo ;
actions echo
{
echo "something"
}
The only difference from the make rule is
that the name of the target is not considered a name of a file, so
Boost.Build will unconditionally run the action.
Builtin featuresvariant
A feature that combines several low-level features, making
it easy to request common build configurations.
Allowed values:debug, release,
profile.The value debug expands to
<optimization>off <debug-symbols>on <inlining>off <runtime-debugging>on
The value release expands to
<optimization>speed <debug-symbols>off <inlining>full <runtime-debugging>off
The value profile expands to the same as
release, plus:
<profiling>on <debug-symbols>on
User can define his own build variants using the variant rule from the common
module.Notee: Runtime
debugging is on in debug builds to suit the expectations of
people used to various IDEs.
link
A feature that controls how libraries are built.
Allowed values:shared,
staticsource
The <source>X feature has the same effect on
building a target as putting X in the list of sources.
It's useful when you want to add
the same source to all targets in the project
(you can put <source> in requirements) or to conditionally
include a source (using conditional requirements, see )
See also the <library> feature.
library
This feature is almost equivalent to the <source> feature,
except that it takes effect only for linking. When you want to
link all targets in a Jamfile to certain library, the
<library> feature is preferred over
<source>X -- the latter will add the library to
all targets, even those that have nothing to do with libraries.
dependency
Introduces a dependency on the target named by the
value of this feature (so it will be brought
up-to-date whenever the target being declared is).
The dependency is not used in any other way. For example, in
application with plugins, the plugins are not used when linking
the application,
application might have dependency on its plugins, even though
, and
adds its usage requirements to the build properties
of the target being declared.
The primary use case is when you want
the usage requirements (such as #include paths) of some
library to be applied, but don't want to link to it.
use
Introduces a dependency on the target named by the
value of this feature (so it will be brought
up-to-date whenever the target being declared is), and
adds its usage requirements to the build properties
of the target being declared. The dependency is not used
in any other way. The primary use case is when you want
the usage requirements (such as #include paths) of some
library to be applied, but don't want to link to it.
dll-path
Specify an additional directory where the system should
look for shared libraries when the executable or shared
library is run. This feature only affects Unix
compilers. Plase see
in for details.
hardcode-dll-paths
Controls automatic generation of dll-path properties.
Allowed values:true, false. This property
is specific to Unix systems. If an executable is built with
<hardcode-dll-paths>true, the generated binary
will contain the list of all the paths to the used shared
libraries. As the result, the executable can be run without
changing system paths to shared libraries or installing the
libraries to system paths. This
is very convenient during
development. Plase see the FAQ entry for details.
Note that on Mac OSX, the paths are unconditionally hardcoded by
the linker, and it's not possible to disable that behaviour.
cflagscxxflagslinkflags
The value of those features is passed without modification to the
corresponding tools. For cflags that's both the C and C++
compilers, for cxxflags that's the C++ compiler and for
linkflags that's the linker. The features are handy when
you're trying to do something special that cannot be achieved by
higher-level feature in Boost.Build.
warnings
The <warnings> feature controls the warning level of compilers. It has the following values:
off - disables all warnings.on - enables default warning level for the tool.all - enables all warnings.
Default value is all.
warnings-as-errors
The <warnings-as-errors> makes it possible to treat warnings as errors and abort
compilation on a warning. The value on enables this behaviour. The default value is
off.
buildAllowed values:no
The build feature is used to conditionally disable build of a target. If <build>no
is in properties when building a target, build of that target is skipped. Combined with conditional requirements this
allows to skip building some target in configurations where the build is known to fail.
Differences to Boost.Build V1While Boost.Build V2 is based on the same ideas as Boost.Build V1,
some of the syntax was changed, and some new important features were
added. This chapter describes most of the changes.ConfigurationIn V1, toolsets were configured by environment variables. If you
wanted to use two versions of the same toolset, you had to create a new
toolset module that would set the variables and then invoke the base
toolset. In V2, toolsets are configured by the
using, and you can easily configure several
versions of a toolset. See for details.
Writing JamfilesProbably one of the most important differences in V2 Jamfiles is
the use of project requirements. In V1, if several targets had the same
requirements (for example, a common #include path), it was necessary to
manually write the requirements or use a helper rule or template target. In V2, the
common properties can be specified with the requirements project
attribute, as documented in .
Usage requirements
also help to simplify Jamfiles.
If a library requires
all clients to use specific #include paths or macros when compiling
code that depends on the library, that information can be cleanly
represented.The difference between lib and dll targets in V1 is completely
eliminated in V2. There's only one library target type, lib, which can create
either static or shared libraries depending on the value of the
<link>
feature. If your target should be only built in one way, you
can add <link>shared or <link>static to its requirements.
The syntax for referring to other targets was changed a bit. While
in V1 one would use:
exe a : a.cpp <lib>../foo/bar ;
the V2 syntax is:
exe a : a.cpp ../foo//bar ;
Note that you don't need to specify the type of other target, but the
last element should be separated from the others by a double slash to indicate that
you're referring to target bar in project ../foo, and not to
project ../foo/bar.
Build processThe command line syntax in V2 is completely different. For example
bjam -sTOOLS=msvc -sBUILD=release some_target
now becomes:
bjam toolset=msvc variant=release some_target
or, using implicit features, just:
bjam msvc release some_target
See the reference for a
complete description of the syntax.