cmake-developer.7.rst 18 KB

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