Create tar archive with Cmake

扶醉桌前 提交于 2020-05-13 03:51:05

问题


I have used the *_OUTPUT_PATH variables in my CMakeLists.txt file to specify specific locations for my binaries and library files, and that seems to be working "automatically"

I would like as part of a "build" for one final step to happen, which is to create a tarball of the binaries that output directory.

What do I need to add to create a tar?


回答1:


You can use a CMake custom target to invoke CMake in command mode and have it produce a tarball from the binaries in the output directory. Here is a CMakeLists.txt that sketches the necessary steps:

project(TarExample)

set (EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/executables")
add_executable(foo foo.cpp)

add_custom_target(create_tar ALL COMMAND
    ${CMAKE_COMMAND} -E tar "cfvz" "executables.tgz" "${EXECUTABLE_OUTPUT_PATH}")
add_dependencies(create_tar foo)

The custom target generates a gzipped tarball from the files in the directory EXECUTABLE_OUTPUT_PATH. The add_dependencies call ensures that the tarball is created as a final step.

To produce an uncompressed tarball, use the option cfv instead of cfvz.



来源:https://stackoverflow.com/questions/13477585/create-tar-archive-with-cmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!