简体   繁体   English

如何使用CPack打包多个cmake构建结果?

[英]How to use CPack to pack several cmake build results?

As I have to build both static and shared library for x86 and arm platform.因为我必须为 x86 和 arm 平台构建静态和共享库。 So with the same CMakeLists.txt, I have to run it four times with different configuration.因此,对于相同的 CMakeLists.txt,我必须以不同的配置运行它四次。 I want to use CPack to pack those libraries to one tar file.我想使用 CPack 将这些库打包到一个 tar 文件中。 However, it seems that only the last cmake build results will be included in the tar file.但是,似乎只有最后的 cmake 构建结果会包含在 tar 文件中。

Is there any idea for this problem?这个问题有什么想法吗?

Here is part of my CMakeLists.txt:这是我的 CMakeLists.txt 的一部分:

install(FILES api_cpp.h api_c.h  DESTINATION api_lib/include)
install(TARGETS lib
ARCHIVE DESTINATION api_lib/${lib_folder}
LIBRARY DESTINATION api_lib/${lib_folder})

INCLUDE(CPack)
SET(CPACK_GENERATOR "TGZ")

Obviously, you use a single-configuration generator -- meaning that you can't have more than one particular build configuration in the same build directory.显然,您使用的是单一配置生成器——这意味着在同一个构建目录中不能有多个特定的构建配置。 Actually the problem exists even for the multi-configuration generators as well (at least for CMake < 3.16).实际上,即使对于多配置生成器也存在问题(至少对于 CMake < 3.16)。

To make a package one ought to run CMake, which generates build files, then build a project, and finally can make a package (eg, w/ make package ).要制作一个包,应该运行 CMake,它生成构建文件,然后构建一个项目,最后可以制作一个包(例如,w/ make package )。 The last action runs CPack, which performs make install DESTDIR=<some-temporary-dir> , and then cpack just compress the directory into an archive.最后一个操作运行 CPack,它执行make install DESTDIR=<some-temporary-dir> ,然后cpack只是将目录压缩到一个存档中。 So, having a build directory with the only configuration it's impossible to have an archive with few of them.因此,拥有一个只有配置的构建目录,不可能有一个包含很少配置的存档。

To make your need possible you ought to run CMake 4 times doing install into the same location and then pack that directory into a package.为了满足您的需求,您应该运行 CMake 4 次,将安装到同一位置,然后将该目录打包到一个包中。 It can be done with CMake+CPack, but IMHO easier to do w/ a trivial shell script :)它可以用 CMake+CPack 来完成,但恕我直言,用一个简单的 shell 脚本更容易做到:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM