记录 CMake 模块的正确方法是什么?

What is the proper way to document a CMake module?

快速 Google 搜索(...实际上有很多相当广泛的 Google 搜索)无法解释如何正确记录 CMake 模块。

我正在寻找一种记录自定义 CMake 模块的方法,以便它们与 cmake --help-module <module_name> 命令一起使用。有没有标准的方法可以做到这一点?谁能给我指出一些很好的例子?记录过程似乎很奇怪……没有很好的记录。哈哈

如何记录与 cmake --help-module 一起使用的模块?

感谢任何帮助。

引自 Brad King(CMake 开发人员电子邮件列表成员)的电子邮件回复:

There is no way to do this. The only reason --help-module exists at all is because prior to 3.0 the documentation was generated by the CMake binary itself, and people were used to the option being available. It is only for builtin modules and only available for legacy reasons, and may one day go away in favor of the man pages and html docs.

The online docs, like those at https://cmake.org/cmake/help/v3.14 do publish a /objects.inv to support intersphinx:

http://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html

This was done on request of some users so I haven't looked into how that works, but one should be able to use sphinx to generate one's own documentation and still cross-reference CMake's online docs.

If you get that working we'd welcome a MR to add docs describing how, perhaps in

https://gitlab.kitware.com/cmake/cmake/blob/master/Help/dev/documentation.rst

听起来使用 Sphinx 是可行的方法。

附加信息:

Sphinx 怎么知道去解析那个“.cmake”文件? Sphinx 是否以特殊方式识别 "cmake-module" 关键字并知道如何处理它?

it’s from a Sphinx module that you can find the in the CMake sources Utilities/Sphinx/cmake.py. Or you can install this file using pip:

pip install sphinxcontrib-moderncmakedomain

When configuring Sphinx, you have to name the extensions to use in Sphinx's configuration file (conf.py) and add the name of the extension (sphinxcontrib.moderncmakedomain) to the extensions array.

好消息:您可以使用 sphinx 来记录您的 CMake 模块,同时使用 Doxygen 来记录您的 C++(或其他)源代码。

我创建了一个示例项目,展示了如何将 sphinxcontrib-moderncmakedomain 与 Sphinx 和 Doxygen 结合使用,为您的 C++ 代码和 CMake 代码生成文档:

https://gitlab.com/Pro1/doxygen-cmake-sphinx

它使用 sphinxcontrib-moderncmakedomain 包和 CMake 本身来配置 sphinx conf.py 然后 运行 sphinx。

该示例主要基于官方 CMake 文档,来自:https://gitlab.kitware.com/cmake/cmake/-/tree/master/Utilities/Sphinx