【问题标题】:CMake for Doxygen用于 Doxygen 的 CMake
【发布时间】:2020-07-12 07:36:41
【问题描述】:

我正在尝试将 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

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

【问题讨论】:

  • 参数WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 表示doxygen 可执行文件将从build 目录中调用。所以src/player.cpp不能从那个目录访问。
  • 啊,明白了! @Tsyvarev 有什么方法可以直接从 CMakeLists 中的某个命令打开 index.html 文件?
  • @FSJ 要使用 CMake 打开生成的文档(例如 index.html),请参阅回复 here

标签: cmake doxygen


【解决方案1】:

如果您想从 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)

【讨论】:

  • 我在这里写了 /doc set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/config-file.doxygen) 假设这应该是在制作之后放置文档的位置。不是这样吗?此外,目前当我运行 make 时,它​​工作正常,但由于某种原因,会生成一个额外的 build... 文件夹。知道为什么吗?
  • @FSJ 不,当您运行doxygen 时,您需要为其提供配置文件。因此,当您在自定义目标中运行 COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} 时,${DOXYGEN_OUT} 需要是配置文件。您指定 where 将生成的文档放置在配置文件本身中。在 Doxygen 配置文件中查找 OUTPUT_DIRECTORY 变量,您可以根据自己的情况将其设置为 ../docdoc
  • 那么/config-fileconfig-file.doxygen之间到底有什么区别。目前,我的根目录中只有一个配置文件,它实际上创建了文档。
  • 您使用configure_file()config-file 从您的根目录复制到您的构建目录,并且@ONLY 参数可以 对此文件进行修改。由于您将 Doxygen 配置文件复制到 build 目录,因此您似乎想从该目录run Doxygen。我刚刚将复制的文件重命名为config-file.doxygen,以更清楚地表明它是一个 Doxygen 配置文件。
猜你喜欢
  • 2017-10-26
  • 2013-01-31
  • 2016-04-25
  • 1970-01-01
  • 2020-07-06
  • 2012-11-11
  • 2011-04-06
  • 2021-01-01
相关资源
最近更新 更多