Generating Doxygen Documentation for C++ using CMake

Tutorials Jun 06, 2020


In early October 2019, whilst I was searching for a Visual Novel game engine, I happened to stumble upon a project called NovelRT.
NovelRT is a newer game engine designed with Visual Novels (VNs) in mind. Seeing as how no documentation was present when I planned to use it I decided to PR the documentation and documentation generation myself.
This blog post intends to show and explain how I achieved that goal.


Since some of you might wonder what the results are I decided to provide a link to the repository.


The official Doxygen site contains plenty of information on how to use its syntax to generate *.html documentation files. For this reason, we are not going to be covering that.
At the same time we will presume you already have some basic knowledge of CMake.

Project file structure

|-- doxygen/
|   |-- CMakeLists.txt
|   |--
|   `-- logo.png
|-- include/
|   `-- (All header files)
|-- src/
|   |-- CMakeLists.txt
|   `-- (All source files)
`-- CMakeLists.txt
Example directory structure

With this setup the Doxygen output will be in the CMake binaries directory.

CMake setup

The first CMake file that we shall configure will be the root one. Its main function is to load the other files so they get properly recognized. We will achieve that by using the add_subdirectory() function, the result should look something like this:

# Specifies the minimum required CMake version.
# More information found at
cmake_minimum_required(VERSION 3.17)

# This just sets the CMake project name.
# More information found at

# Adds the given directories to those the compiler uses to search for include files.
# More information found at

# "add_subdirectory" has a rather fitting name, it adds a subdirectory to the build.
# More information found at

# This adds the src folder a new directory so that it can be properly handled by CMake
# and this adds the doxygen folder as a CMake subdirectory.

The 2nd CMakeLists file that we need is located in the doxygen directory and is responsible for handling the documentation generation.

# Finds and loads settings from an external project.
# "QUIET" makes it so that CMake won't complain in case Doxygen isn't present.
# More information at
find_package(Doxygen QUIET)

# Here we set a list of images that can/will be used in the documentation.
# For now we only have a logo to use.

# While "DOCS_RESOURCES" contains all the other lists so that the file moving can be done with only one call in CMake.

  # Input directory of header files from which the documentation will be formed.
  # Output directory for built documentation.
  # "CMAKE_BINARY_DIR" is usually a directory named "out" located in the root of the project.
  # "DOXYGEN_INDEX_FILE" is the path to the documentation homepage html file.
  # The following is used to always force Doxygen to try a run regardless if one was already performed.
  # The 2 following lines just specify the input path for the template Doxygen options.
  # Whilst the 2nd specifies the output for when the place holder data has already been filled in.


  #Replace variables inside @@ with the current values
  configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY)
  # Here we use CMake to manually create the Doxygen output directory since it doesn't do it itself.
  # Copy the needed resources like the logo for instance into the output directory.

  # More information at
                     COMMENT "Generating docs")

  # More information at
  add_custom_target(Doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE})
else ()
	message("Doxygen need to be installed to generate the doxygen documentation")

Doxyfile setup

The contains the Doxygen recipe for building the docs. At first, it is recommended to generate a default Doxyfile and then edit the necessary settings within the file.
For our compatibility with the CMakeLists file, we have to set the pre-configured variables inside the We can do so by enclosing the set variable with @@; an example of that would be @[email protected].
The full Doxyfile being referenced can be found here.

Example class documentation page

If you've stuck around to read the whole post I have a small reward for you, a rather nice song.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.