如何使用 CMake 有条件地安装多个 doxygen 生成的文档?
How to install multiple, doxygen-generated documentation conditionally with CMake?
我有一个 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()
您几乎自己找到了解决方案。
有一个文档字符串列表是可行的方法。
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()
我有一个 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()
您几乎自己找到了解决方案。 有一个文档字符串列表是可行的方法。
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()