cmake-developer.7.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. cmake-developer(7)
  2. ******************
  3. .. only:: html or latex
  4. .. contents::
  5. Introduction
  6. ============
  7. This manual is intended for reference by developers modifying the CMake
  8. source tree itself.
  9. Help
  10. ====
  11. The ``Help`` directory contains CMake help manual source files.
  12. They are written using the `reStructuredText`_ markup syntax and
  13. processed by `Sphinx`_ to generate the CMake help manuals.
  14. .. _`reStructuredText`: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
  15. .. _`Sphinx`: http://sphinx-doc.org
  16. Markup Constructs
  17. -----------------
  18. In addition to using Sphinx to generate the CMake help manuals, we
  19. also use a C++-implemented document processor to print documents for
  20. the ``--help-*`` command-line help options. It supports a subset of
  21. reStructuredText markup. When authoring or modifying documents,
  22. please verify that the command-line help looks good in addition to the
  23. Sphinx-generated html and man pages.
  24. The command-line help processor supports the following constructs
  25. defined by reStructuredText, Sphinx, and a CMake extension to Sphinx.
  26. ..
  27. Note: This list must be kept consistent with the cmRST implementation.
  28. CMake Domain directives
  29. Directives defined in the `CMake Domain`_ for defining CMake
  30. documentation objects are printed in command-line help output as
  31. if the lines were normal paragraph text with interpretation.
  32. CMake Domain interpreted text roles
  33. Interpreted text roles defined in the `CMake Domain`_ for
  34. cross-referencing CMake documentation objects are replaced by their
  35. link text in command-line help output. Other roles are printed
  36. literally and not processed.
  37. ``code-block`` directive
  38. Add a literal code block without interpretation. The command-line
  39. help processor prints the block content without the leading directive
  40. line and with common indentation replaced by one space.
  41. ``include`` directive
  42. Include another document source file. The command-line help
  43. processor prints the included document inline with the referencing
  44. document.
  45. literal block after ``::``
  46. A paragraph ending in ``::`` followed by a blank line treats
  47. the following indented block as literal text without interpretation.
  48. The command-line help processor prints the ``::`` literally and
  49. prints the block content with common indentation replaced by one
  50. space. We prefer the ``::`` to appear at the end of a paragraph
  51. line instead of as its own line.
  52. ``parsed-literal`` directive
  53. Add a literal block with markup interpretation. The command-line
  54. help processor prints the block content without the leading
  55. directive line and with common indentation replaced by one space.
  56. ``replace`` directive
  57. Define a ``|substitution|`` replacement.
  58. The command-line help processor requires a substitution replacement
  59. to be defined before it is referenced.
  60. ``|substitution|`` reference
  61. Reference a substitution replacement previously defined by
  62. the ``replace`` directive. The command-line help processor
  63. performs the substitution and replaces all newlines in the
  64. replacement text with spaces.
  65. ``toctree`` directive
  66. Include other document sources in the Table-of-Contents
  67. document tree. The command-line help processor prints
  68. the referenced documents inline as part of the referencing
  69. document.
  70. Inline markup constructs not listed above are printed literally in the
  71. command-line help output. We prefer to use inline markup constructs that
  72. look correct in source form, so avoid use of \\-escapes in favor of inline
  73. literals when possible.
  74. Explicit markup blocks not matching directives listed above are removed from
  75. command-line help output. Do not use them, except for plain ``..`` comments
  76. that are removed by Sphinx too.
  77. Note that nested indentation of blocks is not recognized by the
  78. command-line help processor. Therefore:
  79. * Explicit markup blocks are recognized only when not indented
  80. inside other blocks.
  81. * Literal blocks after paragraphs ending in ``::`` but not
  82. at the top indentation level may consume all indented lines
  83. following them.
  84. Try to avoid these cases in practice.
  85. CMake Domain
  86. ------------
  87. CMake adds a `Sphinx Domain`_ called ``cmake``, also called the
  88. "CMake Domain". It defines several "object" types for CMake
  89. documentation:
  90. ``command``
  91. A CMake language command.
  92. ``generator``
  93. A CMake native build system generator.
  94. See the :manual:`cmake(1)` command-line tool's ``-G`` option.
  95. ``manual``
  96. A CMake manual page, like this :manual:`cmake-developer(7)` manual.
  97. ``module``
  98. A CMake module.
  99. See the :manual:`cmake-modules(7)` manual
  100. and the :command:`include` command.
  101. ``policy``
  102. A CMake policy.
  103. See the :manual:`cmake-policies(7)` manual
  104. and the :command:`cmake_policy` command.
  105. ``prop_cache, prop_dir, prop_gbl, prop_sf, prop_test, prop_tgt``
  106. A CMake cache, directory, global, source file, test, or target
  107. property, respectively. See the :manual:`cmake-properties(7)` manual
  108. and the :command:`set_property` command.
  109. ``variable``
  110. A CMake language variable.
  111. See the :manual:`cmake-variables(7)` manual
  112. and the :command:`set` command.
  113. Documentation objects in the CMake Domain come from two sources.
  114. First, the CMake extension to Sphinx transforms every document named
  115. with the form ``Help/<type>/<file-name>.rst`` to a domain object with
  116. type ``<type>``. The object name is extracted from the document title,
  117. which is expected to be of the form::
  118. <object-name>
  119. -------------
  120. and to appear at or near the top of the ``.rst`` file before any other
  121. lines starting in a letter, digit, or ``<``. If no such title appears
  122. literally in the ``.rst`` file, the object name is the ``<file-name>``.
  123. If a title does appear, it is expected that ``<file-name>`` is equal
  124. to ``<object-name>`` with any ``<`` and ``>`` characters removed.
  125. Second, the CMake Domain provides directives to define objects inside
  126. other documents:
  127. .. code-block:: rst
  128. .. command:: <command-name>
  129. This indented block documents <command-name>.
  130. .. variable:: <variable-name>
  131. This indented block documents <variable-name>.
  132. Object types for which no directive is available must be defined using
  133. the first approach above.
  134. .. _`Sphinx Domain`: http://sphinx-doc.org/domains.html
  135. Cross-References
  136. ----------------
  137. Sphinx uses reStructuredText interpreted text roles to provide
  138. cross-reference syntax. The `CMake Domain`_ provides for each
  139. domain object type a role of the same name to cross-reference it.
  140. CMake Domain roles are inline markup of the forms::
  141. :type:`name`
  142. :type:`text <name>`
  143. where ``type`` is the domain object type and ``name`` is the
  144. domain object name. In the first form the link text will be
  145. ``name`` (or ``name()`` if the type is ``command``) and in
  146. the second form the link text will be the explicit ``text``.
  147. For example, the code:
  148. .. code-block:: rst
  149. * The :command:`list` command.
  150. * The :command:`list(APPEND)` sub-command.
  151. * The :command:`list() command <list>`.
  152. * The :command:`list(APPEND) sub-command <list>`.
  153. * The :variable:`CMAKE_VERSION` variable.
  154. * The :prop_tgt:`OUTPUT_NAME_<CONFIG>` target property.
  155. produces:
  156. * The :command:`list` command.
  157. * The :command:`list(APPEND)` sub-command.
  158. * The :command:`list() command <list>`.
  159. * The :command:`list(APPEND) sub-command <list>`.
  160. * The :variable:`CMAKE_VERSION` variable.
  161. * The :prop_tgt:`OUTPUT_NAME_<CONFIG>` target property.
  162. Note that CMake Domain roles differ from Sphinx and reStructuredText
  163. convention in that the form ``a<b>``, without a space preceding ``<``,
  164. is interpreted as a name instead of link text with an explicit target.
  165. This is necessary because we use ``<placeholders>`` frequently in
  166. object names like ``OUTPUT_NAME_<CONFIG>``. The form ``a <b>``,
  167. with a space preceding ``<``, is still interpreted as a link text
  168. with an explicit target.
  169. Modules
  170. =======
  171. The ``Modules`` directory contains CMake-language ``.cmake`` module files.
  172. Module Documentation
  173. --------------------
  174. To add a module to the CMake documentation, follow these steps:
  175. 1. Add file ``Help/module/<module-name>.rst`` containing just the line::
  176. .. cmake-module:: ../../Modules/<module-name>.cmake
  177. 2. Modify ``Help/manual/cmake-modules.7.rst`` to reference the module in the
  178. toctree directive as::
  179. /module/<module-name>
  180. Keep the toctree in sorted order!
  181. 3. Add to the top of ``Modules/<module-name>.cmake`` a #-comment of the form::
  182. #.rst:
  183. # <module-name>
  184. # -------------
  185. #
  186. # ...reStructuredText documentation of module...
  187. Comment blocks starting with the line ``#.rst:`` may appear anywhere
  188. in the file. The ``cmake-module`` directive used above will scan the
  189. file to extract reStructuredText markup from such comments.
  190. For example, a ``Modules/Findxxx.cmake`` module may contain:
  191. .. code-block:: cmake
  192. #.rst:
  193. # FindXxx
  194. # -------
  195. #
  196. # This is a cool module.
  197. # This module does really cool stuff.
  198. # It can do even more than you think.
  199. #
  200. # It even needs two paragraphs to tell you about it.
  201. # And it defines the following variables:
  202. #
  203. # * VAR_COOL: this is great isn't it?
  204. # * VAR_REALLY_COOL: cool right?
  205. <code>
  206. #.rst:
  207. # .. command:: xxx_do_something
  208. #
  209. # This command does something for Xxx::
  210. #
  211. # xxx_do_something(some arguments)
  212. macro(xxx_do_something)
  213. <code>
  214. endmacro()
  215. Find Modules
  216. ------------
  217. A "find module" is a ``Modules/Find<package>.cmake`` file to be loaded
  218. by the :command:`find_package` command when invoked for ``<package>``.
  219. We would like all ``FindXxx.cmake`` files to produce consistent variable
  220. names. Please use the following consistent variable names for general use.
  221. Xxx_INCLUDE_DIRS
  222. The final set of include directories listed in one variable for use by client
  223. code. This should not be a cache entry.
  224. Xxx_LIBRARIES
  225. The libraries to link against to use Xxx. These should include full paths.
  226. This should not be a cache entry.
  227. Xxx_DEFINITIONS
  228. Definitions to use when compiling code that uses Xxx. This really shouldn't
  229. include options such as (-DHAS_JPEG)that a client source-code file uses to
  230. decide whether to #include <jpeg.h>
  231. Xxx_EXECUTABLE
  232. Where to find the Xxx tool.
  233. Xxx_Yyy_EXECUTABLE
  234. Where to find the Yyy tool that comes with Xxx.
  235. Xxx_LIBRARY_DIRS
  236. Optionally, the final set of library directories listed in one variable for
  237. use by client code. This should not be a cache entry.
  238. Xxx_ROOT_DIR
  239. Where to find the base directory of Xxx.
  240. Xxx_VERSION_Yy
  241. Expect Version Yy if true. Make sure at most one of these is ever true.
  242. Xxx_WRAP_Yy
  243. If False, do not try to use the relevant CMake wrapping command.
  244. Xxx_Yy_FOUND
  245. If False, optional Yy part of Xxx sytem is not available.
  246. Xxx_FOUND
  247. Set to false, or undefined, if we haven't found, or don't want to use Xxx.
  248. Xxx_NOT_FOUND_MESSAGE
  249. Should be set by config-files in the case that it has set Xxx_FOUND to FALSE.
  250. The contained message will be printed by the find_package() command and by
  251. find_package_handle_standard_args() to inform the user about the problem.
  252. Xxx_RUNTIME_LIBRARY_DIRS
  253. Optionally, the runtime library search path for use when running an
  254. executable linked to shared libraries. The list should be used by user code
  255. to create the PATH on windows or LD_LIBRARY_PATH on unix. This should not be
  256. a cache entry.
  257. Xxx_VERSION_STRING
  258. A human-readable string containing the version of the package found, if any.
  259. Xxx_VERSION_MAJOR
  260. The major version of the package found, if any.
  261. Xxx_VERSION_MINOR
  262. The minor version of the package found, if any.
  263. Xxx_VERSION_PATCH
  264. The patch version of the package found, if any.
  265. You do not have to provide all of the above variables. You should provide
  266. Xxx_FOUND under most circumstances. If Xxx is a library, then Xxx_LIBRARIES,
  267. should also be defined, and Xxx_INCLUDE_DIRS should usually be defined (I
  268. guess libm.a might be an exception)
  269. The following names should not usually be used in CMakeLists.txt files, but
  270. they may be usefully modified in users' CMake Caches to control stuff.
  271. Xxx_LIBRARY
  272. Name of Xxx Library. A User may set this and Xxx_INCLUDE_DIR to ignore to
  273. force non-use of Xxx.
  274. Xxx_Yy_LIBRARY
  275. Name of Yy library that is part of the Xxx system. It may or may not be
  276. required to use Xxx.
  277. Xxx_INCLUDE_DIR
  278. Where to find xxx.h, etc. (Xxx_INCLUDE_PATH was considered bad because a path
  279. includes an actual filename.)
  280. Xxx_Yy_INCLUDE_DIR
  281. Where to find xxx_yy.h, etc.
  282. For tidiness's sake, try to keep as many options as possible out of the cache,
  283. leaving at least one option which can be used to disable use of the module, or
  284. locate a not-found library (e.g. Xxx_ROOT_DIR). For the same reason, mark
  285. most cache options as advanced.
  286. If you need other commands to do special things then it should still begin
  287. with ``Xxx_``. This gives a sort of namespace effect and keeps things tidy for the
  288. user. You should put comments describing all the exported settings, plus
  289. descriptions of any the users can use to control stuff.
  290. You really should also provide backwards compatibility any old settings that
  291. were actually in use. Make sure you comment them as deprecated, so that
  292. no-one starts using them.
  293. To add a module to the CMake documentation, follow the steps in the
  294. `Module Documentation`_ section above. Test the documentation formatting
  295. by running ``cmake --help-module FindXxx``, and also by enabling the
  296. ``SPHINX_HTML`` and ``SPHINX_MAN`` options to build the documentation.
  297. Edit the comments until generated documentation looks satisfactory.
  298. To have a .cmake file in this directory NOT show up in the modules
  299. documentation, simply leave out the ``Help/module/<module-name>.rst`` file
  300. and the ``Help/manual/cmake-modules.7.rst`` toctree entry.
  301. After the documentation, leave a *BLANK* line, and then add a
  302. copyright and licence notice block like this one::
  303. #=============================================================================
  304. # Copyright 2009-2011 Your Name
  305. #
  306. # Distributed under the OSI-approved BSD License (the "License");
  307. # see accompanying file Copyright.txt for details.
  308. #
  309. # This software is distributed WITHOUT ANY WARRANTY; without even the
  310. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  311. # See the License for more information.
  312. #=============================================================================
  313. # (To distribute this file outside of CMake, substitute the full
  314. # License text for the above reference.)
  315. The layout of the notice block is strictly enforced by the ``ModuleNotices``
  316. test. Only the year range and name may be changed freely.
  317. A FindXxx.cmake module will typically be loaded by the command::
  318. FIND_PACKAGE(Xxx [major[.minor[.patch[.tweak]]]] [EXACT]
  319. [QUIET] [[REQUIRED|COMPONENTS] [components...]])
  320. If any version numbers are given to the command it will set the following
  321. variables before loading the module:
  322. Xxx_FIND_VERSION
  323. full requested version string
  324. Xxx_FIND_VERSION_MAJOR
  325. major version if requested, else 0
  326. Xxx_FIND_VERSION_MINOR
  327. minor version if requested, else 0
  328. Xxx_FIND_VERSION_PATCH
  329. patch version if requested, else 0
  330. Xxx_FIND_VERSION_TWEAK
  331. tweak version if requested, else 0
  332. Xxx_FIND_VERSION_COUNT
  333. number of version components, 0 to 4
  334. Xxx_FIND_VERSION_EXACT
  335. true if EXACT option was given
  336. If the find module supports versioning it should locate a version of
  337. the package that is compatible with the version requested. If a
  338. compatible version of the package cannot be found the module should
  339. not report success. The version of the package found should be stored
  340. in "Xxx_VERSION..." version variables documented by the module.
  341. If the QUIET option is given to the command it will set the variable
  342. Xxx_FIND_QUIETLY to true before loading the FindXxx.cmake module. If
  343. this variable is set the module should not complain about not being
  344. able to find the package. If the
  345. REQUIRED option is given to the command it will set the variable
  346. Xxx_FIND_REQUIRED to true before loading the FindXxx.cmake module. If
  347. this variable is set the module should issue a FATAL_ERROR if the
  348. package cannot be found.
  349. If neither the QUIET nor REQUIRED options are given then the
  350. FindXxx.cmake module should look for the package and complain without
  351. error if the module is not found.
  352. FIND_PACKAGE() will set the variable CMAKE_FIND_PACKAGE_NAME to
  353. contain the actual name of the package.
  354. A package can provide sub-components.
  355. Those components can be listed after the COMPONENTS (or REQUIRED) or
  356. OPTIONAL_COMPONENTS keywords. The set of all listed components will be
  357. specified in a Xxx_FIND_COMPONENTS variable.
  358. For each package-specific component, say Yyy, a variable Xxx_FIND_REQUIRED_Yyy
  359. will be set to true if it listed after COMPONENTS and it will be set to false
  360. if it was listed after OPTIONAL_COMPONENTS.
  361. Using those variables a FindXxx.cmake module and also a XxxConfig.cmake
  362. package configuration file can determine whether and which components have
  363. been requested, and whether they were requested as required or as optional.
  364. For each of the requested components a Xxx_Yyy_FOUND variable should be set
  365. accordingly.
  366. The per-package Xxx_FOUND variable should be only set to true if all requested
  367. required components have been found. A missing optional component should not
  368. keep the Xxx_FOUND variable from being set to true.
  369. If the package provides Xxx_INCLUDE_DIRS and Xxx_LIBRARIES variables, the
  370. include dirs and libraries for all components which were requested and which
  371. have been found should be added to those two variables.
  372. To get this behaviour you can use the FIND_PACKAGE_HANDLE_STANDARD_ARGS()
  373. macro, as an example see FindJPEG.cmake.
  374. For internal implementation, it's a generally accepted convention that
  375. variables starting with underscore are for temporary use only. (variable
  376. starting with an underscore are not intended as a reserved prefix).