2
votes

I have CMake project built and installed. Now I want to generate debian package (*.deb) from this. In the Internet there are many instructions how to create debian package with adding something to CMake's files, but the project, which I've built does not belongs to me, so I shouldn't modify its source. I've found command cpack, which is can also generate deb packages. Unfortunately when I try to use the command:

cpack -G DEB -C cmake/build/directory -P myPackage.deb -R 1.0.

I see:

CPack Error: Please specify build tree of the project that uses CMake using CPACK_INSTALL_CMAKE_PROJECTS, specify CPACK_INSTALL_COMMANDS, CPACK_INSTALL_SCRIPT, or CPACK_INSTALLED_DIRECTORIES.

Unfortunately the options can't be specified in commands in help:

cpack --help

So is it possible to generate debian package with command cpack without any changes to CMake files?

1
"So is it possible to generate debian package with command cpack without any changes to CMake files?" - Probably, yes, you could use CPack without CMake project. But you are right, that CPack commands are simply not described in the official documentation. The same is true for other CMake derivatives like CTest.Tsyvarev
"but the project, which I've built does not belongs to me, so I shouldn't modify its source." - Unsure about legal issues, but there are ways for modify the project's files and still be able to synchronize them with the project's repo. E.g. you may create a patch and apply it when you want to pack the project. If you want to create CMake project which drives packaging of external project, you may use ExternalProject_Add command for that purpose. Its option PATCH_COMMAND may be used for applying the patch.Tsyvarev

1 Answers

3
votes

When the CMakeLists.txt includes the CPack module, it produces CPackConfig.cmake in the top build directory. This config file is the default for CPack, but you can override it w/ --config option.

The file consists of a bunch of set() commands to set various CPACK_* variables. To produce a package (the DEB in your question) you ought to write the config file "manually" and set vital variables for CPack, as well as some for DEB generator (i.e. CPACK_DEBIAN_*).

Generally, this config (the variables in it) describes what project(s) and it's components to include to package(s), define some meta-data & so on... In theory, you can pass all that defines via -D options to cpack(1). In practice, IMHO, it'll be easier to write the CPackConfig.cmake %)

Having that config file this command should to what you want:

$ cpack -G DEB

(or just cpack alone if your config describes only Debian package to build).