6

I am trying to use CMake for Doxygen generated documentation. This is what my CMakeList.txt looks like:

if (DOXYGEN_FOUND) # set input and output files set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/config-file) set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}doc) # request to configure the file configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) message("Doxygen build started") # note the option ALL which allows to build the docs together with the application add_custom_target( doc_doxygen ALL COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating API documentation with Doxygen" VERBATIM ) else (DOXYGEN_FOUND) message("Doxygen need to be installed to generate the doxygen documentation") endif (DOXYGEN_FOUND) 

Upon running make , I get these errors:

Doxygen build started -- Configuring done -- Generating done -- Build files have been written to: /home/newproject/build [ 5%] Generating API documentation with Doxygen warning: tag INPUT: input source `doc/mainpage.txt' does not exist warning: tag INPUT: input source `src/player.cpp' does not exist warning: tag INPUT: input source `src/player.h' does not exist warning: tag INPUT: input source `test/tests-mainfunctionality-v2.cpp' does not exist error: tag OUTPUT_DIRECTORY: Output directory `doc' does not exist and cannot be created Exiting... CMakeFiles/doc_doxygen.dir/build.make:57: recipe for target 'CMakeFiles/doc_doxygen' failed make[2]: *** [CMakeFiles/doc_doxygen] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/doc_doxygen.dir/all' failed make[1]: *** [CMakeFiles/doc_doxygen.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2 

even though these files do exist. Is there something wrong with the paths I am using?

3
  • Parameter WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} implies that doxygen executable will be called from the build directory. So src/player.cpp cannot be accessed from that directory. Commented Mar 31, 2020 at 17:13
  • Ah got it! @Tsyvarev is there any way I can directly open the index.html file from some command in the CMakeLists? Commented Mar 31, 2020 at 17:46
  • @FSJ For opening the generated documentation (e.g. index.html) using CMake, see the response here. Commented Mar 31, 2020 at 17:57

1 Answer 1

5

If you want to run Doxygen from your CMake binary directory (build), you will have to modify your Doxygen configuration file to include the correct relative paths:

INPUT = ../doc/mainpage.txt \ ../src/player.cpp \ ../src/player.h \ ../test/tests-mainfunctionality-v2.cpp 

Also, your use of the DOXYGEN_OUT looks a bit odd, as it is currently set to something outside the binary directory. This variable should specify a file name, in order for your configure_file() and custom target commands to work correctly. Perhaps, try renaming it to something like this:

# check if Doxygen is installed find_package(Doxygen) if (DOXYGEN_FOUND) # set input and output files set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/config-file) set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/config-file.doxygen) # request to configure the file configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) message("Doxygen build started") # note the option ALL which allows to build the docs together with the application add_custom_target( doc_doxygen ALL COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating API documentation with Doxygen" VERBATIM ) else (DOXYGEN_FOUND) message("Doxygen need to be installed to generate the doxygen documentation") endif (DOXYGEN_FOUND) 
Sign up to request clarification or add additional context in comments.

4 Comments

I wrote /doc here set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/config-file.doxygen) assuming that this is supposed to be the location where the documentation will be placed after the make. Isn't that so? Also, currently when I run make, it works fine but for some reason an additional build... folder gets generated. Any idea why?
@FSJ No, when you run doxygen, you need to provide it a config file. So when you run COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} in your custom target, ${DOXYGEN_OUT} needs to be the config file. You specify where to place the generated documentation inside the config file itself. Look for the OUTPUT_DIRECTORY variable in the Doxygen config file, and you can set it to ../doc or doc in your case.
Then what exactly is the difference between /config-file and config-file.doxygen. For now, I only have one config-file in my root which actually creates the documentation.
You use configure_file() to copy config-file from your root to your build directory, and the @ONLY argument may make modifications to this file. Since you copy the Doxygen config file to your build directory, it seems like you want to run Doxygen from that directory. I just renamed the copied file to config-file.doxygen to make it more clear that it was a Doxygen config file.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.