CMake (2026-08-19 - 2026-08-20)#

Day 1: Basics#

Basic material, mandatory:

Final agenda point for day 1: have a look in Agenda: CMake (2026-08-19 - 2026-08-20), and discuss topics for day 2.

Day 2: Less Structured, More Practical#

The participants were well able to follow everything, and I was busy upholding my well-structured agenda against their demands 🥷. I really enjoyed day 2: much dynamicity, much live-hacking, less slide-presenting - all in all leading to severe trainer exhaustion.

Yesterday’s Exercise Solution#

Structure: public/, private/, src/#

Following the screenplay, we restructured the project into something that had more structure. Emphasis was put on when to use PRIVATE to reach one node’s own header files vs. INTERFACE to export usage requirements to using nodes.

For an immediate outcome it is probably best to look into the screenplay’s solution (https://codeberg.org/jfasch/cmake-public-private-src).

Find-Modules: SQLite3#

CMake comes with many “find modules”; show how to use FindSQLite3. Relevant places to look:

Hand-Writing A Find-Module#

  • Step 1: for the purpose of integrating our own project into another project, I created a simple brute-force find-module that is installed together with the project’s artifacts for use by others. It requires a little CMake programming knowledge, though, which I presented as necessary. See The Language for more.

    Relevant places:

    Build and install:

    $ cmake -DCMAKE_INSTALL_PREFIX=/home/jfasch/My-Installs/deployment ~/My-Projects/2026-08-19-gluehwein
    $ make
    $ make install
    
  • Step 2: use our project from another project. We quickly created such a project (here); it only contains one trivial program that uses our project via the find-module from step1.

    cmake_minimum_required(VERSION 3.16)
    project(DecadentlyCookingWine)
    
    find_package(Gluehwein REQUIRED)     # <-- HERE
    
    add_executable(cook-it cook-it.cpp)
    target_link_libraries(
      cook-it
      Gluehwein::Gluehwein               # <-- AND HERE
    )
    

    Build and use cookery from what’s installed/deployed in /home/jfasch/My-Installs/deployment. We are using a FindGluehwein.cmake from a non-standard location, so we pass CMAKE_MODULE_PATH. The find-module is passed that location too which we also have to pass, separately, unfortunately.

    $ cmake \
        -DCMAKE_MODULE_PATH=/home/jfasch/My-Installs/deployment/share/Modules \
        -DDEPLOYMENT_DIR=/home/jfasch/My-Installs/deployment \
        \
        ~/My-Projects/2026-08-19-gluehwein-user
    $ make
    
../../../../_images/using-gluehwein.svg

Note

Conan is a package manager for C/C++, and probably better suited for such tasks.

CMake Function gluehwein_add_library()#

To defend against code explosion, one usually writes functions to eliminate duplicate code. This is what we did near the end of day 2.

Relevant places: