Document template targets

main
Duncan Ogilvie 3 years ago
parent d905be1d13
commit 87b3c7ec6c

@ -35,7 +35,7 @@ jobs:
- name: Test - name: Test
run: | run: |
cd build/tests cd build/tests
ctest -C ${{ env.BUILD_TYPE }} ctest -C ${{ env.BUILD_TYPE }} --verbose
- name: Upload artifacts - name: Upload artifacts
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2

@ -19,6 +19,7 @@ description = "Header-only library"
[target.mylib] [target.mylib]
type = "interface" type = "interface"
include-directories = ["include"] include-directories = ["include"]
compile-features = ["cxx_std_11"]
[target.example] [target.example]
type = "executable" type = "executable"

@ -0,0 +1,40 @@
---
# Automatically generated from tests/templates/cmake.toml - DO NOT EDIT
layout: default
title: Target templates
permalink: /examples/templates
parent: Examples
nav_order: 7
---
# Target templates
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.
```toml
[project]
name = "templates"
description = "Target templates"
[template.app]
type = "executable"
sources = ["src/templates.cpp"]
compile-definitions = ["IS_APP"]
# Unlike interface targets you can also inherit properties
[template.app.properties]
CXX_STANDARD = "11"
CXX_STANDARD_REQUIRED = true
[target.app-a]
type = "app"
compile-definitions = ["APP_A"]
[target.app-b]
type = "app"
compile-definitions = ["APP_B"]
```
**Note**: In most cases you probably want to use an [interface](/examples/interface) target instead.
<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>

10
tests/CMakeLists.txt generated

@ -78,3 +78,13 @@ add_test(
build build
) )
add_test(
NAME
templates
WORKING_DIRECTORY
"${CMAKE_CURRENT_LIST_DIR}/templates"
COMMAND
$<TARGET_FILE:cmkr>
build
)

@ -1,41 +1,47 @@
[[test]] [[test]]
name = "basic" name = "basic"
command = "$<TARGET_FILE:cmkr>"
working-directory = "basic" working-directory = "basic"
command = "$<TARGET_FILE:cmkr>"
arguments = ["build"] arguments = ["build"]
[[test]] [[test]]
name = "interface" name = "interface"
command = "$<TARGET_FILE:cmkr>"
working-directory = "interface" working-directory = "interface"
command = "$<TARGET_FILE:cmkr>"
arguments = ["build"] arguments = ["build"]
[[test]] [[test]]
name = "fetch-content" name = "fetch-content"
command = "$<TARGET_FILE:cmkr>"
working-directory = "fetch-content" working-directory = "fetch-content"
command = "$<TARGET_FILE:cmkr>"
arguments = ["build"] arguments = ["build"]
[[test]] [[test]]
name = "conditions" name = "conditions"
command = "$<TARGET_FILE:cmkr>"
working-directory = "conditions" working-directory = "conditions"
command = "$<TARGET_FILE:cmkr>"
arguments = ["build"] arguments = ["build"]
[[test]] [[test]]
name = "vcpkg" name = "vcpkg"
command = "$<TARGET_FILE:cmkr>"
working-directory = "vcpkg" working-directory = "vcpkg"
command = "$<TARGET_FILE:cmkr>"
arguments = ["build"] arguments = ["build"]
[[test]] [[test]]
name = "cxx-standard" name = "cxx-standard"
command = "$<TARGET_FILE:cmkr>"
working-directory = "cxx-standard" working-directory = "cxx-standard"
command = "$<TARGET_FILE:cmkr>"
arguments = ["build"] arguments = ["build"]
[[test]] [[test]]
name = "globbing" name = "globbing"
command = "$<TARGET_FILE:cmkr>"
working-directory = "globbing" working-directory = "globbing"
command = "$<TARGET_FILE:cmkr>"
arguments = ["build"]
[[test]]
name = "templates"
working-directory = "templates"
command = "$<TARGET_FILE:cmkr>"
arguments = ["build"] arguments = ["build"]

@ -5,6 +5,7 @@ description = "Header-only library"
[target.mylib] [target.mylib]
type = "interface" type = "interface"
include-directories = ["include"] include-directories = ["include"]
compile-features = ["cxx_std_11"]
[target.example] [target.example]
type = "executable" type = "executable"

@ -1,13 +1,18 @@
# A project using templates. # 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.
[project] [project]
name = "templates" name = "templates"
description = "Template example" description = "Target templates"
[template.app] [template.app]
type = "executable" type = "executable"
sources = ["src/templates.cpp"] sources = ["src/templates.cpp"]
compile-definitions = ["IS_APP=true"] compile-definitions = ["IS_APP"]
# Unlike interface targets you can also inherit properties
[template.app.properties]
CXX_STANDARD = "11"
CXX_STANDARD_REQUIRED = true
[target.app-a] [target.app-a]
type = "app" type = "app"
@ -16,3 +21,5 @@ compile-definitions = ["APP_A"]
[target.app-b] [target.app-b]
type = "app" type = "app"
compile-definitions = ["APP_B"] compile-definitions = ["APP_B"]
# **Note**: In most cases you probably want to use an [interface](/examples/interface) target instead.

@ -1,5 +1,9 @@
#include <cstdio> #include <cstdio>
#if !defined(IS_APP)
#error Something went wrong with the template
#endif // IS_APP
int main() { int main() {
#if defined(APP_A) #if defined(APP_A)
puts("Hello from app A!"); puts("Hello from app A!");

Loading…
Cancel
Save