From 87b3c7ec6c904410d8694dd7a69000cc952c7d6c Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Thu, 13 Jan 2022 00:15:55 +0100 Subject: [PATCH] Document template targets --- .github/workflows/build.yml | 2 +- docs/examples/interface.md | 1 + docs/examples/templates.md | 40 +++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 10 ++++++++ tests/cmake.toml | 20 ++++++++++------ tests/interface/cmake.toml | 1 + tests/templates/cmake.toml | 13 +++++++--- tests/templates/src/templates.cpp | 4 ++++ 8 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 docs/examples/templates.md diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4d25124..de67108 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: - name: Test run: | cd build/tests - ctest -C ${{ env.BUILD_TYPE }} + ctest -C ${{ env.BUILD_TYPE }} --verbose - name: Upload artifacts uses: actions/upload-artifact@v2 diff --git a/docs/examples/interface.md b/docs/examples/interface.md index 3e27f87..976ed86 100644 --- a/docs/examples/interface.md +++ b/docs/examples/interface.md @@ -19,6 +19,7 @@ description = "Header-only library" [target.mylib] type = "interface" include-directories = ["include"] +compile-features = ["cxx_std_11"] [target.example] type = "executable" diff --git a/docs/examples/templates.md b/docs/examples/templates.md new file mode 100644 index 0000000..398f061 --- /dev/null +++ b/docs/examples/templates.md @@ -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. + +This page was automatically generated from [tests/templates/cmake.toml](https://github.com/build-cpp/cmkr/tree/main/tests/templates/cmake.toml). diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2cd8411..0b46624 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -78,3 +78,13 @@ add_test( build ) +add_test( + NAME + templates + WORKING_DIRECTORY + "${CMAKE_CURRENT_LIST_DIR}/templates" + COMMAND + $ + build +) + diff --git a/tests/cmake.toml b/tests/cmake.toml index 19efbec..10f46ed 100644 --- a/tests/cmake.toml +++ b/tests/cmake.toml @@ -1,41 +1,47 @@ [[test]] name = "basic" -command = "$" working-directory = "basic" +command = "$" arguments = ["build"] [[test]] name = "interface" -command = "$" working-directory = "interface" +command = "$" arguments = ["build"] [[test]] name = "fetch-content" -command = "$" working-directory = "fetch-content" +command = "$" arguments = ["build"] [[test]] name = "conditions" -command = "$" working-directory = "conditions" +command = "$" arguments = ["build"] [[test]] name = "vcpkg" -command = "$" working-directory = "vcpkg" +command = "$" arguments = ["build"] [[test]] name = "cxx-standard" -command = "$" working-directory = "cxx-standard" +command = "$" arguments = ["build"] [[test]] name = "globbing" -command = "$" working-directory = "globbing" +command = "$" +arguments = ["build"] + +[[test]] +name = "templates" +working-directory = "templates" +command = "$" arguments = ["build"] diff --git a/tests/interface/cmake.toml b/tests/interface/cmake.toml index 1f1c0c7..44588c4 100644 --- a/tests/interface/cmake.toml +++ b/tests/interface/cmake.toml @@ -5,6 +5,7 @@ description = "Header-only library" [target.mylib] type = "interface" include-directories = ["include"] +compile-features = ["cxx_std_11"] [target.example] type = "executable" diff --git a/tests/templates/cmake.toml b/tests/templates/cmake.toml index 4fd5f55..9fce97f 100644 --- a/tests/templates/cmake.toml +++ b/tests/templates/cmake.toml @@ -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] name = "templates" -description = "Template example" +description = "Target templates" [template.app] type = "executable" 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] type = "app" @@ -16,3 +21,5 @@ 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. \ No newline at end of file diff --git a/tests/templates/src/templates.cpp b/tests/templates/src/templates.cpp index 57d0797..e4091b3 100644 --- a/tests/templates/src/templates.cpp +++ b/tests/templates/src/templates.cpp @@ -1,5 +1,9 @@ #include +#if !defined(IS_APP) +#error Something went wrong with the template +#endif // IS_APP + int main() { #if defined(APP_A) puts("Hello from app A!");