使用Cmake创建tar存档 [英] Create tar archive with Cmake

查看:243
本文介绍了使用Cmake创建tar存档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在CMakeLists.txt文件中使用* _OUTPUT_PATH变量为我的二进制文件和库文件指定了特定位置,并且似乎在自动工作。

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.

我需要什么添加来创建tar?

What do I need to add to create a tar?

推荐答案

您可以使用CMake自定义目标在命令模式下调用CMake并产生一个输出目录中的二进制文件中的tarball。这是一个CMakeLists.txt,它描绘了必要的步骤:

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)

自定义target从目录 EXECUTABLE_OUTPUT_PATH 中的文件生成压缩的tarball。 add_dependencies 调用可确保在最终步骤中创建tarball。

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.

要生成未压缩的tarball,请使用选项 cfv 而不是 cfvz

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

这篇关于使用Cmake创建tar存档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆