How to add files to a non-executable or non-library target with CMake

本秂侑毒 提交于 2020-02-24 12:10:26

问题


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

or add_library(${target_name} ${source_files})

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)

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.


回答1:


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
)


来源:https://stackoverflow.com/questions/21914020/how-to-add-files-to-a-non-executable-or-non-library-target-with-cmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!