从add_custom_target将目录复制到另一个目录

时间:2015-04-14 01:19:52

标签: cmake

我有这个目标代码:

add_custom_target (
        dist
        COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}"
        COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/CMakeLists.txt ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}
        COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}
        COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/data ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}
        COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/po ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}
        COMMAND ${7Z} a -t7z ${PACKER_PACKAGE_FILE_NAME_EXT} ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}
        COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}"
        COMMENT "${PACKER_PACKAGE_FILE_NAME_EXT} created"
    )

我的目标是将目录(及其内容)复制到我的目录${PROJECT_BINARY_DIR}/${PROJECT_NAME}-${PROJECT_VERSION}。目录中唯一的文件是CMakeLists.txt,其余的只是一堆空的" src","数据"和" po"文件,任何想法

2 个答案:

答案 0 :(得分:0)

你做错了。有一种更好的方法来生成分发tarball。 使用install命令和CPack模块。 Here您可以通过示例项目找到关于CPack的简短教程。

答案 1 :(得分:0)

如果要复制目录,则应使用cmake -E copy_directory

但是如果你想创建一个源包,请查看cpack,它也可以创建源包。