Skip to content

Commit 87b3c7e

Browse files
committed
Document template targets
1 parent d905be1 commit 87b3c7e

File tree

8 files changed

+80
-11
lines changed

8 files changed

+80
-11
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Test
3636
run: |
3737
cd build/tests
38-
ctest -C ${{ env.BUILD_TYPE }}
38+
ctest -C ${{ env.BUILD_TYPE }} --verbose
3939
4040
- name: Upload artifacts
4141
uses: actions/upload-artifact@v2

docs/examples/interface.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ description = "Header-only library"
1919
[target.mylib]
2020
type = "interface"
2121
include-directories = ["include"]
22+
compile-features = ["cxx_std_11"]
2223

2324
[target.example]
2425
type = "executable"

docs/examples/templates.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
# Automatically generated from tests/templates/cmake.toml - DO NOT EDIT
3+
layout: default
4+
title: Target templates
5+
permalink: /examples/templates
6+
parent: Examples
7+
nav_order: 7
8+
---
9+
10+
# Target templates
11+
12+
To avoid repeating yourself in targets you can create your own target type (template). All properties of the template are inherited when used as a target type.
13+
14+
```toml
15+
[project]
16+
name = "templates"
17+
description = "Target templates"
18+
19+
[template.app]
20+
type = "executable"
21+
sources = ["src/templates.cpp"]
22+
compile-definitions = ["IS_APP"]
23+
24+
# Unlike interface targets you can also inherit properties
25+
[template.app.properties]
26+
CXX_STANDARD = "11"
27+
CXX_STANDARD_REQUIRED = true
28+
29+
[target.app-a]
30+
type = "app"
31+
compile-definitions = ["APP_A"]
32+
33+
[target.app-b]
34+
type = "app"
35+
compile-definitions = ["APP_B"]
36+
```
37+
38+
**Note**: In most cases you probably want to use an [interface](/examples/interface) target instead.
39+
40+
<sup><sub>This page was automatically generated from [tests/templates/cmake.toml](https://github.com/build-cpp/cmkr/tree/main/tests/templates/cmake.toml).</sub></sup>

tests/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/cmake.toml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
11
[[test]]
22
name = "basic"
3-
command = "$<TARGET_FILE:cmkr>"
43
working-directory = "basic"
4+
command = "$<TARGET_FILE:cmkr>"
55
arguments = ["build"]
66

77
[[test]]
88
name = "interface"
9-
command = "$<TARGET_FILE:cmkr>"
109
working-directory = "interface"
10+
command = "$<TARGET_FILE:cmkr>"
1111
arguments = ["build"]
1212

1313
[[test]]
1414
name = "fetch-content"
15-
command = "$<TARGET_FILE:cmkr>"
1615
working-directory = "fetch-content"
16+
command = "$<TARGET_FILE:cmkr>"
1717
arguments = ["build"]
1818

1919
[[test]]
2020
name = "conditions"
21-
command = "$<TARGET_FILE:cmkr>"
2221
working-directory = "conditions"
22+
command = "$<TARGET_FILE:cmkr>"
2323
arguments = ["build"]
2424

2525
[[test]]
2626
name = "vcpkg"
27-
command = "$<TARGET_FILE:cmkr>"
2827
working-directory = "vcpkg"
28+
command = "$<TARGET_FILE:cmkr>"
2929
arguments = ["build"]
3030

3131
[[test]]
3232
name = "cxx-standard"
33-
command = "$<TARGET_FILE:cmkr>"
3433
working-directory = "cxx-standard"
34+
command = "$<TARGET_FILE:cmkr>"
3535
arguments = ["build"]
3636

3737
[[test]]
3838
name = "globbing"
39-
command = "$<TARGET_FILE:cmkr>"
4039
working-directory = "globbing"
40+
command = "$<TARGET_FILE:cmkr>"
41+
arguments = ["build"]
42+
43+
[[test]]
44+
name = "templates"
45+
working-directory = "templates"
46+
command = "$<TARGET_FILE:cmkr>"
4147
arguments = ["build"]

tests/interface/cmake.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ description = "Header-only library"
55
[target.mylib]
66
type = "interface"
77
include-directories = ["include"]
8+
compile-features = ["cxx_std_11"]
89

910
[target.example]
1011
type = "executable"

tests/templates/cmake.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
# A project using templates.
1+
# To avoid repeating yourself in targets you can create your own target type (template). All properties of the template are inherited when used as a target type.
22

33
[project]
44
name = "templates"
5-
description = "Template example"
5+
description = "Target templates"
66

77
[template.app]
88
type = "executable"
99
sources = ["src/templates.cpp"]
10-
compile-definitions = ["IS_APP=true"]
10+
compile-definitions = ["IS_APP"]
11+
12+
# Unlike interface targets you can also inherit properties
13+
[template.app.properties]
14+
CXX_STANDARD = "11"
15+
CXX_STANDARD_REQUIRED = true
1116

1217
[target.app-a]
1318
type = "app"
@@ -16,3 +21,5 @@ compile-definitions = ["APP_A"]
1621
[target.app-b]
1722
type = "app"
1823
compile-definitions = ["APP_B"]
24+
25+
# **Note**: In most cases you probably want to use an [interface](/examples/interface) target instead.

tests/templates/src/templates.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include <cstdio>
22

3+
#if !defined(IS_APP)
4+
#error Something went wrong with the template
5+
#endif // IS_APP
6+
37
int main() {
48
#if defined(APP_A)
59
puts("Hello from app A!");

0 commit comments

Comments
 (0)