I am trying to create debian packages, from CPP sources that are built using CMake.
I am using debuild, I am NOT using cpack.
Till now I have reached the following stage:
debian/rules looks like the following:
%:
dh $@ --buildsystem=cmake
override_dh_auto_configure:
dh_auto_configure -- --no-warn-unused-cli -DPACKAGE_ONE=ON -DPACKAGE_TWO=OFF
debian/control looks like:
Source: blabla
Maintainer: ME <[email protected]>
Section: misc
Priority: optional
Build-Depends:
debhelper-compat (= 12),
cmake (>= 3.10.0),
Package: package1
Architecture: any
Pre-Depends: ${misc:Pre-Depends}
Depends:
${misc:Depends},
${shlibs:Depends},
${debconf:Depends},
unzip
Description: Package 1
The first package.
#Package: package2
#Architecture: any
#Pre-Depends: ${misc:Pre-Depends}
#Depends:
# ${misc:Depends},
# ${shlibs:Depends},
# ${debconf:Depends},
# unzip
#Description: Package 2
# The second package.
A very simplified CMakeLists.txt looks like:
project(blabla)
add_subdirectory(common_dependencies)
if(PACKAGE_ONE)
add_subdirectory(package1)
endif()
if(PACKAGE_TWO)
add_subdirectory(package2)
endif()
add_subdirectory(other_dependencies)
CMakeLists.txt in the respective package1/2
sub-directories takes care of creating the executable, etc...
The problem is that for the result I need to generate two different debian packages (package1.deb, package2.deb) when calling debuild...
But I simply cannot guess how can I build two different debian packages from the same source, using the above requirements, ie: pass in a CMake flag, when there is only one debian/rules file (installing various extra files for the different packages I have sorted out by creating package1.install, package2.install with all the files, images, icons, etc ... they need)
Is this even possible? Thanks!
it's of course possible (and rather common) to build multiple binary packages from a single source package.
debian/control
must list every binary packages that is being created.debian/rules
file, because this file contains the recipe to build everythingso typically you would have a debian/control
like this (note that package2 has been un-commented):
Source: blabla
Maintainer: ME <[email protected]>
Section: misc
Priority: optional
Build-Depends:
debhelper-compat (= 12),
cmake (>= 3.10.0),
Package: package1
Architecture: any
Pre-Depends: ${misc:Pre-Depends}
Depends:
${misc:Depends},
${shlibs:Depends},
${debconf:Depends},
unzip
Description: Package 1
The first package.
Package: package2
Architecture: any
Pre-Depends: ${misc:Pre-Depends}
Depends:
${misc:Depends},
${shlibs:Depends},
${debconf:Depends},
unzip
Description: Package 2
The second package.
your debian/rules
might look like this (note that both packages are built):
%:
dh $@ --buildsystem=cmake
override_dh_auto_configure:
dh_auto_configure -- --no-warn-unused-cli -DPACKAGE_ONE=ON -DPACKAGE_TWO=ON
the only thing that is left is sorting the build artifacts into the two packages.
assume that building with -DPACKAGE_ONE=1
produces an an artifact /usr/bin/package1
and -DPACKAGE_ONE=2
produces an an artifact /usr/bin/package2
when running make install
.
then you need to create/edit some more files, debian/package1.install
and debian/package2.install
that - being very declarative - simply list the files that go into each package.
so debian/package1.install
would contain:
/usr/bin/package1
and debian/package2.install
would contain:
/usr/bin/package2
under the hood, dh
invokes dh_auto_install
which instructs cmake to install all files into DESTDIR=$(pwd)/debian/tmp/
.
this is the place where dh_install
will look for files listed in the various debian/*.install
files and sort them into $(pwd)/debian/<pkgname>/
, before assembling the final package.
there are many ways to tweak all this, but the standard behavior will most likely fit your needs.