如何使用CMake有条件地安装多个doxygen生成的文档?

时间:2018-01-30 17:19:36

标签: cmake doxygen documentation-generation

我有一个CMakeLists.txt,它根据命令行中的用户配置有条件地生成各种格式的文档。

set(DOXYGEN_INPUT ${PROJECT_SOURCE_DIR}/docs/doxygen/Doxyfile.in)
set(DOXY_OUT ${PROJECT_SOURCE_DIR}/docs/Doxyfile)

if(GENERATE_QHP)
    message("Enabled the .qhp documentation")
    set(qch "qch")
    find_program(QHELPGEN_EXECUTABLE qhelpgenerator)
    if(NOT QHELPGEN_EXECUTABLE)
        message(FATAL_ERROR "Unable to build API documentation in qch format.")
    endif()
endif(GENERATE_QHP)

if(GENERATE_MAN)
    message("Enabled the unix man page documentation")
    set(man "man")
endif(GENERATE_MAN)

configure_file(${DOXYGEN_INPUT} ${DOXY_OUT} @ONLY)
message("Doxygen build started")

add_custom_target(doc ALL
    COMMAND ${DOXYGEN_EXECUTABLE} ${DOXY_OUT}
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "Generating API documentation with Doxygen"
    VERBATIM
    )

有条件安装的一种方法是在ifs中写入多个install if(GENERATE_HTML) install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION ${CMAKE_INSTALL_DOCDIR}) endif(GENERATE_HTML) if(GENERATE_MAN) install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/man DESTINATION ${CMAKE_INSTALL_DOCDIR}) endif(GENERATE_MAN)

有没有更好的方法,比如:

foreach(doc_type html;man;qch )
    install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${doc_type} DESTINATION ${CMAKE_INSTALL_DOCDIR})
endforeach()

1 个答案:

答案 0 :(得分:0)

你几乎自己找到了解决方案。 拥有文档字符串列表是可行的方法。

set(doc_types_to_install)

if(GENERATE_MAN)
...
list(APPEND doc_types_to_install "man")
endif()
#continue for other doc_types
foreach(doc_type ${doc_types_to_install})
...
endforeach()