Skip to content

Commit c785b54

Browse files
committed
Document target templates
1 parent 275b73e commit c785b54

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/cmake-toml.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,29 @@ CXX_STANDARD_REQUIRED = true
212212
FOLDER = "MyFolder"
213213
```
214214

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+
215238
## Tests and installation (unfinished)
216239

217240
**Note**: The `[[test]]` and `[[install]]` are unfinished features and will likely change in a future release.

0 commit comments

Comments
 (0)