我正在尝试使用 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)
Run Code Online (Sandbox Code Playgroud)
运行后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
Run Code Online (Sandbox Code Playgroud)
即使这些文件确实存在。我使用的路径有问题吗?
如果您想从 CMake 二进制目录 ( ) 运行 Doxygen build,则必须修改 Doxygen 配置文件以包含正确的相对路径:
INPUT = ../doc/mainpage.txt \
../src/player.cpp \
../src/player.h \
../test/tests-mainfunctionality-v2.cpp
Run Code Online (Sandbox Code Playgroud)
另外,您对这些的使用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)
Run Code Online (Sandbox Code Playgroud)