| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Dependent Targets</title>
- <link rel="stylesheet" href="../../boostbook.css" type="text/css">
- <meta name="generator" content="DocBook XSL Stylesheets V1.68.1">
- <style type="text/css">
- body { background-image: url('http://docbook.sourceforge.net/release/images/draft.png');
- background-repeat: no-repeat;
- background-position: top left;
- /* The following properties make the watermark "fixed" on the page. */
- /* I think that's just a bit too distracting for the reader... */
- /* background-attachment: fixed; */
- /* background-position: center center; */
- }</style>
- <link rel="start" href="../../index.html" title="The Boost C++ Libraries">
- <link rel="up" href="../tutorial.html" title="Chapter 23. Tutorial">
- <link rel="prev" href="hierarchy.html" title="Project Hierarchies">
- <link rel="next" href="linkage.html" title="Static and shared libaries">
- </head>
- <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
- <table cellpadding="2" width="100%">
- <td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../boost.png"></td>
- <td align="center"><a href="../../../../index.htm">Home</a></td>
- <td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
- <td align="center"><a href="../../../../people/people.htm">People</a></td>
- <td align="center"><a href="../../../../more/faq.htm">FAQ</a></td>
- <td align="center"><a href="../../../../more/index.htm">More</a></td>
- </table>
- <hr>
- <div class="spirit-nav">
- <a accesskey="p" href="hierarchy.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorial.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="linkage.html"><img src="../../images/next.png" alt="Next"></a>
- </div>
- <div class="section" lang="en">
- <div class="titlepage"><div><div><h2 class="title" style="clear: both">
- <a name="bbv2.tutorial.libs"></a>Dependent Targets</h2></div></div></div>
- <p>
- Targets that are “needed” by other targets are called
- <em class="firstterm">dependencies</em> of those other targets. The
- targets that need the other targets are called
- <em class="firstterm">dependent</em> targets.
- </p>
- <p>To get a feeling of target dependencies, let's continue the
- above example and see how <code class="filename">top/app/Jamfile</code> can
- use libraries from <code class="filename">top/util/foo</code>. If
- <code class="filename">top/util/foo/Jamfile</code> contains
- </p>
- <pre class="programlisting">
- lib bar : bar.cpp ;
- </pre>
- <p>
- then to use this library in <code class="filename">top/app/Jamfile</code>, we can
- write:
- </p>
- <pre class="programlisting">
- exe app : app.cpp ../util/foo//bar ;
- </pre>
- <p>
- While <code class="computeroutput">app.cpp</code> refers to a regular source file,
- <code class="computeroutput">../util/foo//bar</code> is a reference to another target:
- a library <code class="filename">bar</code> declared in the Jamfile at
- <code class="filename">../util/foo</code>.
- </p>
- <div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
- <h3 class="title">Tip</h3>
- <p>Some other build system have special syntax for listing dependent
- libraries, for example <code class="varname">LIBS</code> variable. In Boost.Build,
- you just add the library to the list of sources.
- </p>
- </div>
- <p>Suppose we build <code class="filename">app</code> with:
- </p>
- <pre class="screen">
- bjam app optimization=full define=USE_ASM
- </pre>
- <p>
- Which properties will be used to build <code class="computeroutput">foo</code>? The answer is
- that some features are
- <em class="firstterm">propagated</em>—Boost.Build attempts to use
- dependencies with the same value of propagated features. The
- <code class="varname"><optimization></code> feature is propagated, so both
- <code class="filename">app</code> and <code class="filename">foo</code> will be compiled
- with full optimization. But <code class="varname"><define></code> is not
- propagated: its value will be added as-is to the compiler flags for
- <code class="filename">a.cpp</code>, but won't affect <code class="filename">foo</code>.
- </p>
- <p>Let's improve this project further.
- The library
- probably has some headers that must be used when compiling
- <code class="filename">app.cpp</code>. We could manually add the necessary
- <code class="computeroutput">#include</code> paths to <code class="filename">app</code>'s
- requirements as values of the
- <code class="varname"><include></code> feature, but then this work will
- be repeated for all programs
- that use <code class="filename">foo</code>. A better solution is to modify
- <code class="filename">util/foo/Jamfile</code> in this way:
- </p>
- <pre class="programlisting">
- project
- : usage-requirements <include>.
- ;
- lib foo : foo.cpp ;
- </pre>
- <p>
- Usage requirements are applied not to the target being declared
- but to its
- dependents. In this case, <code class="literal"><include>.</code> will be applied to all
- targets that directly depend on <code class="filename">foo</code>.
- </p>
- <p>Another improvement is using symbolic identifiers to refer to
- the library, as opposed to <code class="filename">Jamfile</code> location.
- In a large project, a library can be used by many targets, and if
- they all use <code class="filename">Jamfile</code> location,
- a change in directory organization entails much work.
- The solution is to use project ids—symbolic names
- not tied to directory layout. First, we need to assign a project id by
- adding this code to
- <code class="filename">Jamroot</code>:</p>
- <pre class="programlisting">
- use-project /library-example/foo : util/foo ;
- </pre>
- <p>Second, we modify <code class="filename">app/Jamfile</code> to use the
- project id:
- </p>
- <pre class="programlisting">
- exe app : app.cpp /library-example/foo//bar ;
- </pre>
- <p>
- The <code class="filename">/library-example/foo//bar</code> syntax is used
- to refer to the target <code class="filename">bar</code> in
- the project with id <code class="filename">/library-example/foo</code>.
- We've achieved our goal—if the library is moved to a different
- directory, only <code class="filename">Jamroot</code> must be modified.
- Note that project ids are global—two Jamfiles are not
- allowed to assign the same project id to different directories.
-
- </p>
- <div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
- <h3 class="title">Tip</h3>
- <p>If you want all applications in some project to link
- to a certain library, you can avoid having to specify it directly the sources of every
- target by using the
- <code class="varname"><source></code> property. For example, if <code class="filename">/boost/filesystem//fs</code>
- should be linked to all applications in your project, you can add
- <code class="computeroutput"><source>/boost/filesystem//fs</code> to the project's requirements, like this:</p>
- <pre class="programlisting">
- project
- : requirements <source>/boost/filesystem//fs
- ;
- </pre>
- </div>
- </div>
- <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
- <td align="left"></td>
- <td align="right"><small></small></td>
- </tr></table>
- <hr>
- <div class="spirit-nav">
- <a accesskey="p" href="hierarchy.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorial.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="linkage.html"><img src="../../images/next.png" alt="Next"></a>
- </div>
- </body>
- </html>
|