documentation.rst 25 KB

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