Hands-on exercises for a brief CMake tutorial.
The exercises are adapted from the dev-cafe/cmake-cookbook repository and the CodeRefinery CMake lesson.
CMake Cookbook offers a more in-depth discussion of many additional topics.
Introductory slides are rendered here.
Introduce basic CMake commands to successfully compile a project. We will also show how to work with dependencies and switch generators.
Commands discussed:
project
cmake_minimum_required
message
set
option
if
add_executable
find_package
target_link_libraries
target_sources
We will discuss how to structure a project and how to produce libraries, in addition to executables.
Commands discussed:
add_library
We will have a first look at the Catch2 unit test framework and how to use it with CTest.
CMake is not just for C/C++, it can be used also for Fortran projects. In this example we will build a C++/Fortran project. We will also get acquainted with CTest, the testing framework that is part of the CMake suite.
This final example will focus on unit testing and present some of the available C++ frameworks. We will focuse on Catch2 and introduce some of its features.