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/cmake-toml.md
+12-8Lines changed: 12 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,25 +67,29 @@ _Note_: It is generally discouraged to disable the `C` language, unless you are
67
67
68
68
## Conditions
69
69
70
-
You can specify your own conditions and use them in any `condition` field:
70
+
You can specify your own named conditions and use them in any `condition` field:
71
71
72
72
```toml
73
73
[conditions]
74
-
arch64 = "CMAKE_SIZEOF_VOID_P EQUAL 8"
75
-
arch32 = "CMAKE_SIZEOF_VOID_P EQUAL 4"
74
+
ptr64 = "CMAKE_SIZEOF_VOID_P EQUAL 8"
75
+
ptr32 = "CMAKE_SIZEOF_VOID_P EQUAL 4"
76
76
```
77
77
78
-
This will make the `arch64` and `arch32` conditions available with their respective CMake expressions.
78
+
This will make the `ptr64` and `ptr32` conditions available with their respective CMake expressions.
79
+
80
+
**Note**: condition names can only contain lower-case alphanumeric characters (`[0-9a-z]`) and dashes (`-`).
79
81
80
82
You can also prefix most keys with `condition.` to represent a conditional:
81
83
82
84
```toml
83
85
[target]
84
86
type = "executable"
85
87
sources = ["src/main.cpp"]
86
-
windows.sources = ["src/windows_specific.cpp"]
88
+
ptr64.sources = ["src/ptr64_only.cpp"]
87
89
```
88
90
91
+
Instead of a named condition you can also specify a [CMake expression](https://cmake.org/cmake/help/latest/command/if.html#condition-syntax) directly.
92
+
89
93
### Predefined conditions
90
94
91
95
The following conditions are predefined (you can override them if you desire):
@@ -131,7 +135,7 @@ MYPROJECT_SPECIAL_OPTION = { value = true, help = "Docstring for this option." }
131
135
MYPROJECT_BUILD_EXAMPLES = "root"
132
136
```
133
137
134
-
Options correspond to [CMake cache variables](https://cmake.org/cmake/help/book/mastering-cmake/chapter/CMake%20Cache.html) that can be used to customize your project at configure-time. You can configure with `cmake -DMYPROJECT_BUILD_TESTS=ON` to enable the option. Every option automatically gets a corresponding [condition](#conditions).
138
+
Options correspond to [CMake cache variables](https://cmake.org/cmake/help/book/mastering-cmake/chapter/CMake%20Cache.html) that can be used to customize your project at configure-time. You can configure with `cmake -DMYPROJECT_BUILD_TESTS=ON` to enable the option. Every option automatically gets a corresponding [condition](#conditions). Additionally, a normalized condition is created based on the `[project].name` (i.e. `MYPROJECT_BUILD_TESTS` becomes `build-tests`).
135
139
136
140
The special value `root` can be used to set the option to `true` if the project is compiled as the root project (it will be `false` if someone is including your project via `[fetch-content]` or `[subdir]`).
137
141
@@ -149,8 +153,8 @@ Variables emit a [`set`](https://cmake.org/cmake/help/latest/command/set.html) a
0 commit comments