3

我目前正在尝试设置 CMake 以自动生成我的 Doxygen 文档。我目前使用以下代码。

find_package(Doxygen)
if (DOXYGEN_FOUND)
    configure_file("docs/Doxyfile.in" "${PROJECT_BINARY_DIR}/Doxyfile")
    add_custom_target(docs
                      COMMAND ${DOXYGEN_EXECUTABLE}
                              "${PROJECT_BINARY_DIR}/Doxyfile"
                      SOURCES "${PROJECT_BINARY_DIR}/Doxyfile")
    install(DIRECTORY "${PROJECT_BINARY_DIR}/docs/"
            DESTINATION "docs")
endif()

当您输入make docs它时,它可以正常工作,它会在PROJECT_BINARY_DIR/docs. 当您输入make install时,它将 docs 子目录复制到CMAKE_INSTALL_PREFIX. 但是,当用户不希望生成文档而只是键入make install时,会发生以下错误:

CMake Error at cmake_install.cmake:36 (FILE):
  file INSTALL cannot find "/home/lukas/workspace/TheGame/build/docs".

如何指示install仅在docs构建自定义目标 ( ) 时执行命令(或者如果子目录docs存在于 中PROJECT_BINARY_DIR)?

4

1 回答 1

7

您是否尝试过使用OPTIONAL标志?

install(DIRECTORY "${PROJECT_BINARY_DIR}/docs/" DESTINATION "docs" OPTIONAL)
于 2012-07-06T11:11:13.200 回答