conditions.html 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.68.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>&lt;link&gt;shared:&lt;define&gt;NEWORK_LIB_SHARED</strong></span>
  48. &lt;variant&gt;release:&lt;define&gt;EXTRA_FAST
  49. ;
  50. </pre>
  51. <p>
  52. In the example above, whenever <code class="filename">network</code> is
  53. built with <code class="computeroutput">&lt;link&gt;shared</code>,
  54. <code class="computeroutput">&lt;define&gt;NEWORK_LIB_SHARED</code> will be in its
  55. properties, too.
  56. </p>
  57. <p>
  58. Sometimes the ways a target is built are so different that
  59. describing them using conditional requirements would be
  60. hard. For example, imagine that a library actually uses
  61. different source files depending on the toolset used to build
  62. it. We can express this situation using <em class="firstterm">target
  63. alternatives</em>:
  64. </p>
  65. <pre class="programlisting">
  66. lib demangler : dummy_demangler.cpp ; # alternative 1
  67. lib demangler : demangler_gcc.cpp : &lt;toolset&gt;gcc ; # alternative 2
  68. lib demangler : demangler_msvc.cpp : &lt;toolset&gt;msvc ; # alternative 3
  69. </pre>
  70. <p>
  71. In the example above, when built with <code class="literal">gcc</code>
  72. or <code class="literal">msvc</code>, <code class="filename">demangler</code>
  73. will use a source file specific to the toolset. Otherwise, it
  74. will use a generic source file,
  75. <code class="filename">dummy_demangler.cpp</code>.
  76. </p>
  77. </div>
  78. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  79. <td align="left"></td>
  80. <td align="right"><small></small></td>
  81. </tr></table>
  82. <hr>
  83. <div class="spirit-nav">
  84. <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>
  85. </div>
  86. </body>
  87. </html>
粤ICP备19079148号