根据特定的cmake自定义目标设置变量

时间:2014-08-20 10:08:48

标签: variables cmake

我的CMakeLists.txt

中有一个这样定义的目标
find_package(Doxygen)
if(DOXYGEN_FOUND)
    set(INTERNAL, no)
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
    add_custom_target(doc
        ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
        DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Generating API documentation with Doxygen" VERBATIM
    )
endif(DOXYGEN_FOUND)

现在我想添加一个名为doc_internal的新自定义目标,但这次变量INTERNAL必须设置为yes

这归结为全局不设置变量INTERNAL,但变量取决于自定义目标。

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

例如configure_file可以为不同的目标输出不同的Doxyfiles

macro(gen_doxy target INTERNAL)
  set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_${target})
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${doxyfile} @ONLY)
  add_custom_target(${target} ${DOXYGEN_EXECUTABLE} ${doxyfile} ...)
end macro()