1 | <html> |
---|
2 | <head> |
---|
3 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
---|
4 | <title>Conditions and alternatives</title> |
---|
5 | <link rel="stylesheet" href="../../boostbook.css" type="text/css"> |
---|
6 | <meta name="generator" content="DocBook XSL Stylesheets V1.69.1"> |
---|
7 | <style type="text/css"> |
---|
8 | body { background-image: url('http://docbook.sourceforge.net/release/images/draft.png'); |
---|
9 | background-repeat: no-repeat; |
---|
10 | background-position: top left; |
---|
11 | /* The following properties make the watermark "fixed" on the page. */ |
---|
12 | /* I think that's just a bit too distracting for the reader... */ |
---|
13 | /* background-attachment: fixed; */ |
---|
14 | /* background-position: center center; */ |
---|
15 | }</style> |
---|
16 | <link rel="start" href="../../index.html" title="The Boost C++ Libraries"> |
---|
17 | <link rel="up" href="../tutorial.html" title="Chapter 23. Tutorial"> |
---|
18 | <link rel="prev" href="linkage.html" title="Static and shared libaries"> |
---|
19 | <link rel="next" href="prebuilt.html" title="Prebuilt targets"> |
---|
20 | </head> |
---|
21 | <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
---|
22 | <table cellpadding="2" width="100%"> |
---|
23 | <td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../../boost.png"></td> |
---|
24 | <td align="center"><a href="../../../../index.htm">Home</a></td> |
---|
25 | <td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td> |
---|
26 | <td align="center"><a href="../../../../people/people.htm">People</a></td> |
---|
27 | <td align="center"><a href="../../../../more/faq.htm">FAQ</a></td> |
---|
28 | <td align="center"><a href="../../../../more/index.htm">More</a></td> |
---|
29 | </table> |
---|
30 | <hr> |
---|
31 | <div class="spirit-nav"> |
---|
32 | <a accesskey="p" href="linkage.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="prebuilt.html"><img src="../../images/next.png" alt="Next"></a> |
---|
33 | </div> |
---|
34 | <div class="section" lang="en"> |
---|
35 | <div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
---|
36 | <a name="bbv2.tutorial.conditions"></a>Conditions and alternatives</h2></div></div></div> |
---|
37 | <p>Sometimes, particular relationships need to be maintained |
---|
38 | among a target's build properties. This can be achieved with |
---|
39 | <em class="firstterm">conditional |
---|
40 | requirement</em>. For example, you might want to set |
---|
41 | specific <code class="computeroutput">#defines</code> when a library is built as shared, |
---|
42 | or when a target's <code class="computeroutput">release</code> variant is built in |
---|
43 | release mode. |
---|
44 | </p> |
---|
45 | <pre class="programlisting"> |
---|
46 | lib network : network.cpp |
---|
47 | : <span class="bold"><strong><link>shared:<define>NEWORK_LIB_SHARED</strong></span> |
---|
48 | <variant>release:<define>EXTRA_FAST |
---|
49 | ; |
---|
50 | </pre> |
---|
51 | <p> |
---|
52 | |
---|
53 | In the example above, whenever <code class="filename">network</code> is |
---|
54 | built with <code class="computeroutput"><link>shared</code>, |
---|
55 | <code class="computeroutput"><define>NEWORK_LIB_SHARED</code> will be in its |
---|
56 | properties, too. |
---|
57 | </p> |
---|
58 | <p> |
---|
59 | Sometimes the ways a target is built are so different that |
---|
60 | describing them using conditional requirements would be |
---|
61 | hard. For example, imagine that a library actually uses |
---|
62 | different source files depending on the toolset used to build |
---|
63 | it. We can express this situation using <em class="firstterm">target |
---|
64 | alternatives</em>: |
---|
65 | </p> |
---|
66 | <pre class="programlisting"> |
---|
67 | lib demangler : dummy_demangler.cpp ; # alternative 1 |
---|
68 | lib demangler : demangler_gcc.cpp : <toolset>gcc ; # alternative 2 |
---|
69 | lib demangler : demangler_msvc.cpp : <toolset>msvc ; # alternative 3 |
---|
70 | </pre> |
---|
71 | <p> |
---|
72 | In the example above, when built with <code class="literal">gcc</code> |
---|
73 | or <code class="literal">msvc</code>, <code class="filename">demangler</code> |
---|
74 | will use a source file specific to the toolset. Otherwise, it |
---|
75 | will use a generic source file, |
---|
76 | <code class="filename">dummy_demangler.cpp</code>. |
---|
77 | </p> |
---|
78 | </div> |
---|
79 | <table width="100%"><tr> |
---|
80 | <td align="left"></td> |
---|
81 | <td align="right"><small></small></td> |
---|
82 | </tr></table> |
---|
83 | <hr> |
---|
84 | <div class="spirit-nav"> |
---|
85 | <a accesskey="p" href="linkage.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="prebuilt.html"><img src="../../images/next.png" alt="Next"></a> |
---|
86 | </div> |
---|
87 | </body> |
---|
88 | </html> |
---|