documentation.rst 24 KB

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