tl;dr version: is it possible with CMake (>= 2.8) to generate zip files from some files and put the packed zip file in a specific location?
longer version: I have a CMakeLists.txt that build my project to a .exe file. And this exe file will read data from a zip file. Now it is so that the content to be packed in the zip file is in my git repository so that it can be edited, too. But the program needs this data in a zip file. So it would be good if the cmake script could take the data, put it in a zip file and place it next to the exe. I already heard of CPack, but I did not found easy examples and am not sure if this is even the right tool for my task.
Is this possible? If yes: how?
It's never late to show real answer:
Use like
This will pack all files from
zip/
subdirectory intonative_data.zip
(in build directory). Then either include your archive (path will differ in differentCMakeLists.txt
!) as source file or add it as target:Install will not differ a lot from usual:
Essentially what I did was create custom target
With this target I copy the files and directories to the
CMAKE_CURRENT_BINARY_DIR
The important line
inside my
I specify all the files I want to include in my zip
I can now execute the command
which will copy and zip everything i need
I assume you already have a zip-tool installed (WinZip or 7z, etc.). You could write a find_zip-tool script which will search for WinZip, or 7Z, etc...
Snippet for WinZip:
Snippet for 7-zip:
Take a look at the file
it shows how CPack searches for a Zip_Executable and prepares some "useful" default flags.
After that, I would suggest to execute_process, similar to sakra's answer
Since version 3.2 CMake has the functionality to generate a zip file built-in. The CMake command-line mode sub-command
tar
supports both the creation of zip and 7zip archives.For example, if the current CMake source directory contains the file
testfile.txt
and the directorytestdir
, you can use the following CMake commands to create a zip file containing both items:As a work-around for earlier CMake versions, you can use the jar command that is part of a standard Java JRE installation.
The zip file will be generated in the current CMake binary dir (
CMAKE_CURRENT_BINARY_DIR
).