How does cmake-docs use Sphinx to parse comments in CMake files?

Excuse me, CMake Team.

I’ve noticed before that many CMake files in Kitware/CMake have comments in the following format in their headers (ex. FindPython.cmake):

#[====================[.rst:

#]====================]

And these comments eventually end up in the CMake Documentation (ex. FindPython). This is similar to how Doxygen parses C/C++ comments. Since I didn’t see that Sphinx Documentation has built-in support for this kind of parsing, I’m guessing that CMake has implemented its own mechanism to parse these types of comments? If so, how?

We implement a Sphinx extension module that adds a cmake-module directive. The directive is used by each Help/module/*.rst file to parse documentation blocks out of a .cmake file.

1 Like