Building Documentation with Doxygen, the modular CMake way?

Is there a guide on writing your doxygen generation with the Modern CMake approach? I’d like to not have to re-write all the include paths and #defines a second time in the doxygen call, I’d like to be able to get those values from the targets themselves. Basically a way to build doxygen-per-target (like an executable && all it’s transitive dependencies).

Is the doxygen_add_docs() command from the FindDoxygen module what you’re looking for, or are you after something else?

As far as I know, doxygen_add_docs() doesn’t take dependent TARGETS which it can pull transitive compile defines, includes, warnings, etc. It wants you do provide #defines and INCLUDES via the DOXYGEN_xxx variables.

It would be great if we could build documentation based on how the code was built, i.e. using the paths and defines given to the code.

For example, this would be nice:

add_executable(foo <sources>)
target_compile_defines(foo -D...)
target_include_directories(foo -I...)
doxygen_add_docs(foo_docs ... TARGET foo ...)

An enhancement could be done to use TARGET_PROPERTY genex queries on the given target(s). See here for how VTK gets -D and -I flags as needed. Adapting it for Doxygen would be a welcome merge request (or even just an issue).

Added issue:

FWIW here is how GLFW handles doxygen. Which I think is pretty clean and considering the fantastic quality of the docs for this library it’s worth looking at.