Skip to content

Commit a8d6b15

Browse files
authored
Merge pull request #47 from cursey/templates
Add support for target templates
2 parents 61851d2 + 87b3c7e commit a8d6b15

File tree

13 files changed

+366
-203
lines changed

13 files changed

+366
-203
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

CMakeLists.txt

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

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>

include/enum_helper.hpp

Lines changed: 0 additions & 69 deletions
This file was deleted.

include/project_parser.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ enum TargetType {
5656
target_interface,
5757
target_custom,
5858
target_object,
59+
target_template,
60+
target_last,
5961
};
6062

63+
extern const char *targetTypeNames[target_last];
64+
6165
struct Target {
6266
std::string name;
63-
TargetType type = {};
67+
TargetType type = target_last;
68+
std::string type_name;
6469

6570
ConditionVector headers;
6671
ConditionVector sources;
@@ -100,6 +105,12 @@ struct Target {
100105
ConditionVector include_after;
101106
};
102107

108+
struct Template {
109+
Target outline;
110+
std::string add_function;
111+
bool pass_sources_to_add_function = false;
112+
};
113+
103114
struct Test {
104115
std::string name;
105116
std::string condition;
@@ -160,6 +171,7 @@ struct Project {
160171
std::vector<Package> packages;
161172
Vcpkg vcpkg;
162173
std::vector<Content> contents;
174+
std::vector<Template> templates;
163175
std::vector<Target> targets;
164176
std::vector<Test> tests;
165177
std::vector<Install> installs;

0 commit comments

Comments
 (0)