Quick setup to use Doxygen with CMake
Problem statement
It was finally time to set up API documentation for one of my projects. For reference, the project size is about 7-8K lines. Some of the requirements were:
- The documentation should be generated by a CMake file
- It should only be generated in Release mode
- It should contain some user documentation files (of Markdown origin) which are not located with the source folder
The official Doxygen site contains plenty of information on how to use the Doxygen syntax so that to generate *.html
files of documentation. This is not going to be repeated here.
Repository structure
To provide an outline, this is the repository structure for which I want to build the documentation:
Root:
.git
build-folder
docs
:Doxyfile.in
,MarkdownFile.md
src
:CMakeLists.txt
, all the source files (e.g. .cpp and .h)
Lets say I would like my documentation to be built inside the build-folder
.
CMake setup
To make the Doxygen to build documentation from the CMake file, the following code snipped can be used:
If we only want the documentation to be generated in Release mode, then we can embrace the above code snippet by:
Doxyfile setup
The Doxyfile.in
contains the Doxygen parameters and setting for a build. At first, it is recommended to generate a default Doxyfile and then edit the necessary settings within the file.
For our compatibility with the CMake file, we have to set the input (where is the source code and other files to generate the documentation from) and the output (where the result doc files will be rendered).
Here is an example of parameters:
Those settings were enough to get me started with the Doxygen. As a result I now have a set of generated .html
pages of my project’s API. The only thing left is to edit the code comments in correspondence with Doxygen syntax.
Update
With codedocs.xyz, getting documentation online became even easier! All you need is to connect your github account and select which githib repository to use for documentation build. As long as you have doxygen configuration files, no further steps are required, and as a result you get online development documentation.
Leave a Comment