如何使用CMake将文件添加到非可执行或非库目标 [英] How to add files to a non-executable or non-library target with CMake
问题描述
我了解,如果目标是可执行文件或库,可以使用以下命令将某些文件添加到CMake中:
I understand I can add some files to a target in CMake if the target is an executable or a library with the following command:
add_executable(${target_name} ${source_files})
或 add_library($ {target_name} $ {source_files})
然后我的问题是,如果目标不是可执行文件或库,该怎么办?之所以提出这个问题,是因为我想用Doxygen建立文档的目标,并且可以使用以下命令来完成:
Then my question is what if the target is not an an executable or a library. I raise this question because I want to build a target for documentation with Doxygen, and this can be done with the following commands:
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) #doxygen file
set(doxyfile ${PROJECT_BINARY_DIR}/Doxyfile)
#configure the doxygen file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxygen.in ${PROJECT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target( doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)
使用Visual Studio, doc
成为目标,我也想添加 Doxyfile.in
项目中的文件,以防万一我需要在IDE中更改一些变量。关于如何在 doc
目标上添加此文件的任何想法?谢谢。
With Visual Studio, doc
becomes a target, and I also want to add Doxyfile.in
file in the project just in case that I need to change some variables inside with the IDE. Any ideas on how I can add this file on the doc
target? Thanks.
推荐答案
您可以使用 add_custom_target
:
You can use the SOURCES
argument of add_custom_target
for this:
add_custom_target( doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Doxygen.in
)
这篇关于如何使用CMake将文件添加到非可执行或非库目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!