CMake: Advanced Topics (2024-06-11)¶
Day 1¶
Basics¶
From CMake: Introduction
Exercise: Build It!¶
Add CMake build to existing source code in https://github.com/jfasch/2024-06-11/tree/main/exercises/straightforward

Bringing CMake Information Into C/C++¶
Day 2¶
Morning Awakening¶
Someone to show how WSL can be used.
Continue discussion from yesterday: how do I include file from the local directory?
#include "file.h"
#include <file.h>
⟶
target_include_directories(... INTERFACE ...)
More About Dependencies¶
Much More … (Various Kinds Of Dependencies)¶
Demo project: https://github.com/jfasch/2024-06-11/tree/main/livecoding/kinds-of-dependencies

![digraph "dummy" {
node [
fontsize = "12"
];
subgraph clusterLegend {
label = "Legend";
color = black;
edge [ style = invis ];
legendNode0 [ label = "Executable", shape = egg ];
legendNode1 [ label = "Static Library", shape = octagon ];
legendNode2 [ label = "Shared Library", shape = doubleoctagon ];
legendNode3 [ label = "Module Library", shape = tripleoctagon ];
legendNode4 [ label = "Interface Library", shape = pentagon ];
legendNode5 [ label = "Object Library", shape = hexagon ];
legendNode6 [ label = "Unknown Library", shape = septagon ];
legendNode7 [ label = "Custom Target", shape = box ];
legendNode0 -> legendNode1 [ style = solid ];
legendNode0 -> legendNode2 [ style = solid ];
legendNode0 -> legendNode3;
legendNode1 -> legendNode4 [ label = "Interface", style = dashed ];
legendNode2 -> legendNode5 [ label = "Private", style = dotted ];
legendNode3 -> legendNode6 [ style = solid ];
legendNode0 -> legendNode7;
}
"node0" [ label = "a", shape = egg ];
"node1" [ label = "b", shape = doubleoctagon ];
"node2" [ label = "c", shape = pentagon ];
"node1" -> "node2" // b -> c
"node3" [ label = "d", shape = octagon ];
"node1" -> "node3" [ style = dotted ] // b -> d
"node0" -> "node1" [ style = dotted ] // a -> b
}](../../../../_images/graphviz-bbc7df4242e59e351d5cbf64d7accbed7cb77ea3.png)
Various kinds of property propagation (
PUBLIC
,PRIVATE
,INTERFACE
)add_library()
variationsSHARED
: b/CMakeLists.txtINTERFACE
: c/CMakeLists.txt
Aggregating static libraries into shared libraries
Static library as position independent code: d/CMakeLists.txt
Shared library depends on static library: b/CMakeLists.txt
The CMake Language¶
From The Language
Exercise
Write a CMake script (see Scripts) that receives as input parameters
A directory name
INPUT_DIR
A filename
OUTPUT_FILE
It reads all directory entries from
INPUT_DIR
, transforms those names into their filename-only part (e.g./a/b/c.txt
->c.txt
), and writes those names toOUTPUT_FILE
Day 3¶
Morning Awakening¶
Recap https://github.com/jfasch/2024-06-11/tree/main/exercises/ausbaufaehig
Create build directory and all that
Graph
Include paths (
make VERBOSE=1
)Remember building a shared library from a subgraph?
The CMake Language, Continued¶
From The Language …
One example of a function …
External Dependencies¶
From CMake: Advanced Topics …