Skip to content

Commit 83559cc

Browse files
committed
Improve target reference documentation
1 parent 5d85cc8 commit 83559cc

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

docs/cmake-toml.md

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,28 +218,28 @@ Table keys that match CMake variable names (`[A-Z_]+`) will be passed to the [`F
218218
[target.mytarget]
219219
condition = "mycondition"
220220
alias = "mytarget::mytarget"
221-
type = "static" # executable, shared (DLL), static, interface, object, library, custom
221+
type = "static" # executable, library, shared (DLL), static, interface, object, custom
222222
headers = ["src/mytarget.h"]
223223
sources = ["src/mytarget.cpp"]
224224
msvc-runtime = "" # dynamic (implicit default), static
225225

226226
# The keys below match the target_xxx CMake commands
227227
# Keys prefixed with private- will get PRIVATE visibility
228-
compile-definitions = [""]
228+
compile-definitions = [""] # preprocessor define (-DFOO)
229229
private-compile-definitions = [""]
230-
compile-features = [""]
230+
compile-features = [""] # C++ standard version (cxx_std_20)
231231
private-compile-features = [""]
232-
compile-options = [""]
232+
compile-options = [""] # compiler flags
233233
private-compile-options = [""]
234-
include-directories = [""]
234+
include-directories = [""] # include paths/directories
235235
private-include-directories = [""]
236-
link-directories = [""]
236+
link-directories = [""] # library directories
237237
private-link-directories = [""]
238-
link-libraries = [""]
238+
link-libraries = [""] # dependencies
239239
private-link-libraries = [""]
240-
link-options = [""]
240+
link-options = [""] # linker flags
241241
private-link-options = [""]
242-
precompile-headers = [""]
242+
precompile-headers = [""] # precompiled headers
243243
private-precompile-headers = [""]
244244

245245
cmake-before = """
@@ -258,6 +258,35 @@ CXX_STANDARD_REQUIRED = true
258258
FOLDER = "MyFolder"
259259
```
260260

261+
A table mapping the cmkr features to the relevant CMake construct and the relevant documentation pages:
262+
263+
| cmkr | CMake construct | Description |
264+
| ---- | ----- | ----------- |
265+
| `alias` | [Alias Libraries](https://cmake.org/cmake/help/latest/command/add_library.html#alias-libraries) | Create an [alias target](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#alias-targets), used for namespacing or clarity. |
266+
| `sources` | [`target_sources`](https://cmake.org/cmake/help/latest/command/target_sources.html) | Source files (`PRIVATE` except `interface` targets). |
267+
| `headers` | [`target_sources`](https://cmake.org/cmake/help/latest/command/target_sources.html) | For readability (and future packaging). |
268+
| `msvc-runtime` | [`MSVC_RUNTIME_LIBRARY`](https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html) | The [CMP0091](https://cmake.org/cmake/help/latest/policy/CMP0091.html) policy is set automatically. |
269+
| `compile-definitions` | [`target_compile_definitions`](https://cmake.org/cmake/help/latest/command/target_compile_definitions.html) | Adds a macro definition (define, `-DMYMACRO=XXX`). |
270+
| `compile-features` | [`target_compile_features`](https://cmake.org/cmake/help/latest/command/target_compile_features.html) | Specifies the C++ standard version (`cxx_std_20`). |
271+
| `compile-options` | [`target_compile_options`](https://cmake.org/cmake/help/latest/command/target_compile_options.html) | Adds compiler flags. |
272+
| `include-directories` | [`target_include_directories`](https://cmake.org/cmake/help/latest/command/target_include_directories.html) | Adds include directories. |
273+
| `link-directories` | [`target_link_directories`](https://cmake.org/cmake/help/latest/command/target_link_directories.html) | Adds library directories. |
274+
| `link-libraries` | [`target_link_libraries`](https://cmake.org/cmake/help/latest/command/target_link_libraries.html) | Adds library dependencies. |
275+
| `link-options` | [`target_link_options`](https://cmake.org/cmake/help/latest/command/target_link_options.html) | Adds linker flags. |
276+
| `precompile-headers` | [`target_precompile_headers`](https://cmake.org/cmake/help/latest/command/target_precompile_headers.html) | Specifies precompiled headers. |
277+
| `properties` | [`set_target_properties`](https://cmake.org/cmake/help/latest/command/set_target_properties.html) | See [properties on targets](https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets) for more information. |
278+
279+
The default [visibility](/basics) is as follows:
280+
281+
| Type | Visibility |
282+
| ------------ | ----------- |
283+
| `executable` | `PRIVATE` |
284+
| `library` | `PUBLIC` |
285+
| `shared` | `PUBLIC` |
286+
| `static` | `PUBLIC` |
287+
| `object` | `PUBLIC` |
288+
| `interface` | `INTERFACE` |
289+
261290
## Templates
262291

263292
To avoid repeating yourself you can create your own target type and use it in your targets:

docs/examples/compile-options.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ nav_order: 9
99

1010
# Compiler flags
1111

12-
Example project that sets compiler/linker flags for various platforms.
12+
Example project that sets compiler flags and preprocessor defines for various platforms.
1313

1414
```toml
1515
[project]
@@ -20,11 +20,14 @@ description = "Compiler flags"
2020
type = "executable"
2121
sources = ["src/main.cpp"]
2222
msvc.compile-options = ["/W2"]
23+
msvc.compile-definitions = ["PLATFORM=\"msvc\""]
2324
gcc.compile-options = ["-Wall"]
25+
gcc.compile-definitions = ["PLATFORM=\"gcc\""]
2426
clang.compile-options = ["-Wall"]
27+
clang.compile-definitions = ["PLATFORM=\"clang\""]
2528
```
2629

27-
The `hello` target uses [conditions](/cmake-toml#conditions) to set different compiler flags depending on the platform. See the [targets](/cmake-toml/#targets) documentation for other things you can set.
30+
The `hello` target uses [conditions](/cmake-toml#conditions) to set different compiler flags and definitions depending on the platform. See the [targets](/cmake-toml/#targets) documentation for other things you can set.
2831

2932
_Note_: In general you only want to specify flags _required_ to compile your code without errors.
3033

tests/compile-options/cmake.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Example project that sets compiler/linker flags for various platforms.
1+
# Example project that sets compiler flags and preprocessor defines for various platforms.
22

33
[project]
44
name = "compile-options"
@@ -8,8 +8,11 @@ description = "Compiler flags"
88
type = "executable"
99
sources = ["src/main.cpp"]
1010
msvc.compile-options = ["/W2"]
11+
msvc.compile-definitions = ["PLATFORM=\"msvc\""]
1112
gcc.compile-options = ["-Wall"]
13+
gcc.compile-definitions = ["PLATFORM=\"gcc\""]
1214
clang.compile-options = ["-Wall"]
15+
clang.compile-definitions = ["PLATFORM=\"clang\""]
1316

14-
# The `hello` target uses [conditions](/cmake-toml#conditions) to set different compiler flags depending on the platform. See the [targets](/cmake-toml/#targets) documentation for other things you can set.
17+
# The `hello` target uses [conditions](/cmake-toml#conditions) to set different compiler flags and definitions depending on the platform. See the [targets](/cmake-toml/#targets) documentation for other things you can set.
1518
# _Note_: In general you only want to specify flags _required_ to compile your code without errors.

0 commit comments

Comments
 (0)