用于 Doxygen 的 CMake

CMake for Doxygen

我正在尝试将 CMake 用于 Doxygen 生成的文档。这就是我的 CMakeList.txt 的样子:

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)

在 运行 make 之后,我得到了这些错误:

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

即使这些文件确实存在。我使用的路径有问题吗?

如果您想从您的 CMake 二进制目录 (build) 运行 Doxygen,您将必须修改您的 Doxygen 配置文件以包含正确的相对路径:

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

此外,您对 DOXYGEN_OUT 的使用看起来有点奇怪,因为它当前设置为 二进制目录之外的内容。此变量应指定文件名,以便您的 configure_file() 和自定义目标命令正常工作。也许,尝试将其重命名为这样的名称:

# 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)