documentation.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. CMake Documentation Guide
  2. *************************
  3. The following is a guide to the CMake documentation source for developers.
  4. See documentation on `CMake Development`_ for more information.
  5. .. _`CMake Development`: README.rst
  6. Help
  7. ====
  8. The ``Help`` directory contains CMake help manual source files.
  9. They are written using the `reStructuredText`_ markup syntax and
  10. processed by `Sphinx`_ to generate the CMake help manuals.
  11. .. _`reStructuredText`: https://docutils.sourceforge.net/docs/ref/rst/introduction.html
  12. .. _`Sphinx`: https://sphinx-doc.org
  13. Markup Constructs
  14. -----------------
  15. In addition to using Sphinx to generate the CMake help manuals, we
  16. also use a C++-implemented document processor to print documents for
  17. the ``--help-*`` command-line help options. It supports a subset of
  18. reStructuredText markup. When authoring or modifying documents,
  19. please verify that the command-line help looks good in addition to the
  20. Sphinx-generated html and man pages.
  21. The command-line help processor supports the following constructs
  22. defined by reStructuredText, Sphinx, and a CMake extension to Sphinx.
  23. ..
  24. Note: This list must be kept consistent with the cmRST implementation.
  25. CMake Domain directives
  26. Directives defined in the `CMake Domain`_ for defining CMake
  27. documentation objects are printed in command-line help output as
  28. if the lines were normal paragraph text with interpretation.
  29. CMake Domain interpreted text roles
  30. Interpreted text roles defined in the `CMake Domain`_ for
  31. cross-referencing CMake documentation objects are replaced by their
  32. link text in command-line help output. Other roles are printed
  33. literally and not processed.
  34. ``code-block`` directive
  35. Add a literal code block without interpretation. The command-line
  36. help processor prints the block content without the leading directive
  37. line and with common indentation replaced by one space.
  38. ``include`` directive
  39. Include another document source file. The command-line help
  40. processor prints the included document inline with the referencing
  41. document.
  42. literal block after ``::``
  43. A paragraph ending in ``::`` followed by a blank line treats
  44. the following indented block as literal text without interpretation.
  45. The command-line help processor prints the ``::`` literally and
  46. prints the block content with common indentation replaced by one
  47. space.
  48. ``note`` directive
  49. Call out a side note. The command-line help processor prints the
  50. block content as if the lines were normal paragraph text with
  51. interpretation.
  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. ``productionlist`` directive
  57. Render context-free grammar productions. The command-line help
  58. processor prints the block content as if the lines were normal
  59. paragraph text with interpretation.
  60. ``replace`` directive
  61. Define a ``|substitution|`` replacement.
  62. The command-line help processor requires a substitution replacement
  63. to be defined before it is referenced.
  64. ``|substitution|`` reference
  65. Reference a substitution replacement previously defined by
  66. the ``replace`` directive. The command-line help processor
  67. performs the substitution and replaces all newlines in the
  68. replacement text with spaces.
  69. ``toctree`` directive
  70. Include other document sources in the Table-of-Contents
  71. document tree. The command-line help processor prints
  72. the referenced documents inline as part of the referencing
  73. document.
  74. ``versionadded``, ``versionchanged`` directives
  75. Specify that something was added or changed by a named CMake version.
  76. The command-line help processor prints the block content as if the lines
  77. were normal paragraph text with interpretation.
  78. Inline markup constructs not listed above are printed literally in the
  79. command-line help output. We prefer to use inline markup constructs that
  80. look correct in source form, so avoid use of \\-escapes in favor of inline
  81. literals when possible.
  82. Explicit markup blocks not matching directives listed above are removed from
  83. command-line help output. Do not use them, except for plain ``..`` comments
  84. that are removed by Sphinx too.
  85. Note that nested indentation of blocks is not recognized by the
  86. command-line help processor. Therefore:
  87. * Explicit markup blocks are recognized only when not indented
  88. inside other blocks.
  89. * Literal blocks after paragraphs ending in ``::`` but not
  90. at the top indentation level may consume all indented lines
  91. following them.
  92. Try to avoid these cases in practice.
  93. CMake Domain
  94. ------------
  95. CMake adds a `Sphinx Domain`_ called ``cmake``, also called the
  96. "CMake Domain". It defines several "object" types for CMake
  97. documentation:
  98. ``command``
  99. A CMake language command.
  100. ``cpack_gen``
  101. A CPack package generator.
  102. See the `cpack(1)`_ command-line tool's ``-G`` option.
  103. ``envvar``
  104. An environment variable.
  105. See the `cmake-env-variables(7)`_ manual
  106. and the `set()`_ command.
  107. ``generator``
  108. A CMake native build system generator.
  109. See the `cmake(1)`_ command-line tool's ``-G`` option.
  110. ``genex``
  111. A CMake generator expression.
  112. See the `cmake-generator-expressions(7)`_ manual.
  113. ``manual``
  114. A CMake manual page, like the `cmake(1)`_ manual.
  115. ``module``
  116. A CMake module.
  117. See the `cmake-modules(7)`_ manual
  118. and the `include()`_ command.
  119. ``policy``
  120. A CMake policy.
  121. See the `cmake-policies(7)`_ manual
  122. and the `cmake_policy()`_ command.
  123. ``prop_cache, prop_dir, prop_gbl, prop_sf, prop_inst, prop_test, prop_tgt``
  124. A CMake cache, directory, global, source file, installed file, test,
  125. or target property, respectively. See the `cmake-properties(7)`_
  126. manual and the `set_property()`_ command.
  127. ``variable``
  128. A CMake language variable.
  129. See the `cmake-variables(7)`_ manual
  130. and the `set()`_ command.
  131. Documentation objects in the CMake Domain come from two sources:
  132. 1. The CMake extension to Sphinx transforms every document named
  133. with the form ``Help/<type>/<file-name>.rst`` to a domain object with
  134. type ``<type>``. The object name is extracted from the document title,
  135. which is expected to be of the form::
  136. <object-name>
  137. -------------
  138. and to appear at or near the top of the ``.rst`` file before any other lines
  139. starting in a letter, digit, ``<``, or ``$``. If no such title appears
  140. literally in the ``.rst`` file, the object name is the ``<file-name>``.
  141. If a title does appear, it is expected that ``<file-name>`` is equal
  142. to ``<object-name>`` with any ``<`` and ``>`` characters removed,
  143. or in the case of a ``$<genex-name>`` or ``$<genex-name:...>``, the
  144. ``genex-name``.
  145. 2. `CMake Domain directives`_ may be used in documents to explicitly define
  146. some object types:
  147. * `command directive`_
  148. * `envvar directive`_
  149. * `genex directive`_
  150. * `variable directive`_
  151. Object types for which no directive is available must be defined using
  152. the document transform above.
  153. CMake Domain Directives
  154. -----------------------
  155. The CMake Domain provides the following directives.
  156. ``command`` directive
  157. ^^^^^^^^^^^^^^^^^^^^^
  158. Document a "command" object:
  159. .. code-block:: rst
  160. .. command:: <command-name>
  161. This indented block documents <command-name>.
  162. The directive requires a single argument, the command name.
  163. ``envvar`` directive
  164. ^^^^^^^^^^^^^^^^^^^^
  165. Document an "envvar" object:
  166. .. code-block:: rst
  167. .. envvar:: <envvar-name>
  168. This indented block documents <envvar-name>.
  169. The directive requires a single argument, the environment variable name.
  170. ``genex`` directive
  171. ^^^^^^^^^^^^^^^^^^^
  172. Document a "genex" object:
  173. .. code-block:: rst
  174. .. genex:: <genex-name>
  175. This indented block documents <genex-name>.
  176. The directive requires a single argument, the generator expression name.
  177. The optional ``:target:`` option allows a custom target name to be specified.
  178. Because this will affect the ability to reference the "genex" object using the
  179. ``:genex:`` role, this option should be used very sparingly.
  180. ``signature`` directive
  181. ^^^^^^^^^^^^^^^^^^^^^^^
  182. Document `CMake Command Signatures <Style: CMake Command Signatures_>`_
  183. within a ``Help/command/<command-name>.rst`` document.
  184. .. code-block:: rst
  185. .. signature:: <command-name>(<signature>)
  186. This indented block documents one or more signatures of a CMake command.
  187. The ``signature`` directive requires one argument, the signature summary:
  188. * One or more signatures must immediately follow the ``::``.
  189. The first signature may optionally be placed on the same line.
  190. A blank line following the ``signature`` directive will result in a
  191. documentation generation error: ``1 argument(s) required, 0 supplied``.
  192. * Signatures may be split across multiple lines, but the final ``)`` of each
  193. signature must be the last character on its line.
  194. * Blank lines between signatures are not allowed. (Content after a blank line
  195. is treated as part of the description.)
  196. * Whitespace in signatures is not preserved. To document a complex signature,
  197. abbreviate it in the ``signature`` directive argument and specify the full
  198. signature in a ``code-block`` in the description.
  199. The ``signature`` directive generates a hyperlink target for each signature:
  200. * Default target names are automatically extracted from leading "keyword"
  201. arguments in the signatures, where a keyword is any sequence of
  202. non-space starting with a letter. For example, the signature
  203. ``string(REGEX REPLACE <match-regex> ...)`` generates the target
  204. ``REGEX REPLACE``, similar to ``.. _`REGEX REPLACE`:``.
  205. * Custom target names may be specified using a ``:target:`` option.
  206. For example:
  207. .. code-block:: rst
  208. .. signature::
  209. cmake_path(GET <path-var> ROOT_NAME <out-var>)
  210. cmake_path(GET <path-var> ROOT_PATH <out-var>)
  211. :target:
  212. GET ROOT_NAME
  213. GET ROOT_PATH
  214. Provide a custom target name for each signature, one per line.
  215. The first target may optionally be placed on the same line as ``:target:``.
  216. * If a target name is already in use earlier in the document, no hyperlink
  217. target will be generated.
  218. * The targets may be referenced from within the same document using
  219. ```REF`_`` or ```TEXT <REF_>`_`` syntax. Like reStructuredText section
  220. headers, the targets do not work with Sphinx ``:ref:`` syntax, however
  221. they can be globally referenced using e.g. ``:command:`string(APPEND)```.
  222. Although whitespace in the signature is not preserved, by default, line breaks
  223. are suppressed inside of square- or angle-brackets. This behavior can be
  224. controlled using the ``:break:`` option; note, however, that there is no way
  225. to *force* a line break. The default value is 'smart'. Allowable values are:
  226. ``all``
  227. Allow line breaks at any whitespace.
  228. ``smart`` (default)
  229. Allow line breaks at whitespace, except between matched square- or
  230. angle-brackets. For example, if a signature contains the text
  231. ``<input>... [OUTPUT_VARIABLE <out-var>]``, a line break would be allowed
  232. after ``<input>...`` but not between ``OUTPUT_VARIABLE`` and ``<out-var>``.
  233. ``verbatim``
  234. Allow line breaks only where the source document contains a newline.
  235. The directive treats its content as the documentation of the signature(s).
  236. Indent the signature documentation accordingly.
  237. ``variable`` directive
  238. ^^^^^^^^^^^^^^^^^^^^^^
  239. Document a "variable" object:
  240. .. code-block:: rst
  241. .. variable:: <variable-name>
  242. This indented block documents <variable-name>.
  243. The directive requires a single argument, the variable name.
  244. .. _`Sphinx Domain`: https://sphinx-doc.org/domains.html
  245. .. _`cmake(1)`: https://cmake.org/cmake/help/latest/manual/cmake.1.html
  246. .. _`cmake-env-variables(7)`: https://cmake.org/cmake/help/latest/manual/cmake-env-variables.7.html
  247. .. _`cmake-generator-expressions(7)`: https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
  248. .. _`cmake-modules(7)`: https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html
  249. .. _`cmake-policies(7)`: https://cmake.org/cmake/help/latest/manual/cmake-policies.7.html
  250. .. _`cmake-properties(7)`: https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html
  251. .. _`cmake-variables(7)`: https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html
  252. .. _`cmake_policy()`: https://cmake.org/cmake/help/latest/command/cmake_policy.html
  253. .. _`cpack(1)`: https://cmake.org/cmake/help/latest/manual/cpack.1.html
  254. .. _`include()`: https://cmake.org/cmake/help/latest/command/include.html
  255. .. _`set()`: https://cmake.org/cmake/help/latest/command/set.html
  256. .. _`set_property()`: https://cmake.org/cmake/help/latest/command/set_property.html
  257. Cross-References
  258. ----------------
  259. Sphinx uses reStructuredText interpreted text roles to provide
  260. cross-reference syntax. The `CMake Domain`_ provides for each
  261. domain object type a role of the same name to cross-reference it.
  262. CMake Domain roles are inline markup of the forms::
  263. :type:`name`
  264. :type:`text <name>`
  265. where ``type`` is the domain object type and ``name`` is the
  266. domain object name. In the first form the link text will be
  267. ``name`` (or ``name()`` if the type is ``command``) and in
  268. the second form the link text will be the explicit ``text``.
  269. For example, the code:
  270. .. code-block:: rst
  271. * The :command:`list` command.
  272. * The :command:`list(APPEND)` sub-command.
  273. * The :command:`list() command <list>`.
  274. * The :command:`list(APPEND) sub-command <list>`.
  275. * The :variable:`CMAKE_VERSION` variable.
  276. * The :prop_tgt:`OUTPUT_NAME_<CONFIG>` target property.
  277. produces:
  278. * The `list()`_ command.
  279. * The `list(APPEND)`_ sub-command.
  280. * The `list() command`_.
  281. * The `list(APPEND) sub-command`_.
  282. * The `CMAKE_VERSION`_ variable.
  283. * The `OUTPUT_NAME_<CONFIG>`_ target property.
  284. Note that CMake Domain roles differ from Sphinx and reStructuredText
  285. convention in that the form ``a<b>``, without a space preceding ``<``,
  286. is interpreted as a name instead of link text with an explicit target.
  287. This is necessary because we use ``<placeholders>`` frequently in
  288. object names like ``OUTPUT_NAME_<CONFIG>``. The form ``a <b>``,
  289. with a space preceding ``<``, is still interpreted as a link text
  290. with an explicit target.
  291. Additionally, the ``cref`` role may be used to create references
  292. to local targets that have literal styling. This is especially
  293. useful for referencing a subcommand in the command's documentation.
  294. .. _`list()`: https://cmake.org/cmake/help/latest/command/list.html
  295. .. _`list(APPEND)`: https://cmake.org/cmake/help/latest/command/list.html
  296. .. _`list(APPEND) sub-command`: https://cmake.org/cmake/help/latest/command/list.html
  297. .. _`list() command`: https://cmake.org/cmake/help/latest/command/list.html
  298. .. _`CMAKE_VERSION`: https://cmake.org/cmake/help/latest/variable/CMAKE_VERSION.html
  299. .. _`OUTPUT_NAME_<CONFIG>`: https://cmake.org/cmake/help/latest/prop_tgt/OUTPUT_NAME_CONFIG.html
  300. Style
  301. -----
  302. Style: Section Headers
  303. ^^^^^^^^^^^^^^^^^^^^^^
  304. When marking section titles, make the section decoration line as long as
  305. the title text. Use only a line below the title, not above. For
  306. example:
  307. .. code-block:: rst
  308. Title Text
  309. ----------
  310. Capitalize the first letter of each non-minor word in the title.
  311. The section header underline character hierarchy is
  312. * ``#``: Manual group (part) in the master document
  313. * ``*``: Manual (chapter) title
  314. * ``=``: Section within a manual
  315. * ``-``: Subsection or `CMake Domain`_ object document title
  316. * ``^``: Subsubsection or `CMake Domain`_ object document section
  317. * ``"``: Paragraph or `CMake Domain`_ object document subsection
  318. * ``~``: `CMake Domain`_ object document subsubsection
  319. Style: Whitespace
  320. ^^^^^^^^^^^^^^^^^
  321. Use two spaces for indentation. Use two spaces between sentences in
  322. prose.
  323. Style: Line Length
  324. ^^^^^^^^^^^^^^^^^^
  325. Prefer to restrict the width of lines to 75-80 columns. This is not a
  326. hard restriction, but writing new paragraphs wrapped at 75 columns
  327. allows space for adding minor content without significant re-wrapping of
  328. content.
  329. Style: Prose
  330. ^^^^^^^^^^^^
  331. Use American English spellings in prose.
  332. Style: Starting Literal Blocks
  333. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  334. Prefer to mark the start of literal blocks with ``::`` at the end of
  335. the preceding paragraph. In cases where the following block gets
  336. a ``code-block`` marker, put a single ``:`` at the end of the preceding
  337. paragraph.
  338. Style: CMake Command Signatures
  339. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  340. A ``Help/command/<command-name>.rst`` document defines one ``command``
  341. object in the `CMake Domain`_, but some commands have multiple signatures.
  342. Use the CMake Domain's `signature directive`_ to document each signature.
  343. Separate signatures from preceding content by a section header.
  344. For example:
  345. .. code-block:: rst
  346. ... preceding paragraph.
  347. Normal Libraries
  348. ^^^^^^^^^^^^^^^^
  349. .. signature::
  350. add_library(<lib> ...)
  351. This signature is used for ...
  352. Use the following conventions in command signature documentation:
  353. * Use an angle-bracket ``<placeholder>`` for arguments to be specified
  354. by the caller. Refer to them in prose using
  355. `inline literal <Style: Inline Literals_>`_ syntax.
  356. * Wrap optional parts with square brackets.
  357. * Mark repeatable parts with a trailing ellipsis (``...``).
  358. The ``signature`` directive may be used multiple times for different
  359. signatures of the same command.
  360. Style: Boolean Constants
  361. ^^^^^^^^^^^^^^^^^^^^^^^^
  362. Use "``OFF``" and "``ON``" for boolean values which can be modified by
  363. the user, such as ``POSITION_INDEPENDENT_CODE``. Such properties
  364. may be "enabled" and "disabled". Use "``True``" and "``False``" for
  365. inherent values which can't be modified after being set, such as the
  366. ``IMPORTED`` property of a build target.
  367. Style: Inline Literals
  368. ^^^^^^^^^^^^^^^^^^^^^^
  369. Mark up references to keywords in signatures, file names, and other
  370. technical terms with ``inline-literal`` syntax, for example:
  371. .. code-block:: rst
  372. If ``WIN32`` is used with :command:`add_executable`, the
  373. :prop_tgt:`WIN32_EXECUTABLE` target property is enabled. That command
  374. creates the file ``<name>.exe`` on Windows.
  375. Style: Cross-References
  376. ^^^^^^^^^^^^^^^^^^^^^^^
  377. Mark up linkable references as links, including repeats.
  378. An alternative, which is used by wikipedia
  379. (`<https://en.wikipedia.org/wiki/WP:REPEATLINK>`_),
  380. is to link to a reference only once per article. That style is not used
  381. in CMake documentation.
  382. Style: Referencing CMake Concepts
  383. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  384. If referring to a concept which corresponds to a property, and that
  385. concept is described in a high-level manual, prefer to link to the
  386. manual section instead of the property. For example:
  387. .. code-block:: rst
  388. This command creates an :ref:`Imported Target <Imported Targets>`.
  389. instead of:
  390. .. code-block:: rst
  391. This command creates an :prop_tgt:`IMPORTED` target.
  392. The latter should be used only when referring specifically to the
  393. property.
  394. References to manual sections are not automatically created by creating
  395. a section, but code such as:
  396. .. code-block:: rst
  397. .. _`Imported Targets`:
  398. creates a suitable anchor. Use an anchor name which matches the name
  399. of the corresponding section. Refer to the anchor using a
  400. cross-reference with specified text.
  401. Imported Targets need the ``IMPORTED`` term marked up with care in
  402. particular because the term may refer to a command keyword, a target
  403. property, or a concept.
  404. Where a property, command or variable is related conceptually to others,
  405. by for example, being related to the buildsystem description, generator
  406. expressions or Qt, each relevant property, command or variable should
  407. link to the primary manual, which provides high-level information. Only
  408. particular information relating to the command should be in the
  409. documentation of the command.
  410. Style: Referencing CMake Domain Objects
  411. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  412. When referring to `CMake Domain`_ objects such as properties, variables,
  413. commands etc, prefer to link to the target object and follow that with
  414. the type of object it is. For example:
  415. .. code-block:: rst
  416. Set the :prop_tgt:`AUTOMOC` target property to ``ON``.
  417. Instead of
  418. .. code-block:: rst
  419. Set the target property :prop_tgt:`AUTOMOC` to ``ON``.
  420. The ``policy`` directive is an exception, and the type us usually
  421. referred to before the link:
  422. .. code-block:: rst
  423. If policy :policy:`CMP0022` is set to ``NEW`` the behavior is ...
  424. However, markup self-references with ``inline-literal`` syntax.
  425. For example, within the ``add_executable`` command documentation, use
  426. .. code-block:: rst
  427. ``add_executable``
  428. not
  429. .. code-block:: rst
  430. :command:`add_executable`
  431. which is used elsewhere.
  432. Modules
  433. =======
  434. The ``Modules`` directory contains CMake-language ``.cmake`` module files.
  435. Module Documentation
  436. --------------------
  437. To document CMake module ``Modules/<module-name>.cmake``, modify
  438. ``Help/manual/cmake-modules.7.rst`` to reference the module in the
  439. ``toctree`` directive, in sorted order, as::
  440. /module/<module-name>
  441. Then add the module document file ``Help/module/<module-name>.rst``
  442. containing just the line::
  443. .. cmake-module:: ../../Modules/<module-name>.cmake
  444. The ``cmake-module`` directive will scan the module file to extract
  445. reStructuredText markup from comment blocks that start in ``.rst:``.
  446. At the top of ``Modules/<module-name>.cmake``, begin with the following
  447. license notice:
  448. ::
  449. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  450. # file Copyright.txt or https://cmake.org/licensing for details.
  451. After this notice, add a *BLANK* line. Then, add documentation using
  452. a `Bracket Comment`_ of the form:
  453. ::
  454. #[=======================================================================[.rst:
  455. <module-name>
  456. -------------
  457. <reStructuredText documentation of module>
  458. #]=======================================================================]
  459. Any number of ``=`` may be used in the opening and closing brackets
  460. as long as they match. Content on the line containing the closing
  461. bracket is excluded if and only if the line starts in ``#``.
  462. Additional such ``.rst:`` comments may appear anywhere in the module file.
  463. All such comments must start with ``#`` in the first column.
  464. For example, a ``FindXxx.cmake`` module may contain:
  465. ::
  466. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  467. # file Copyright.txt or https://cmake.org/licensing for details.
  468. #[=======================================================================[.rst:
  469. FindXxx
  470. -------
  471. This is a cool module.
  472. This module does really cool stuff.
  473. It can do even more than you think.
  474. It even needs two paragraphs to tell you about it.
  475. And it defines the following variables:
  476. ``VAR_COOL``
  477. this is great isn't it?
  478. ``VAR_REALLY_COOL``
  479. cool right?
  480. #]=======================================================================]
  481. <code>
  482. #[=======================================================================[.rst:
  483. .. command:: Xxx_do_something
  484. This command does something for Xxx::
  485. Xxx_do_something(some arguments)
  486. #]=======================================================================]
  487. macro(Xxx_do_something)
  488. <code>
  489. endmacro()
  490. Test the documentation formatting by running
  491. ``cmake --help-module <module-name>``, and also by enabling the
  492. ``SPHINX_HTML`` and ``SPHINX_MAN`` options to build the documentation.
  493. Edit the comments until generated documentation looks satisfactory. To
  494. have a .cmake file in this directory NOT show up in the modules
  495. documentation, simply leave out the ``Help/module/<module-name>.rst``
  496. file and the ``Help/manual/cmake-modules.7.rst`` toctree entry.
  497. .. _`Bracket Comment`: https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#bracket-comment
  498. Module Functions and Macros
  499. ---------------------------
  500. Modules may provide CMake functions and macros defined by the `function()`_
  501. and `macro()`_ commands. To avoid conflicts across modules, name the
  502. functions and macros using the prefix ``<ModuleName>_`` followed by the
  503. rest of the name, where ``<ModuleName>`` is the exact-case spelling of
  504. the module name. We have no convention for the portion of names after
  505. the ``<ModuleName>_`` prefix.
  506. For historical reasons, some modules that come with CMake do not follow
  507. this prefix convention. When adding new functions to these modules,
  508. discussion during review can decide whether to follow their existing
  509. convention or to use the module name prefix.
  510. Documentation of public functions and macros should be provided in
  511. the module, typically in the main `module documentation`_ at the top.
  512. For example, a ``MyModule`` module may document a function like this::
  513. #[=======================================================================[.rst:
  514. MyModule
  515. --------
  516. This is my module. It provides some functions.
  517. .. command:: MyModule_Some_Function
  518. This is some function:
  519. .. code-block:: cmake
  520. MyModule_Some_Function(...)
  521. #]=======================================================================]
  522. Documentation may alternatively be placed just before each definition.
  523. For example, a ``MyModule`` module may document another function like this::
  524. #[=======================================================================[.rst:
  525. .. command:: MyModule_Other_Function
  526. This is another function:
  527. .. code-block:: cmake
  528. MyModule_Other_Function(...)
  529. #]=======================================================================]
  530. function(MyModule_Other_Function ...)
  531. # ...
  532. endfunction()
  533. .. _`function()`: https://cmake.org/cmake/help/latest/command/function.html
  534. .. _`macro()`: https://cmake.org/cmake/help/latest/command/macro.html