I am considering to create a Debian package from an existing library (paho-mqtt-c). The project uses CMake as its build system. After some research I think I need to create two or three different packages:
- libpaho-mqtt3 (with library .so files and related stuff)
- libpaho-mqtt3-dev (with header files)
- also maybe I need a third package with sample files or documentation (called
paho-mqtt3
?)
I have done some research and it seems there exist at least three different ways how I can create a Debian package when I use CMake as my build system:
- Use debmake procedure described in Debian documentation (Chapter 8).
- Use cmake-debhelper.
- Use dh-cmake
I have looked into all three methods and it seems each has some advantages and disadvantages.
Debmake
As far as I have understood using debmake assumes I have an upstream tarball with the sources and the build system and then I invoke debmake on the extracted tarball. Afterwards I get a lot of templates which I need to manually adjust to fill in the missing gaps. I started doing this but it seems quite complex.
cmake-debhelper
I tried to use it but received lots of errors. The github page has an open issue with no solution so I stopped looking at this. This is also what the paho-mqtt-c
build system is currently using, but it does not work due to the issue linked.
dh-cmake
I briefly looked into this and it seems to be the most modern solution and it should be possible to combine this with CPack. However, it seems dh-cmake is only available for Ubuntu 18.04 and 16.04, but I am using Ubuntu 19.10 so I was not able to install dh-cmake on my system.
Have I missed anything in my research? What are the recommended steps to create a Debian package from a software managed with CMake and which documentation is useful to read?
2
Answers
In short, on Ubuntu you need to create at least these files:
And then run
debuild
and it will runcmake install
to temporary folder and pack an installabledeb
package from it.To quickly create those
debian
files rundh_make --createorig
and presss
for source package.Then you’ll need to carefully edit debian files as described in Chapter 4. Required files under the debian directory
of Debian New Maintainers’ Guide.
If you need to set cmake properties or make any other configuration then you’ll need to adjust
override_dh_auto_configure
inrules
:Here the
-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)
and-DIWINFO_SUPPORT=OFF
will be directly passed to cmake.You can then upload your package to Ubuntu PPA:
After that PPA build bot will compile and publish your package to PPA and you’ll see them on https://launchpad.net/~your-launchpad-user/+archive/ubuntu/your-ppa/+packages
Unfortunately there is a lot of other steps, I just described briefly.
The dh-cmake is needed for more sophisticated things. CPack won’t work for you if you want to publish to PPA because its buildbot will anyway run debhelper (short version of debuild) so it needs for the
debian
folderor you could use
cpack
withcmake
to generate adeb
fairly easy to do but cmake and cpack are poorly documented still they work wellI suggest adding the following to the bottom of CMakeLists.txt
the
postisnt
is to run a script after the install see CMAKE/CPACK:I want to the deb executes a bash script after installed, but it doesn't work for more on that.