You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/basics.md
+35-6Lines changed: 35 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ nav_order: 1
6
6
7
7
# Basics
8
8
9
-
To effectively use cmkr it helps to understand the basic concepts of CMake.
9
+
To effectively use cmkr it helps to understand the basic concepts of CMake. This page serves as an introduction to CMake for beginners. Links to the CMake documentation are included for reference.
10
10
11
11
## Projects
12
12
@@ -16,11 +16,11 @@ A CMake **project** is a collection of targets. In the context of libraries the
16
16
17
17
## Targets
18
18
19
-
The basic unit of CMake is called a **target**. A target (also referred to as [binary target](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#binary-targets) in the CMake documentation) corresponds to an executable or static/dynamic library you can build. There are also [pseudo targets](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#pseudo-targets), but we ignore them for now.
19
+
The basic unit of CMake is called a **target**. A target (also referred to as [binary target](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#binary-targets) in the CMake documentation) corresponds to an executable or static/dynamic library you can build.
20
20
21
21
<sub>Visual Studio: a **target** corresponds to a _project_.</sub>
22
22
23
-
Target types:
23
+
Most important target types:
24
24
25
25
|Type|Purpose|
26
26
|-|-|
@@ -29,9 +29,11 @@ Target types:
29
29
|Dynamic library|Library code loaded at runtime (`.dll`, `.so`, `.dylib`)|
30
30
|Interface|Used for organizational purposes (common flags/includes/libraries)|
31
31
32
+
There are also other [pseudo targets](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#pseudo-targets), but they are not important for now.
33
+
32
34
## Target Properties
33
35
34
-
Targets have a collection of **properties** that describe how to build them.
36
+
Targets have a collection of **properties** that describe how the compiler builds them.
35
37
36
38
The most commonly-used properties:
37
39
@@ -45,9 +47,9 @@ The most commonly-used properties:
45
47
46
48
<sub>See the [CMake documentation](https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets) for an exhaustive list of target properties.</sub>
47
49
48
-
**Important**: The term **link** has a slightly different meaning in CMake than you might expect. In addition to adding a library to the command line of the linker, CMake also (transitively) propagates properties of the target you link to based on their _visibility_.
50
+
**Important**: The term **link** has a slightly different meaning in CMake than you might expect. In addition to adding a library to the command line, CMake also (transitively) propagates properties of the target you link to based on their _visibility_.
49
51
50
-
<sub>You can think of **linking** as _depending on_.</sub>
52
+
You should think of **linking**in CMake as _depending on_.{:.info}
51
53
52
54
The propagation of properties depends on their **visibility**:
3.**Build**: Execute the compiler to produce executables/libraries.
128
+
129
+
CMake keeps generated files separate from your source in a **build directory**. You specify a [**generator**](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html) (Visual Studio/Ninja) and [**build type**](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#build-configurations) (Debug/Release) during configuration.
130
+
131
+
```bash
132
+
# Configure project and generate build files in build directory
133
+
cmake -B build -DCMAKE_BUILD_TYPE=Release
134
+
135
+
# Build the project
136
+
cmake --build build --config Release
137
+
```
138
+
139
+
We specify both `CMAKE_BUILD_TYPE` and `--config` to be compatible with generators (like Visual Studio/Xcode) that allow multiple configurations at once.{:.info}
140
+
141
+
**Build Types**:
142
+
-`Debug`: No optimization, debug symbols
143
+
-`Release`: Full optimization, no debug symbols
144
+
-`RelWithDebInfo`: Medium optimizations, debug symbols
145
+
-`MinSizeRel`: Optimize for size, no debug symbols
146
+
147
+
**Generators**: CMake auto-detects (Makefiles on Linux/macOS, Visual Studio on Windows), but you can specify explicitly with `-G` during the _configure_ step.
0 commit comments