cmake-developer.7.rst 18 KB

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