Let us try to package the code from the CMake exercise with CPack, such that we can give the (binary) software to somebody else.
Deadline: December 11, 2024, 9:00
- The goal of the exercise is to open a pull request from a fork of the CPack exercise repository. Please name your pull request
Add installation and packaging targets
. In the pull request description, please explain what we need to do to test your code. If you work on any of the optional tasks below, please document in the description as well. - The current state of the code is basically a solution of the CMake exercise from last week. For demonstration purpose the code is now, however, artificially split into a library
cpackexamplelib
and an executablecpackexample
. - Your task is to develop a CMake/CPack configuration that allows generating a
.tar.gz
and a Debian.deb
package of the code. To this end, follow the same four steps as in the lecture (details below).
- Fork and clone the repository.
- Build the Docker image:
docker build -t IMAGENAME .
(might take a few minutes, continue reading already) - Take a look at the
CMakeLists.txt
file. It should look familiar. - Once the Docker image is ready, run it and mount the current directory:
docker run --rm -it --mount type=bind,source="$(pwd)",target=/mnt/cpack-exercise IMAGENAME
- In the Docker container: build the code and run
cpackexample
.
The same four steps as in the lecture:
- The executable
cpackexample
should be installed in a<prefix>/bin/
directory, the librarylibcpackexamplelib.a
orlibcpackexamplelib.so
should be installed in a<prefix>/lib/
directory, and all header files (fem.hpp
,filesystem.hpp
,flatset.hpp
,yamlParser.hpp
) should be installed in a<prefix>/include/cpackexamplelib
directory. - Test whether
make install
works as expected.
- Write a separate CMake module
cmake/CPackConfig.cmake
for the packaging process and include it in theCMakeLists.txt
file. The created package should contain sufficient information about the package, at least: maintainer, contact, project description, vendor, and homepage (e.g. your fork on GitHub). Feel free to set more additional options. make package
should (only) create atar.gz
and adeb
package.- Inspect that both packages contain the correct content:
-
To inspect the contents of a
.tar.gz.
file, you can unpack it using the tooltar
:tar -xzf TARGZFILE
-
To inspect the contents of a
.deb
file, you can unpack it using the tooldpkg-deb
:dpkg-deb -R DEBFILE DIRECTORY_FOR_UNPACKED_DEBFILE
-
- Extend the configuration for the generation of Debian packages. Make sure that the package file name is generated according to the Debian package naming scheme.
- Make sure that you can install the Debian package (
apt install ./DEBFILENAME
) and that you can run the executablecpackexample
. The executable should now be located in/usr/bin
. - Optional: Inspect the content of the Debian package again. Do the dependencies look correct? Modify the Dockerfile such that
libyaml-cpp
also properly appears as dependency.
- Inspect your Debian package with lintian:
lintian ./DEBFILENAME
. Check and save the output (report in pull request). - Make sure that your compiled code gets stripped.
- Optional: Create your package once with stripped and once with unstripped files. This should show a difference in file size, which you can check, for example, with
du -h FILENAME
. - Optional: Fix more errors and warnings (not necessarily all). Add the initial and the final output of
lintian
to the pull request such that we can see what errors or warnings disappeared. Briefly describe in the pull request what you did to get rid of errors and warnings.
Let us completely automatize the package creation using the Docker image. Simply running a container via docker run
should automatically build and save the created packages at a predefined location. No further user interaction should be necessary. Once the container exits, the tar.gz
and deb
packages should be present on the host system. However, no build
directory or other temporary files should be present on the host system, i.e., make sure the package is not created in the mounted drive. Please package cpackexamplelib
as shared library when creating the packages.
Extend the Dockerfile accordingly. Please state the actual command that has to be used to run the container in the pull request.