How to create debian package with CPack command (not from CMake's files)?

Viewed 3286

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 Answers

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).

Related