properties.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  4. <title>Properties</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="../tutorial.html" title="Chapter 23. Tutorial">
  19. <link rel="next" href="hierarchy.html" title="Project Hierarchies">
  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="../tutorial.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="hierarchy.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.properties"></a>Properties</h2></div></div></div>
  37. <div class="toc"><dl>
  38. <dt><span class="section"><a href="properties.html#bbv2.tutorial.properties.requirements">Build Requests and Target Requirements</a></span></dt>
  39. <dt><span class="section"><a href="properties.html#bbv2.tutorial.properties.project_attributes">Project Attributes</a></span></dt>
  40. </dl></div>
  41. <p>
  42. To portably represent aspects of target configuration such as
  43. debug and release variants, or single- and multi-threaded
  44. builds, Boost.Build uses <em class="firstterm">features</em> with
  45. associated <em class="firstterm">values</em>. For
  46. example, the <code class="computeroutput">debug-symbols</code> feature can have a value of <code class="computeroutput">on</code> or
  47. <code class="computeroutput">off</code>. A <em class="firstterm">property</em> is just a (feature,
  48. value) pair. When a user initiates a build, Boost.Build
  49. automatically translates the requested properties into appropriate
  50. command-line flags for invoking toolset components like compilers
  51. and linkers.</p>
  52. <p>There are many built-in features that can be combined to
  53. produce arbitrary build configurations. The following command
  54. builds the project's <code class="computeroutput">release</code> variant with inlining
  55. disabled and debug symbols enabled:
  56. </p>
  57. <pre class="screen">
  58. bjam release inlining=off debug-symbols=on
  59. </pre>
  60. <p>Properties on the command-line are specified with the syntax:
  61. </p>
  62. <pre class="screen"><em class="replaceable"><code>feature-name</code></em>=<em class="replaceable"><code>feature-value</code></em></pre>
  63. <p>The <code class="option">release</code> and <code class="option">debug</code> that we've seen
  64. in <span><strong class="command">bjam</strong></span> invocations are just a shorthand way to
  65. specify values of the <code class="varname">variant</code> feature. For example, the command
  66. above could also have been written this way:
  67. </p>
  68. <pre class="screen">
  69. bjam variant=release inlining=off debug-symbols=on
  70. </pre>
  71. <p><code class="varname">variant</code> is so commonly-used that it has
  72. been given special status as an <em class="firstterm">implicit</em>
  73. feature&#8212;Boost.Build will deduce the its identity just
  74. from the name of one of its values.
  75. </p>
  76. <p>
  77. A complete description of features can be found in <a href="../reference/definitions.html#bbv2.reference.features" title="Features and properties">the section called &#8220;Features and properties&#8221;</a>.
  78. </p>
  79. <div class="section" lang="en">
  80. <div class="titlepage"><div><div><h3 class="title">
  81. <a name="bbv2.tutorial.properties.requirements"></a>Build Requests and Target Requirements</h3></div></div></div>
  82. <p>
  83. The set of properties specified on the command line constitute
  84. a <em class="firstterm">build request</em>&#8212;a description of
  85. the desired properties for building the requested targets (or,
  86. if no targets were explicitly requested, the project in the
  87. current directory). The <span class="emphasis"><em>actual</em></span>
  88. properties used for building targets are typically a
  89. combination of the build request and properties derived from
  90. the project's <code class="filename">Jamroot</code> (and its other
  91. Jamfiles, as described in <a href="hierarchy.html" title="Project Hierarchies">the section called &#8220;Project Hierarchies&#8221;</a>). For example, the
  92. locations of <code class="computeroutput">#include</code>d header files are normally
  93. not specified on the command-line, but described in
  94. Jamfiles as <em class="firstterm">target
  95. requirements</em> and automatically combined with the
  96. build request for those targets. Multithread-enabled
  97. compilation is another example of a typical target
  98. requirement. The Jamfile fragment below
  99. illustrates how these requirements might be specified.
  100. </p>
  101. <pre class="programlisting">
  102. exe hello
  103. : hello.cpp
  104. : &lt;include&gt;boost &lt;threading&gt;multi
  105. ;
  106. </pre>
  107. <p>
  108. When <code class="filename">hello</code> is built, the two
  109. requirements specified above will always be present.
  110. If the build request given on the <span><strong class="command">bjam</strong></span>
  111. command-line explictly contradicts a target's requirements,
  112. the target requirements usually override (or, in the case of
  113. &#8220;free&#8221; features like
  114. <code class="varname">&lt;include&gt;</code>,
  115. <sup>[<a name="id1701753" href="#ftn.id1701753">4</a>]</sup>
  116. augments) the build request.
  117. </p>
  118. <div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
  119. <h3 class="title">Tip</h3>
  120. <p>The value of the <code class="varname">&lt;include&gt;</code> feature is
  121. relative to the location of <code class="filename">Jamroot</code> where it's
  122. used.
  123. </p>
  124. </div>
  125. </div>
  126. <div class="section" lang="en">
  127. <div class="titlepage"><div><div><h3 class="title">
  128. <a name="bbv2.tutorial.properties.project_attributes"></a>Project Attributes</h3></div></div></div>
  129. <p>
  130. If we want the same requirements for our other
  131. target, <code class="filename">hello2</code>, we could simply duplicate
  132. them. However, as projects grow, that approach leads to a great
  133. deal of repeated boilerplate in Jamfiles.
  134. Fortunately, there's a better way. Each project can specify a
  135. set of <em class="firstterm">attributes</em>, including
  136. requirements:
  137. </p>
  138. <pre class="programlisting">
  139. project
  140. : requirements &lt;include&gt;/home/ghost/Work/boost &lt;threading&gt;multi
  141. ;
  142. exe hello : hello.cpp ;
  143. exe hello2 : hello.cpp ;
  144. </pre>
  145. <p>
  146. The effect would be as if we specified the same requirement for
  147. both <code class="filename">hello</code> and <code class="filename">hello2</code>.
  148. </p>
  149. </div>
  150. <div class="footnotes">
  151. <br><hr width="100" align="left">
  152. <div class="footnote"><p><sup>[<a name="ftn.id1701753" href="#id1701753">4</a>] </sup>
  153. See <a href="../reference/definitions.html#bbv2.reference.features.attributes" title="Feature Attributes">the section called &#8220;Feature Attributes&#8221;</a></p></div>
  154. </div>
  155. </div>
  156. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  157. <td align="left"></td>
  158. <td align="right"><small></small></td>
  159. </tr></table>
  160. <hr>
  161. <div class="spirit-nav">
  162. <a accesskey="p" href="../tutorial.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="hierarchy.html"><img src="../../images/next.png" alt="Next"></a>
  163. </div>
  164. </body>
  165. </html>
粤ICP备19079148号