只有在构建自定义目标时才在CMake中安装

时间:2012-07-06 09:56:14

标签: cmake

我正在尝试设置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命令执行?

1 个答案:

答案 0 :(得分:6)

您是否尝试使用OPTIONAL标志?

install(DIRECTORY "${PROJECT_BINARY_DIR}/docs/" DESTINATION "docs" OPTIONAL)