Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create tar archive with Cmake

Tags:

makefile

cmake

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?

like image 692
Derek Avatar asked Nov 20 '12 16:11

Derek


1 Answers

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.

like image 170
sakra Avatar answered Nov 12 '22 21:11

sakra