问题描述
我的基于CMake的项目由一个.exe
文件和三个.dll
组成,这些文件是使用Visual Studio编译的。我想将这些文件一起以zip格式分发:不包括源代码,没有精美的NSIS安装程序,仅是方便的zip存档中的四个文件。我知道我可以使用add_custom_command
直接在CMake中编写脚本,但是CPack似乎是一个更好的选择。我该怎么办?
解决方法
如果使用CMake(带有install
)指定要安装的文件,则可以轻松利用CPack创建zip存档:
# Specify to install your CMake targets
install(TARGETS MyExe RUNTIME CONFIGURATIONS Release)
install(TARGETS MySharedLib1 RUNTIME CONFIGURATIONS Release)
...
# Specify the CPack generator for packaging files into an archive.
set(CPACK_GENERATOR "ZIP")
# Specify to exclude the top-level directory from the archive.
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
# Now,add CPack to your project.
include(CPack)