问题描述
我在Web上找到了一个示例cmake文件,并将其放在我项目的 / doc
子目录中,其中文件 myproject.doxgen
也位于其中,包含Doxygen配置。
I found on the Web a sample cmake file and put it in the /doc
subdirectory of my project, where the file myproject.doxgen
is also located, containing Doxygen configuration.
我已经测试过运行 doxygen.exe myproject.doxygen
产生有效的输出。我只需要将其构建到CMake流程中即可。因此 /doc/CMakeLists.txt
是:
I've tested that running doxygen.exe myproject.doxygen
produces valid output. I only need to build this into the CMake process. So /doc/CMakeLists.txt
is:
find_package(Doxygen)
option(BUILD_DOCUMENTATION "Create and install the HTML based API
documentation (requires Doxygen)" ${DOXYGEN_FOUND})
if(BUILD_DOCUMENTATION)
if(NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is needed to build the documentation.")
endif()
set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/../doc/myproject.doxygen)
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/doxyfile)
configure_file(${doxyfile_in} ${doxyfile} @ONLY)
message("Doxygen build started.")
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile_in}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
# install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc)
endif()
对我来说,它仅将原始配置文件复制到 / build / my / project / doc /
中,并且仅执行其他操作。
It doesn't work for me, it only copies the original config file into /build/my/project/doc/
and does nothing more.
我想要的是在构建过程中生成doxygen文档。理想情况下,仅当构建Release配置时。
What I want is to generate the doxygen documentation during my builds; ideally, only when building the Release configuration.
推荐答案
您显示的CMake文件的设置方式会创建一个目标称为 doc
;构建该目标(例如运行 make doc
)会产生令人困惑的事情。目标不属于全部
(或同等价值)的一部分;为此,请将 ALL
添加到自定义目标创建中:
The way the CMake file you've shown is set up, it creates a target called doc
; building that target (such as running make doc
) generates the doxymentation. The target is not part of make all
(or equivalent); to make it such, add ALL
into the custom target creation:
add_custom_target(
doc ALL
COMMAND #... everything else as before
)
如果要限制此目标以仅在特定配置中构建(如注释中所述),可以使用:
If you want to limit this target to only build in a particular configuration (as you've mentioned in comments), you can use generator expressions:
add_custom_target(
doc ALL
COMMAND $<$<CONFIG:Release>:${DOXYGEN_EXECUTABLE} ${doxyfile_in}>
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
一些CMake生成器不能很好地应对空的 COMMAND
。考虑到这一点,以下应该是故障安全的:
It might happen that some CMake generators do not cope well with an empty COMMAND
. With this in mind, the following should be fail-safe:
add_custom_target(
doc ALL
COMMAND
$<$<CONFIG:Release>:${DOXYGEN_EXECUTABLE} ${doxyfile_in}>
$<$<NOT:$<CONFIG:Release>>:${CMAKE_COMMAND} -E echo "Only done in Release builds">
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
这篇关于从CMake脚本构建doxygen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!