documentation.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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`: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
  12. .. _`Sphinx`: http://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. ``signature`` directive
  178. ^^^^^^^^^^^^^^^^^^^^^^^
  179. Document `CMake Command Signatures <Style: CMake Command Signatures_>`_
  180. within a ``Help/command/<command-name>.rst`` document.
  181. .. code-block:: rst
  182. .. signature:: <command-name>(<signature>)
  183. This indented block documents one or more signatures of a CMake command.
  184. The ``signature`` directive requires one argument, the signature summary:
  185. * One or more signatures must immediately follow the ``::``.
  186. The first signature may optionally be placed on the same line.
  187. A blank line following the ``signature`` directive will result in a
  188. documentation generation error: ``1 argument(s) required, 0 supplied``.
  189. * Signatures may be split across multiple lines, but the final ``)`` of each
  190. signature must be the last character on its line.
  191. * Blank lines between signatures are not allowed. (Content after a blank line
  192. is treated as part of the description.)
  193. * Whitespace in signatures is not preserved. To document a complex signature,
  194. abbreviate it in the ``signature`` directive argument and specify the full
  195. signature in a ``code-block`` in the description.
  196. The ``signature`` directive generates a hyperlink target for each signature:
  197. * Default target names are automatically extracted from leading "keyword"
  198. arguments in the signatures, where a keyword is any sequence of
  199. non-space starting with a letter. For example, the signature
  200. ``string(REGEX REPLACE <match-regex> ...)`` generates the target
  201. ``REGEX REPLACE``, similar to ``.. _`REGEX REPLACE`:``.
  202. * Custom target names may be specified using a ``:target:`` option.
  203. For example:
  204. .. code-block:: rst
  205. .. signature::
  206. cmake_path(GET <path-var> ROOT_NAME <out-var>)
  207. cmake_path(GET <path-var> ROOT_PATH <out-var>)
  208. :target:
  209. GET ROOT_NAME
  210. GET ROOT_PATH
  211. Provide a custom target name for each signature, one per line.
  212. The first target may optionally be placed on the same line as ``:target:``.
  213. * If a target name is already in use earlier in the document, no hyperlink
  214. target will be generated.
  215. * The targets may be referenced from within the same document using
  216. ```REF`_`` or ```TEXT <REF_>`_`` syntax. Like reStructuredText section
  217. headers, the targets do not work with Sphinx ``:ref:`` syntax, however
  218. they can be globally referenced using e.g. ``:command:`string(APPEND)```.
  219. Although whitespace in the signature is not preserved, by default, line breaks
  220. are suppressed inside of square- or angle-brackets. This behavior can be
  221. controlled using the ``:break:`` option; note, however, that there is no way
  222. to *force* a line break. The default value is 'smart'. Allowable values are:
  223. ``all``
  224. Allow line breaks at any whitespace.
  225. ``smart`` (default)
  226. Allow line breaks at whitespace, except between matched square- or
  227. angle-brackets. For example, if a signature contains the text
  228. ``<input>... [OUTPUT_VARIABLE <out-var>]``, a line break would be allowed
  229. after ``<input>...`` but not between ``OUTPUT_VARIABLE`` and ``<out-var>``.
  230. ``verbatim``
  231. Allow line breaks only where the source document contains a newline.
  232. The directive treats its content as the documentation of the signature(s).
  233. Indent the signature documentation accordingly.
  234. ``variable`` directive
  235. ^^^^^^^^^^^^^^^^^^^^^^
  236. Document a "variable" object:
  237. .. code-block:: rst
  238. .. variable:: <variable-name>
  239. This indented block documents <variable-name>.
  240. The directive requires a single argument, the variable name.
  241. .. _`Sphinx Domain`: http://sphinx-doc.org/domains.html
  242. .. _`cmake(1)`: https://cmake.org/cmake/help/latest/manual/cmake.1.html
  243. .. _`cmake-env-variables(7)`: https://cmake.org/cmake/help/latest/manual/cmake-env-variables.7.html
  244. .. _`cmake-generator-expressions(7)`: https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
  245. .. _`cmake-modules(7)`: https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html
  246. .. _`cmake-policies(7)`: https://cmake.org/cmake/help/latest/manual/cmake-policies.7.html
  247. .. _`cmake-properties(7)`: https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html
  248. .. _`cmake-variables(7)`: https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html
  249. .. _`cmake_policy()`: https://cmake.org/cmake/help/latest/command/cmake_policy.html
  250. .. _`cpack(1)`: https://cmake.org/cmake/help/latest/manual/cpack.1.html
  251. .. _`include()`: https://cmake.org/cmake/help/latest/command/include.html
  252. .. _`set()`: https://cmake.org/cmake/help/latest/command/set.html
  253. .. _`set_property()`: https://cmake.org/cmake/help/latest/command/set_property.html
  254. Cross-References
  255. ----------------
  256. Sphinx uses reStructuredText interpreted text roles to provide
  257. cross-reference syntax. The `CMake Domain`_ provides for each
  258. domain object type a role of the same name to cross-reference it.
  259. CMake Domain roles are inline markup of the forms::
  260. :type:`name`
  261. :type:`text <name>`
  262. where ``type`` is the domain object type and ``name`` is the
  263. domain object name. In the first form the link text will be
  264. ``name`` (or ``name()`` if the type is ``command``) and in
  265. the second form the link text will be the explicit ``text``.
  266. For example, the code:
  267. .. code-block:: rst
  268. * The :command:`list` command.
  269. * The :command:`list(APPEND)` sub-command.
  270. * The :command:`list() command <list>`.
  271. * The :command:`list(APPEND) sub-command <list>`.
  272. * The :variable:`CMAKE_VERSION` variable.
  273. * The :prop_tgt:`OUTPUT_NAME_<CONFIG>` target property.
  274. produces:
  275. * The `list()`_ command.
  276. * The `list(APPEND)`_ sub-command.
  277. * The `list() command`_.
  278. * The `list(APPEND) sub-command`_.
  279. * The `CMAKE_VERSION`_ variable.
  280. * The `OUTPUT_NAME_<CONFIG>`_ target property.
  281. Note that CMake Domain roles differ from Sphinx and reStructuredText
  282. convention in that the form ``a<b>``, without a space preceding ``<``,
  283. is interpreted as a name instead of link text with an explicit target.
  284. This is necessary because we use ``<placeholders>`` frequently in
  285. object names like ``OUTPUT_NAME_<CONFIG>``. The form ``a <b>``,
  286. with a space preceding ``<``, is still interpreted as a link text
  287. with an explicit target.
  288. .. _`list()`: https://cmake.org/cmake/help/latest/command/list.html
  289. .. _`list(APPEND)`: https://cmake.org/cmake/help/latest/command/list.html
  290. .. _`list(APPEND) sub-command`: https://cmake.org/cmake/help/latest/command/list.html
  291. .. _`list() command`: https://cmake.org/cmake/help/latest/command/list.html
  292. .. _`CMAKE_VERSION`: https://cmake.org/cmake/help/latest/variable/CMAKE_VERSION.html
  293. .. _`OUTPUT_NAME_<CONFIG>`: https://cmake.org/cmake/help/latest/prop_tgt/OUTPUT_NAME_CONFIG.html
  294. Style
  295. -----
  296. Style: Section Headers
  297. ^^^^^^^^^^^^^^^^^^^^^^
  298. When marking section titles, make the section decoration line as long as
  299. the title text. Use only a line below the title, not above. For
  300. example:
  301. .. code-block:: rst
  302. Title Text
  303. ----------
  304. Capitalize the first letter of each non-minor word in the title.
  305. The section header underline character hierarchy is
  306. * ``#``: Manual group (part) in the master document
  307. * ``*``: Manual (chapter) title
  308. * ``=``: Section within a manual
  309. * ``-``: Subsection or `CMake Domain`_ object document title
  310. * ``^``: Subsubsection or `CMake Domain`_ object document section
  311. * ``"``: Paragraph or `CMake Domain`_ object document subsection
  312. Style: Whitespace
  313. ^^^^^^^^^^^^^^^^^
  314. Use two spaces for indentation. Use two spaces between sentences in
  315. prose.
  316. Style: Line Length
  317. ^^^^^^^^^^^^^^^^^^
  318. Prefer to restrict the width of lines to 75-80 columns. This is not a
  319. hard restriction, but writing new paragraphs wrapped at 75 columns
  320. allows space for adding minor content without significant re-wrapping of
  321. content.
  322. Style: Prose
  323. ^^^^^^^^^^^^
  324. Use American English spellings in prose.
  325. Style: Starting Literal Blocks
  326. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  327. Prefer to mark the start of literal blocks with ``::`` at the end of
  328. the preceding paragraph. In cases where the following block gets
  329. a ``code-block`` marker, put a single ``:`` at the end of the preceding
  330. paragraph.
  331. Style: CMake Command Signatures
  332. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  333. A ``Help/command/<command-name>.rst`` document defines one ``command``
  334. object in the `CMake Domain`_, but some commands have multiple signatures.
  335. Use the CMake Domain's `signature directive`_ to document each signature.
  336. Separate signatures from preceding content by a section header.
  337. For example:
  338. .. code-block:: rst
  339. ... preceding paragraph.
  340. Normal Libraries
  341. ^^^^^^^^^^^^^^^^
  342. .. signature::
  343. add_library(<lib> ...)
  344. This signature is used for ...
  345. Use the following conventions in command signature documentation:
  346. * Use an angle-bracket ``<placeholder>`` for arguments to be specified
  347. by the caller. Refer to them in prose using
  348. `inline literal <Style: Inline Literals_>`_ syntax.
  349. * Wrap optional parts with square brackets.
  350. * Mark repeatable parts with a trailing ellipsis (``...``).
  351. The ``signature`` directive may be used multiple times for different
  352. signatures of the same command.
  353. Style: Boolean Constants
  354. ^^^^^^^^^^^^^^^^^^^^^^^^
  355. Use "``OFF``" and "``ON``" for boolean values which can be modified by
  356. the user, such as ``POSITION_INDEPENDENT_CODE``. Such properties
  357. may be "enabled" and "disabled". Use "``True``" and "``False``" for
  358. inherent values which can't be modified after being set, such as the
  359. ``IMPORTED`` property of a build target.
  360. Style: Inline Literals
  361. ^^^^^^^^^^^^^^^^^^^^^^
  362. Mark up references to keywords in signatures, file names, and other
  363. technical terms with ``inline-literal`` syntax, for example:
  364. .. code-block:: rst
  365. If ``WIN32`` is used with :command:`add_executable`, the
  366. :prop_tgt:`WIN32_EXECUTABLE` target property is enabled. That command
  367. creates the file ``<name>.exe`` on Windows.
  368. Style: Cross-References
  369. ^^^^^^^^^^^^^^^^^^^^^^^
  370. Mark up linkable references as links, including repeats.
  371. An alternative, which is used by wikipedia
  372. (`<http://en.wikipedia.org/wiki/WP:REPEATLINK>`_),
  373. is to link to a reference only once per article. That style is not used
  374. in CMake documentation.
  375. Style: Referencing CMake Concepts
  376. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  377. If referring to a concept which corresponds to a property, and that
  378. concept is described in a high-level manual, prefer to link to the
  379. manual section instead of the property. For example:
  380. .. code-block:: rst
  381. This command creates an :ref:`Imported Target <Imported Targets>`.
  382. instead of:
  383. .. code-block:: rst
  384. This command creates an :prop_tgt:`IMPORTED` target.
  385. The latter should be used only when referring specifically to the
  386. property.
  387. References to manual sections are not automatically created by creating
  388. a section, but code such as:
  389. .. code-block:: rst
  390. .. _`Imported Targets`:
  391. creates a suitable anchor. Use an anchor name which matches the name
  392. of the corresponding section. Refer to the anchor using a
  393. cross-reference with specified text.
  394. Imported Targets need the ``IMPORTED`` term marked up with care in
  395. particular because the term may refer to a command keyword, a target
  396. property, or a concept.
  397. Where a property, command or variable is related conceptually to others,
  398. by for example, being related to the buildsystem description, generator
  399. expressions or Qt, each relevant property, command or variable should
  400. link to the primary manual, which provides high-level information. Only
  401. particular information relating to the command should be in the
  402. documentation of the command.
  403. Style: Referencing CMake Domain Objects
  404. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  405. When referring to `CMake Domain`_ objects such as properties, variables,
  406. commands etc, prefer to link to the target object and follow that with
  407. the type of object it is. For example:
  408. .. code-block:: rst
  409. Set the :prop_tgt:`AUTOMOC` target property to ``ON``.
  410. Instead of
  411. .. code-block:: rst
  412. Set the target property :prop_tgt:`AUTOMOC` to ``ON``.
  413. The ``policy`` directive is an exception, and the type us usually
  414. referred to before the link:
  415. .. code-block:: rst
  416. If policy :policy:`CMP0022` is set to ``NEW`` the behavior is ...
  417. However, markup self-references with ``inline-literal`` syntax.
  418. For example, within the ``add_executable`` command documentation, use
  419. .. code-block:: rst
  420. ``add_executable``
  421. not
  422. .. code-block:: rst
  423. :command:`add_executable`
  424. which is used elsewhere.
  425. Modules
  426. =======
  427. The ``Modules`` directory contains CMake-language ``.cmake`` module files.
  428. Module Documentation
  429. --------------------
  430. To document CMake module ``Modules/<module-name>.cmake``, modify
  431. ``Help/manual/cmake-modules.7.rst`` to reference the module in the
  432. ``toctree`` directive, in sorted order, as::
  433. /module/<module-name>
  434. Then add the module document file ``Help/module/<module-name>.rst``
  435. containing just the line::
  436. .. cmake-module:: ../../Modules/<module-name>.cmake
  437. The ``cmake-module`` directive will scan the module file to extract
  438. reStructuredText markup from comment blocks that start in ``.rst:``.
  439. At the top of ``Modules/<module-name>.cmake``, begin with the following
  440. license notice:
  441. ::
  442. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  443. # file Copyright.txt or https://cmake.org/licensing for details.
  444. After this notice, add a *BLANK* line. Then, add documentation using
  445. a `Bracket Comment`_ of the form:
  446. ::
  447. #[=======================================================================[.rst:
  448. <module-name>
  449. -------------
  450. <reStructuredText documentation of module>
  451. #]=======================================================================]
  452. Any number of ``=`` may be used in the opening and closing brackets
  453. as long as they match. Content on the line containing the closing
  454. bracket is excluded if and only if the line starts in ``#``.
  455. Additional such ``.rst:`` comments may appear anywhere in the module file.
  456. All such comments must start with ``#`` in the first column.
  457. For example, a ``FindXxx.cmake`` module may contain:
  458. ::
  459. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  460. # file Copyright.txt or https://cmake.org/licensing for details.
  461. #[=======================================================================[.rst:
  462. FindXxx
  463. -------
  464. This is a cool module.
  465. This module does really cool stuff.
  466. It can do even more than you think.
  467. It even needs two paragraphs to tell you about it.
  468. And it defines the following variables:
  469. ``VAR_COOL``
  470. this is great isn't it?
  471. ``VAR_REALLY_COOL``
  472. cool right?
  473. #]=======================================================================]
  474. <code>
  475. #[=======================================================================[.rst:
  476. .. command:: Xxx_do_something
  477. This command does something for Xxx::
  478. Xxx_do_something(some arguments)
  479. #]=======================================================================]
  480. macro(Xxx_do_something)
  481. <code>
  482. endmacro()
  483. Test the documentation formatting by running
  484. ``cmake --help-module <module-name>``, and also by enabling the
  485. ``SPHINX_HTML`` and ``SPHINX_MAN`` options to build the documentation.
  486. Edit the comments until generated documentation looks satisfactory. To
  487. have a .cmake file in this directory NOT show up in the modules
  488. documentation, simply leave out the ``Help/module/<module-name>.rst``
  489. file and the ``Help/manual/cmake-modules.7.rst`` toctree entry.
  490. .. _`Bracket Comment`: https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#bracket-comment
  491. Module Functions and Macros
  492. ---------------------------
  493. Modules may provide CMake functions and macros defined by the `function()`_
  494. and `macro()`_ commands. To avoid conflicts across modules, name the
  495. functions and macros using the prefix ``<ModuleName>_`` followed by the
  496. rest of the name, where ``<ModuleName>`` is the exact-case spelling of
  497. the module name. We have no convention for the portion of names after
  498. the ``<ModuleName>_`` prefix.
  499. For historical reasons, some modules that come with CMake do not follow
  500. this prefix convention. When adding new functions to these modules,
  501. discussion during review can decide whether to follow their existing
  502. convention or to use the module name prefix.
  503. Documentation of public functions and macros should be provided in
  504. the module, typically in the main `module documentation`_ at the top.
  505. For example, a ``MyModule`` module may document a function like this::
  506. #[=======================================================================[.rst:
  507. MyModule
  508. --------
  509. This is my module. It provides some functions.
  510. .. command:: MyModule_Some_Function
  511. This is some function:
  512. .. code-block:: cmake
  513. MyModule_Some_Function(...)
  514. #]=======================================================================]
  515. Documentation may alternatively be placed just before each definition.
  516. For example, a ``MyModule`` module may document another function like this::
  517. #[=======================================================================[.rst:
  518. .. command:: MyModule_Other_Function
  519. This is another function:
  520. .. code-block:: cmake
  521. MyModule_Other_Function(...)
  522. #]=======================================================================]
  523. function(MyModule_Other_Function ...)
  524. # ...
  525. endfunction()
  526. .. _`function()`: https://cmake.org/cmake/help/latest/command/function.html
  527. .. _`macro()`: https://cmake.org/cmake/help/latest/command/macro.html