In this exercise, we need to fight. Not everything always works smoothly. This is the only way to really learn how to juggle with dependencies using CMake. We build a program that uses common, representative dependencies as often used in simulation software. We are not so much interested in the program itself, but in what steps are necessary to build the program.
To get an independent and reproducible environment as common ground, we use and, thus repeat, Docker.
Deadline: Wednesday, November 27th, 2024, 9:00
- The goal of the exercise is to open a pull request from a fork of the CMake exercise repository. Please name your pull request
Add building and container recipes
and assign yourself. - Your pull request should add a
Dockerfile
and aCMakeLists.txt
, besides some minor changes inmain.cpp
, such as commenting in some code parts. - From your pull request, it should be possible to create an executable container. After running the container, it should be possible to
cd
intocmake-exercise
and then run thebuild_and_run.sh
script. - Use as many of the currently commented-out additional files, which induce additional dependencies.
- Fork and clone the repository, have a look at the
main.cpp
and theREADME.md
. - Build
main.cpp
manually (e.g.g++ main.cpp -o main
) and run the executable (./main
). - Build a Docker image, run a container (in interactive mode), and repeat steps 1 and 2 within the container.
- Look into and use the
build_and_run.sh
script.
The bare main.cpp
uses several additions, which are located in the following subdirectories, each containing a cpp
and a hpp
file with the same name.
flatset
adds a function to create and modify a flat set using Boost Container and outputs the set. This example is adapted from a cppsecrets blog post.filesystem
adds a function to inspect and output the current directory using Boost Filesystem. This example is adapted from tutorial 4 of Boost Filesystem.fem
defines a class to solve the Poisson problem with the finite-element method (FEM) using deal.II. Output is written to a filesolution.vtk
, which can be visualized with, for example, Paraview. This example is adapted from the tutorial step 3 of deal.II.yamlParser
adds a function to parse a simple yaml file using yaml-cpp and to output the value of the keyversion
. The folder also contains an example fileconfig.yml
.
The code and all dependencies should run in a Docker container based on the ubuntu:24.04
image. As by now, you already know how to set up a basic Docker container, we do no longer provide detailed instructions. We recommend building the Dockerfile incrementally. Start with a rather empty one and install dependencies manually in the interactive mode. Take notes of the commands you use, so you can integrate them into the Dockerfile afterwards and rebuild your image.
Some standard packages available on Aptitude might come handy:
build-essential
cmake
unzip
wget
vim
Add dependencies one by one: Comment in the parts of main.cpp
that are connected to a specific dependency. Then, install the dependency and extend the CMakeLists.txt
. Verify that you can build and run the executable. If everything works, go on and include the next dependency.
- Maybe start with the boost dependencies. Boost Container is a header-only dependency, Boost Filesystem needs to be linked. Both are available in
libboost-all-dev
. There is a CMake module to find boost libraries. - deal.II is available in
libdeal.ii-dev
. deal.II uses some specific CMake macros. - yaml-cpp is an optional bonus task. For some arbitrary reason, we are not happy with the latest release of the software (which would be available through Aptitude), but we want to use exactly version
v0.6.3
directly from GitHub. Get the sources with wget and build and install (make install
) it yourself. Do not forget to add the necessary instructions to the Dockerfile. If libraries in/usr/local/lib
are not found by CMake, please add the path to the environment variableLD_LIBRARY_PATH
.