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
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -212,6 +212,29 @@ CXX_STANDARD_REQUIRED = true
212
212
FOLDER = "MyFolder"
213
213
```
214
214
215
+
## Templates
216
+
217
+
To avoid repeating yourself you can create your own target type and use it in your targets:
218
+
219
+
```toml
220
+
[template.example]
221
+
condition = "MYPROJECT_BUILD_EXAMPLES"
222
+
type = "executable"
223
+
link-libraries = ["myproject::mylib"]
224
+
add-function = ""
225
+
pass-sources = false
226
+
227
+
# Properties from the template are merged with the ones here
228
+
[target.myexample]
229
+
type = "example"
230
+
sources = ["src/myexample.cpp"]
231
+
```
232
+
233
+
The properties declared on a `template` are the same as the ones you use for targets. The only exceptions are:
234
+
235
+
-`add-function`: Specifies a custom add function. Projects like [pybind11](https://pybind11.readthedocs.io/en/stable/cmake/index.html#new-findpython-mode) have their own `add_xxx` function, which you can specify here.
236
+
-`pass-sources`: Pass sources directly to the add function instead of using `target_sources`.
237
+
215
238
## Tests and installation (unfinished)
216
239
217
240
**Note**: The `[[test]]` and `[[install]]` are unfinished features and will likely change in a future release.
0 commit comments