1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5 <title>Common tasks</title>
6 <link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
7 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8 <link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9 <link rel="up" href="../bbv2.html" title="Chapter 49. Boost.Build User Manual">
10 <link rel="prev" href="overview.html" title="Overview">
11 <link rel="next" href="reference.html" title="Reference">
13 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14 <table cellpadding="2" width="100%"><tr>
15 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
16 <td align="center"><a href="../../../index.html">Home</a></td>
17 <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
18 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20 <td align="center"><a href="../../../more/index.htm">More</a></td>
23 <div class="spirit-nav">
24 <a accesskey="p" href="overview.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../bbv2.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
27 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
28 <a name="bbv2.tasks"></a>Common tasks</h2></div></div></div>
29 <div class="toc"><dl class="toc">
30 <dt><span class="section"><a href="tasks.html#bbv2.tasks.programs">Programs</a></span></dt>
31 <dt><span class="section"><a href="tasks.html#bbv2.tasks.libraries">Libraries</a></span></dt>
32 <dt><span class="section"><a href="tasks.html#bbv2.tasks.alias">Alias</a></span></dt>
33 <dt><span class="section"><a href="tasks.html#bbv2.tasks.installing">Installing</a></span></dt>
34 <dt><span class="section"><a href="tasks.html#bbv2.builtins.testing">Testing</a></span></dt>
35 <dt><span class="section"><a href="tasks.html#bbv2.builtins.raw">Custom commands</a></span></dt>
36 <dt><span class="section"><a href="tasks.html#bbv2.reference.precompiled_headers">Precompiled Headers</a></span></dt>
37 <dt><span class="section"><a href="tasks.html#bbv2.reference.generated_headers">Generated headers</a></span></dt>
38 <dt><span class="section"><a href="tasks.html#bbv2.tasks.crosscompile">Cross-compilation</a></span></dt>
41 This section describes main targets types that Boost.Build supports
42 out-of-the-box. Unless otherwise noted, all mentioned main target rules have
43 the common signature, described in <a class="xref" href="overview.html#bbv2.overview.targets" title="Declaring Targets">the section called “Declaring Targets”</a>.
46 <div class="titlepage"><div><div><h3 class="title">
47 <a name="bbv2.tasks.programs"></a>Programs</h3></div></div></div>
48 <a class="indexterm" name="idp637041952"></a><p>
49 Programs are created using the <code class="computeroutput">exe</code> rule, which follows the
50 <a class="link" href="overview.html#bbv2.main-target-rule-syntax">common syntax</a>. For
53 <pre class="programlisting">
54 exe hello : hello.cpp some_library.lib /some_project//library
55 : <threading>multi
59 This will create an executable file from the sources—in this case, one
60 C++ file, one library file present in the same directory, and another
61 library that is created by Boost.Build. Generally, sources can include C
62 and C++ files, object files and libraries. Boost.Build will automatically
63 try to convert targets of other types.
65 <div class="tip"><table border="0" summary="Tip">
67 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../doc/src/images/tip.png"></td>
68 <th align="left">Tip</th>
70 <tr><td align="left" valign="top"><p>
71 On Windows, if an application uses shared libraries, and both the
72 application and the libraries are built using Boost.Build, it is not
73 possible to immediately run the application, because the <code class="literal">PATH
74 </code> environment variable should include the path to the
75 libraries. It means you have to either add the paths manually, or have
76 the build place the application and the libraries into the same
77 directory. See <a class="xref" href="tasks.html#bbv2.tasks.installing" title="Installing">the section called “Installing”</a>.
82 <div class="titlepage"><div><div><h3 class="title">
83 <a name="bbv2.tasks.libraries"></a>Libraries</h3></div></div></div>
84 <a class="indexterm" name="idp637050368"></a><p>
85 Library targets are created using the <code class="computeroutput">lib</code> rule, which
86 follows the <a class="link" href="overview.html#bbv2.main-target-rule-syntax">common syntax
89 <pre class="programlisting">
90 lib helpers : helpers.cpp ;
93 This will define a library target named <code class="computeroutput">helpers</code> built from
94 the <code class="computeroutput">helpers.cpp</code> source file.
95 It can be either a static library or a shared library,
96 depending on the value of the <a class="link" href="reference.html#bbv2.overview.builtins.features.link"><link></a> feature.
99 Library targets can represent:
101 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
102 <li class="listitem"><p>
103 Libraries that should be built from source,
104 as in the example above.
106 <li class="listitem"><p>
107 Prebuilt libraries which already exist on the system.
108 Such libraries can be searched for by the tools using them (typically
109 with the linker's <code class="option">-l</code> option) or their paths can be
110 known in advance by the build system.
116 The syntax for prebuilt libraries is given below:
118 <pre class="programlisting">
119 lib z : : <name>z <search>/home/ghost ;
120 lib compress : : <file>/opt/libs/compress.a ;
123 The <code class="computeroutput">name</code> property specifies the name of the library
124 without the standard prefixes and suffixes. For example, depending
125 on the system, <code class="computeroutput">z</code> could refer to a file called
126 z.so, libz.a, or z.lib, etc. The <code class="computeroutput">search</code> feature
127 specifies paths in which to search for the library in addition
128 to the default compiler paths. <code class="computeroutput">search</code> can be specified
129 several times or it can be omitted, in which case only the default
130 compiler paths will be searched. The <code class="computeroutput">file</code> property
131 specifies the file location.
134 The difference between using the <code class="computeroutput">file</code> feature and
135 using a combination of the <code class="computeroutput">name</code> and <code class="computeroutput">search</code>
136 features is that <code class="computeroutput">file</code> is more precise.
139 <div class="warning"><table border="0" summary="Warning">
141 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../doc/src/images/warning.png"></td>
142 <th align="left">Warning</th>
144 <tr><td align="left" valign="top">
146 The value of the <code class="computeroutput">search</code> feature is just added to the
147 linker search path. When linking to multiple libraries,
148 the paths specified by <code class="computeroutput">search</code> are combined without
149 regard to which <code class="computeroutput">lib</code> target each path came from.
152 <pre class="programlisting">
153 lib a : : <name>a <search>/pool/release ;
154 lib b : : <name>b <search>/pool/debug ;
157 If /pool/release/a.so, /pool/release/b.so, /pool/debug/a.so,
158 and /pool/release/b.so all exist, the linker will probably
159 take both <code class="computeroutput">a</code> and <code class="computeroutput">b</code> from the same
160 directory, instead of finding <code class="computeroutput">a</code> in /pool/release
161 and <code class="computeroutput">b</code> in /pool/debug. If you need to distinguish
162 between multiple libraries with the same name, it's safer
163 to use <code class="computeroutput">file</code>.
170 For convenience, the following syntax is allowed:
172 <pre class="programlisting">
177 which has exactly the same effect as:
179 <pre class="programlisting">
180 lib z : : <name>z ;
181 lib gui : : <name>gui ;
182 lib db : : <name>db ;
183 lib aux : : <name>aux ;
188 When a library references another library you should put that other
189 library in its list of sources. This will do the right thing in all cases.
190 For portability, you should specify
191 library dependencies even for searched and prebuilt libraries, othewise,
192 static linking on Unix will not work. For example:
194 <pre class="programlisting">
196 lib png : z : <name>png ;
200 <div class="note"><table border="0" summary="Note">
202 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
203 <th align="left">Note</th>
205 <tr><td align="left" valign="top">
207 When a library has a shared library as a source, or a static
208 library has another static library as a source then any target
209 linking to the first library with automatically link to its source
213 On the other hand, when a shared library has a static library as
214 a source then the first library will be built so that it completely
215 includes the second one.
218 If you do not want a shared library to include all the libraries specified
219 in its sources (especially statically linked ones), you would need to
222 <pre class="programlisting">
224 lib a : a.cpp : <use>b : : <library>b ;
227 This specifies that library <code class="computeroutput">a</code> uses library <code class="computeroutput">b</code>,
228 and causes all executables that link to <code class="computeroutput">a</code> to link to
229 <code class="computeroutput">b</code> also. In this case, even for shared linking, the
230 <code class="computeroutput">a</code> library will not refer to <code class="computeroutput">b</code>.
236 <a class="link" href="overview.html#bbv2.overview.targets" title="Declaring Targets">Usage requirements</a> are often
237 very useful for defining library targets. For example, imagine that
238 you want you build a <code class="computeroutput">helpers</code> library and its interface is
239 described in its <code class="computeroutput">helpers.hpp</code> header file located in the same
240 directory as the <code class="computeroutput">helpers.cpp</code> source file. Then you could add
241 the following to the Jamfile located in that same directory:
243 <pre class="programlisting">
244 lib helpers : helpers.cpp : : : <include>. ;
247 which would automatically add the directory where the target has been
248 defined (and where the library's header file is located) to the compiler's
249 include path for all targets using the <code class="computeroutput">helpers</code> library. This
250 feature greatly simplifies Jamfiles.
253 <div class="section">
254 <div class="titlepage"><div><div><h3 class="title">
255 <a name="bbv2.tasks.alias"></a>Alias</h3></div></div></div>
257 The <code class="computeroutput">alias</code> rule gives an alternative name to a
258 group of targets. For example, to give the name <code class="filename">core</code>
259 to a group of three other targets with the following code:
261 <pre class="programlisting">
262 alias core : im reader writer ;
265 Using <code class="filename">core</code> on the command line, or in the source list
266 of any other target is the same as explicitly using <code class="filename">im
267 </code>, <code class="filename">reader</code>, and <code class="filename">writer</code>.
270 Another use of the <code class="computeroutput">alias</code> rule is to change build properties.
271 For example, if you want to use link statically to the Boost Threads
272 library, you can write the following:
274 <pre class="programlisting">
275 alias threads : /boost/thread//boost_thread : <link>static ;
278 and use only the <code class="computeroutput">threads</code> alias in your Jamfiles.
281 You can also specify usage requirements for the <code class="computeroutput">alias</code> target.
282 If you write the following:
284 <pre class="programlisting">
285 alias header_only_library : : : : <include>/usr/include/header_only_library ;
288 then using <code class="computeroutput">header_only_library</code> in sources will only add an
289 include path. Also note that when an alias has sources, their usage
290 requirements are propagated as well. For example:
292 <pre class="programlisting">
293 lib library1 : library1.cpp : : : <include>/library/include1 ;
294 lib library2 : library2.cpp : : : <include>/library/include2 ;
295 alias static_libraries : library1 library2 : <link>static ;
296 exe main : main.cpp static_libraries ;
299 will compile <code class="filename">main.cpp</code> with additional includes
300 required for using the specified static libraries.
303 <div class="section">
304 <div class="titlepage"><div><div><h3 class="title">
305 <a name="bbv2.tasks.installing"></a>Installing</h3></div></div></div>
307 This section describes various ways to install built target and arbitrary
311 <a name="idp637109104"></a>Basic install</h4>
313 For installing a built target you should use the <code class="computeroutput">install</code>
314 rule, which follows the <a class="link" href="overview.html#bbv2.main-target-rule-syntax">
315 common syntax</a>. For example:
317 <pre class="programlisting">
318 install dist : hello helpers ;
321 will cause the targets <code class="computeroutput">hello</code> and <code class="computeroutput">helpers</code> to be
322 moved to the <code class="filename">dist</code> directory, relative to the
323 Jamfile's directory. The directory can be changed using the
324 <code class="computeroutput">location</code> property:
326 <pre class="programlisting">
327 install dist : hello helpers : <location>/usr/bin ;
330 While you can achieve the same effect by changing the target name to
331 <code class="filename">/usr/bin</code>, using the <code class="computeroutput">location</code> property is
332 better as it allows you to use a mnemonic target name.
335 The <code class="computeroutput">location</code> property is especially handy when the location
336 is not fixed, but depends on the build variant or environment variables:
338 <pre class="programlisting">
339 install dist : hello helpers :
340 <variant>release:<location>dist/release
341 <variant>debug:<location>dist/debug ;
342 install dist2 : hello helpers : <location>$(DIST) ;
345 See also <a class="link" href="reference.html#bbv2.reference.variants.propcond" title="Conditional properties">conditional
346 properties</a> and <a class="link" href="faq.html#bbv2.faq.envar" title="Accessing environment variables">environment
350 <a name="idp637121808"></a>Installing with all dependencies</h4>
352 Specifying the names of all libraries to install can be boring. The
353 <code class="computeroutput">install</code> allows you to specify only the top-level executable
354 targets to install, and automatically install all dependencies:
356 <pre class="programlisting">
358 : <install-dependencies>on <install-type>EXE
359 <install-type>LIB
363 will find all targets that <code class="computeroutput">hello</code> depends on, and install all
364 of those which are either executables or libraries. More specifically, for
365 each target, other targets that were specified as sources or as dependency
366 properties, will be recursively found. One exception is that targets
367 referred with the <a class="link" href="reference.html#bbv2.builtin.features.use">
368 <code class="computeroutput">use</code></a> feature are not considered, as that feature is
369 typically used to refer to header-only libraries. If the set of target
370 types is specified, only targets of that type will be installed,
371 otherwise, all found target will be installed.
374 <a name="idp637127200"></a>Preserving Directory Hierarchy</h4>
375 <a class="indexterm" name="idp637127584"></a><p>
376 By default, the <code class="computeroutput">install</code> rule will strip paths from its
377 sources. So, if sources include <code class="filename">a/b/c.hpp</code>, the
378 <code class="filename">a/b</code> part will be ignored. To make the
379 <code class="computeroutput">install</code> rule preserve the directory hierarchy you need to
380 use the <code class="literal"><install-source-root></code> feature to specify
381 the root of the hierarchy you are installing. Relative paths from that
382 root will be preserved. For example, if you write:
384 <pre class="programlisting">
387 : <location>/tmp <install-source-root>a
391 the a file named <code class="filename">/tmp/b/c.h</code> will be created.
394 The <a class="link" href="reference.html#bbv2.reference.glob-tree">glob-tree</a> rule can be
395 used to find all files below a given directory, making it easy to install
396 an entire directory tree.
399 <a name="idp637135936"></a>Installing into Several Directories</h4>
401 The <a class="link" href="tasks.html#bbv2.tasks.alias" title="Alias"><code class="computeroutput">alias</code></a> rule can be
402 used when targets need to be installed into several directories:
404 <pre class="programlisting">
405 alias install : install-bin install-lib ;
406 install install-bin : applications : /usr/bin ;
407 install install-lib : helper : /usr/lib ;
412 Because the <code class="computeroutput">install</code> rule just copies targets, most free
413 features <a href="#ftn.idp637139920" class="footnote" name="idp637139920"><sup class="footnote">[18]</sup></a> have no
414 effect when used in requirements of the <code class="computeroutput">install</code> rule. The
415 only two that matter are <a class="link" href="reference.html#bbv2.builtin.features.dependency">
416 <code class="varname">dependency</code></a> and, on Unix, <a class="link" href="reference.html#bbv2.reference.features.dll-path"><code class="varname">dll-path</code>
419 <div class="note"><table border="0" summary="Note">
421 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
422 <th align="left">Note</th>
424 <tr><td align="left" valign="top"><p>
425 (Unix specific) On Unix, executables built using Boost.Build typically
426 contain the list of paths to all used shared libraries. For installing,
427 this is not desired, so Boost.Build relinks the executable with an empty
428 list of paths. You can also specify additional paths for installed
429 executables using the <code class="varname">dll-path</code> feature.
433 <div class="section">
434 <div class="titlepage"><div><div><h3 class="title">
435 <a name="bbv2.builtins.testing"></a>Testing</h3></div></div></div>
437 Boost.Build has convenient support for running unit tests. The simplest
438 way is the <code class="computeroutput">unit-test</code> rule, which follows the <a class="link" href="overview.html#bbv2.main-target-rule-syntax">common syntax</a>. For example:
440 <pre class="programlisting">
441 unit-test helpers_test : helpers_test.cpp helpers ;
446 The <code class="computeroutput">unit-test</code> rule behaves like the
447 <a class="link" href="tasks.html#bbv2.tasks.programs" title="Programs">exe</a> rule, but after the executable is created
448 it is also run. If the executable returns an error code, the build system
449 will also return an error and will try running the executable on the next
450 invocation until it runs successfully. This behaviour ensures that you can
451 not miss a unit test failure.
454 There are few specialized testing rules, listed below:
456 <pre class="programlisting">
457 rule compile ( sources : requirements * : target-name ? )
458 rule compile-fail ( sources : requirements * : target-name ? )
459 rule link ( sources + : requirements * : target-name ? )
460 rule link-fail ( sources + : requirements * : target-name ? )
463 They are given a list of sources and requirements. If the target name is
464 not provided, the name of the first source file is used instead. The
465 <code class="literal">compile*</code> tests try to compile the passed source. The
466 <code class="literal">link*</code> rules try to compile and link an application from
467 all the passed sources. The <code class="literal">compile</code> and <code class="literal">link
468 </code> rules expect that compilation/linking succeeds. The <code class="literal">
469 compile-fail</code> and <code class="literal">link-fail</code> rules expect that
470 the compilation/linking fails.
473 There are two specialized rules for running applications, which are more
474 powerful than the <code class="computeroutput">unit-test</code> rule. The <code class="computeroutput">run</code> rule
475 has the following signature:
477 <pre class="programlisting">
478 rule run ( sources + : args * : input-files * : requirements * : target-name ?
482 The rule builds application from the provided sources and runs it, passing
483 <code class="varname">args</code> and <code class="varname">input-files</code> as command-line
484 arguments. The <code class="varname">args</code> parameter is passed verbatim and
485 the values of the <code class="varname">input-files</code> parameter are treated as
486 paths relative to containing Jamfile, and are adjusted if <span class="command"><strong>b2</strong></span>
487 is invoked from a different directory. The
488 <code class="computeroutput">run-fail</code> rule is identical to the <code class="computeroutput">run</code> rule,
489 except that it expects that the run fails.
492 All rules described in this section, if executed successfully, create a
493 special manifest file to indicate that the test passed. For the
494 <code class="computeroutput">unit-test</code> rule the files is named <code class="filename"><em class="replaceable"><code>
495 target-name</code></em>.passed</code> and for the other rules it is
496 called <code class="filename"><em class="replaceable"><code>target-name</code></em>.test</code>.
497 The <code class="computeroutput">run*</code> rules also capture all output from the program, and
498 store it in a file named <code class="filename"><em class="replaceable"><code>
499 target-name</code></em>.output</code>.
502 <a class="indexterm" name="idp637171056"></a>
503 If the <code class="literal">preserve-test-targets</code> feature has the value
504 <code class="literal">off</code>, then <code class="computeroutput">run</code> and the <code class="computeroutput">run-fail</code>
505 rules will remove the executable after running it. This somewhat decreases
506 disk space requirements for continuous testing environments. The default
507 value of <code class="literal">preserve-test-targets</code> feature is <code class="literal">on</code>.
510 It is possible to print the list of all test targets (except for
511 <code class="computeroutput">unit-test</code>) declared in your project, by passing the <code class="literal">
512 --dump-tests</code> command-line option. The output will consist of
516 boost-test(<em class="replaceable"><code>test-type</code></em>) <em class="replaceable"><code>path</code></em> : <em class="replaceable"><code>sources</code></em>
521 It is possible to process the list of tests, Boost.Build output
522 and the presense/absense of the <code class="filename">*.test</code>
523 files created when test passes into human-readable status table of tests.
524 Such processing utilities are not included in Boost.Build.
526 <p>The following features adjust behaviour of the testing metatargets.</p>
527 <div class="variablelist"><dl class="variablelist">
528 <dt><span class="term"><code class="literal">testing.arg</code></span></dt>
531 Defines an argument to be passed to the target when it is executed
532 before the list of input files.
536 <pre class="programlisting">
537 unit-test helpers_test
538 : helpers_test.cpp helpers
539 : <span class="bold"><strong><testing.arg>"--foo bar"</strong></span>
545 <dt><span class="term"><code class="literal">testing.input-file</code></span></dt>
547 Specifies a file to be passed to the executable on the command line
548 after the arguments. All files must be specified in alphabetical
549 order due to constrainsts in the current implementation.
551 <dt><span class="term"><code class="literal">testing.launcher</code></span></dt>
554 By default, the executable is run directly. Sometimes, it is
555 desirable to run the executable using some helper command. You
556 should use this property to specify the name of the helper
557 command. For example, if you write:
559 <pre class="programlisting">
560 unit-test helpers_test
561 : helpers_test.cpp helpers
562 : <span class="bold"><strong><testing.launcher>valgrind</strong></span>
566 The command used to run the executable will be:
569 <span class="bold"><strong>valgrind</strong></span> bin/$toolset/debug/helpers_test
574 <dt><span class="term"><code class="literal">test-info</code></span></dt>
576 A description of the test. This is displayed as part of the
577 <code class="literal">--dump-tests</code> command-line option.
581 <div class="section">
582 <div class="titlepage"><div><div><h3 class="title">
583 <a name="bbv2.builtins.raw"></a>Custom commands</h3></div></div></div>
585 For most main target rules, Boost.Build automatically figures out
586 the commands to run. When you want to use new
587 file types or support new tools, one approach is to extend Boost.Build to
588 support them smoothly, as documented in <a class="xref" href="extender.html" title="Extender Manual">the section called “Extender Manual”</a>.
589 However, if the new tool is only used in a single place, it
590 might be easier just to specify the commands to run explicitly.
594 Three main target rules can be used for that. The <code class="computeroutput">make
595 </code> rule allows you to construct a single file from any number
596 of source file, by running a command you specify. The <code class="computeroutput">
597 notfile</code> rule allows you to run an arbitrary command,
598 without creating any files. And finaly, the <code class="computeroutput">generate
599 </code> rule allows you to describe a transformation using
600 Boost.Build's virtual targets. This is higher-level than the file names that
601 the <code class="computeroutput">make</code> rule operates with and allows you to
602 create more than one target, create differently named targets depending on
603 properties, or use more than one tool.
606 The <code class="computeroutput">make</code> rule is used when you want to create
607 one file from a number of sources using some specific command. The
608 <code class="computeroutput">notfile</code> is used to unconditionally run a
612 Suppose you want to create the file <code class="filename">file.out</code> from
613 the file <code class="filename">file.in</code> by running the command <span class="command"><strong>
614 in2out</strong></span>. Here is how you would do this in Boost.Build:
616 <pre class="programlisting">
617 make file.out : file.in : @in2out ;
620 in2out $(<) $(>)
624 If you run <span class="command"><strong>b2</strong></span> and <code class="filename">file.out</code> does
625 not exist, Boost.Build will run the <span class="command"><strong>in2out</strong></span> command to
626 create that file. For more details on specifying actions, see <a class="xref" href="overview.html#bbv2.overview.jam_language.actions">the section called “Boost.Jam Language”</a>.
629 It could be that you just want to run some command unconditionally, and
630 that command does not create any specific files. For that you can use the
631 <code class="computeroutput">notfile</code> rule. For example:
633 <pre class="programlisting">
634 notfile echo_something : @echo ;
641 The only difference from the <code class="computeroutput">make</code> rule is
642 that the name of the target is not considered a name of a file, so
643 Boost.Build will unconditionally run the action.
647 The <code class="computeroutput">generate</code> rule is used when you want to
648 express transformations using Boost.Build's virtual targets, as opposed to
649 just filenames. The <code class="computeroutput">generate</code> rule has the
650 standard main target rule signature, but you are required to specify the
651 <code class="literal">generating-rule</code> property. The value of the property
652 should be in the form <code class="literal">
653 @<em class="replaceable"><code>rule-name</code></em></code>, the named rule should
654 have the following signature:
656 <pre class="programlisting">
657 rule generating-rule ( project name : property-set : sources * )
660 and will be called with an instance of the <code class="computeroutput">project-target</code>
661 class, the name of the main target, an instance of the
662 <code class="computeroutput">property-set</code> class containing build properties, and the list
663 of instances of the <code class="computeroutput">virtual-target</code> class corresponding to
664 sources. The rule must return a list of <code class="computeroutput">virtual-target</code>
665 instances. The interface of the <code class="computeroutput">virtual-target</code> class can be
666 learned by looking at the <code class="filename">build/virtual-target.jam</code>
667 file. The <code class="filename">generate</code> example contained in the
668 Boost.Build distribution illustrates how the <code class="literal">generate</code>
672 <div class="section">
673 <div class="titlepage"><div><div><h3 class="title">
674 <a name="bbv2.reference.precompiled_headers"></a>Precompiled Headers</h3></div></div></div>
676 Precompiled headers is a mechanism to speed up compilation by creating a
677 partially processed version of some header files, and then using that
678 version during compilations rather then repeatedly parsing the original
679 headers. Boost.Build supports precompiled headers with gcc and msvc
683 To use precompiled headers, follow the following steps:
685 <div class="orderedlist"><ol class="orderedlist" type="1">
686 <li class="listitem"><p>
687 Create a header that includes headers used by your project that you
688 want precompiled. It is better to include only headers that are
689 sufficiently stable — like headers from the compiler and
690 external libraries. Please wrap the header in <code class="computeroutput">#ifdef
691 BOOST_BUILD_PCH_ENABLED</code>, so that the potentially expensive
692 inclusion of headers is not done when PCH is not enabled. Include the
693 new header at the top of your source files.
695 <li class="listitem">
697 Declare a new Boost.Build target for the precompiled header and add
698 that precompiled header to the sources of the target whose compilation
699 you want to speed up:
701 <pre class="programlisting">
702 cpp-pch pch : pch.hpp ;
703 exe main : main.cpp pch ;
706 You can use the <code class="computeroutput">c-pch</code> rule if you want to
707 use the precompiled header in C programs.
712 The <code class="filename">pch</code> example in Boost.Build distribution can be
716 Please note the following:
718 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
719 <li class="listitem"><p>
720 The inclusion of the precompiled header must be the first thing in a
721 source file, before any code or preprocessor directives.
723 <li class="listitem"><p>
724 The build properties used to compile the source files and the
725 precompiled header must be the same. Consider using project
726 requirements to assure this.
728 <li class="listitem"><p>
729 Precompiled headers must be used purely as a way to improve
730 compilation time, not to save the number of <code class="computeroutput">#include</code>
731 statements. If a source file needs to include some header, explicitly
732 include it in the source file, even if the same header is included
733 from the precompiled header. This makes sure that your project will
734 build even if precompiled headers are not supported.
736 <li class="listitem"><p>
737 On the gcc compiler, the name of the header being precompiled must be
738 equal to the name of the <code class="computeroutput">cpp-pch</code> target. This is a gcc
741 <li class="listitem"><p>
742 Prior to version 4.2, the gcc compiler did not allow anonymous
743 namespaces in precompiled headers, which limits their utility. See the
744 <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29085" target="_top"> bug
745 report</a> for details.
749 <div class="section">
750 <div class="titlepage"><div><div><h3 class="title">
751 <a name="bbv2.reference.generated_headers"></a>Generated headers</h3></div></div></div>
753 Usually, Boost.Build handles implicit dependendies completely
754 automatically. For example, for C++ files, all <code class="literal">#include</code>
755 statements are found and handled. The only aspect where user help might be
756 needed is implicit dependency on generated files.
759 By default, Boost.Build handles such dependencies within one main target.
760 For example, assume that main target "app" has two sources, "app.cpp" and
761 "parser.y". The latter source is converted into "parser.c" and "parser.h".
762 Then, if "app.cpp" includes "parser.h", Boost.Build will detect this
763 dependency. Moreover, since "parser.h" will be generated into a build
764 directory, the path to that directory will automatically be added to the include
768 Making this mechanism work across main target boundaries is possible, but
769 imposes certain overhead. For that reason, if there is implicit dependency
770 on files from other main targets, the <code class="literal"><implicit-dependency>
771 </code> feature must be used, for example:
773 <pre class="programlisting">
774 lib parser : parser.y ;
775 exe app : app.cpp : <implicit-dependency>parser ;
778 The above example tells the build system that when scanning all sources of
779 "app" for implicit-dependencies, it should consider targets from "parser"
780 as potential dependencies.
783 <div class="section">
784 <div class="titlepage"><div><div><h3 class="title">
785 <a name="bbv2.tasks.crosscompile"></a>Cross-compilation</h3></div></div></div>
786 <a class="indexterm" name="idp637253296"></a><p>Boost.Build supports cross compilation with the gcc and msvc
789 When using gcc, you first need to specify your cross compiler
790 in <code class="filename">user-config.jam</code> (see <a class="xref" href="overview.html#bbv2.overview.configuration" title="Configuration">the section called “Configuration”</a>),
792 <pre class="programlisting">
793 using gcc : arm : arm-none-linux-gnueabi-g++ ;
796 After that, if the host and target os are the same, for example Linux, you can
797 just request that this compiler version be used:
803 If you want to target a different operating system from the host, you need
804 to additionally specify the value for the <code class="computeroutput">target-os</code> feature, for
809 b2 toolset=gcc-arm <span class="bold"><strong>target-os=linux</strong></span>
811 b2 toolset=gcc-mingw <span class="bold"><strong>target-os=windows</strong></span>
814 For the complete list of allowed opeating system names, please see the documentation for
815 <a class="link" href="reference.html#bbv2.reference.features.target-os">target-os feature</a>.
818 When using the msvc compiler, it's only possible to cross-compile to a 64-bit system
819 on a 32-bit host. Please see <a class="xref" href="reference.html#v2.reference.tools.compiler.msvc.64" title="64-bit support">the section called “64-bit support”</a> for
823 <div class="footnotes">
824 <br><hr style="width:100; text-align:left;margin-left: 0">
825 <div id="ftn.idp637139920" class="footnote"><p><a href="#idp637139920" class="para"><sup class="para">[18] </sup></a>see the definition of "free" in <a class="xref" href="reference.html#bbv2.reference.features.attributes" title="Feature Attributes">the section called “Feature Attributes”</a>.</p></div>
828 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
829 <td align="left"></td>
830 <td align="right"><div class="copyright-footer"></div></td>
833 <div class="spirit-nav">
834 <a accesskey="p" href="overview.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../bbv2.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>