Create tar archive with Cmake

I used the * _OUTPUT_PATH variables in my CMakeLists.txt file to specify specific locations for my binaries and library files and it seems to work "automatically"

I would like, as part of the "assembly", to perform one last step, which is to create a tarball from the binaries that output the directory.

What do I need to add to create tar?

+4
source share
1 answer

You can use the CMake target to invoke CMake in command mode and create a tarball from binary files in the output directory. Here is CMakeLists.txt, which 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 creates a gzipped tarball from the files in the EXECUTABLE_OUTPUT_PATH directory. Calling add_dependencies ensures that the tarball is created as the last step.

To create an uncompressed tarball, use cfv instead of cfvz .

+7
source

Source: https://habr.com/ru/post/1447274/


All Articles