From 4b300df8d5fb55570bda697437455ead2419942c Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sun, 27 Jun 2021 21:36:01 +0200 Subject: [PATCH] Add some more tests for the documentation --- docs/examples/cxx-standard.md | 27 +++++++++++++++ docs/examples/globbing.md | 35 ++++++++++++++++++++ tests/CMakeLists.txt | 20 +++++++++++ tests/cmake.toml | 14 +++++++- tests/cxx-standard/cmake.toml | 12 +++++++ tests/cxx-standard/src/main.cpp | 8 +++++ tests/globbing/cmake.toml | 18 ++++++++++ tests/globbing/example/src/main.cpp | 7 ++++ tests/globbing/mylib/include/mylib/mylib.hpp | 8 +++++ tests/globbing/mylib/src/mylib/mylib.cpp | 6 ++++ tests/vcpkg/vcpkg.json | 2 +- 11 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 docs/examples/cxx-standard.md create mode 100644 docs/examples/globbing.md create mode 100644 tests/cxx-standard/cmake.toml create mode 100644 tests/cxx-standard/src/main.cpp create mode 100644 tests/globbing/cmake.toml create mode 100644 tests/globbing/example/src/main.cpp create mode 100644 tests/globbing/mylib/include/mylib/mylib.hpp create mode 100644 tests/globbing/mylib/src/mylib/mylib.cpp diff --git a/docs/examples/cxx-standard.md b/docs/examples/cxx-standard.md new file mode 100644 index 0000000..5067e67 --- /dev/null +++ b/docs/examples/cxx-standard.md @@ -0,0 +1,27 @@ +--- +# Automatically generated from tests/cxx-standard/cmake.toml - DO NOT EDIT +layout: default +title: Changing C++ standard +permalink: /examples/cxx-standard +parent: Examples +nav_order: 5 +--- + +# Changing C++ standard + +Require a C++11 compiler for the target `example`. + +```toml +[project] +name = "cxx-standard" +description = "Changing C++ standard" + +[target.example] +type = "executable" +sources = ["src/main.cpp"] +compile-features = ["cxx_std_11"] +``` + +This is equivalent to CMake's [target_compile_features](https://cmake.org/cmake/help/latest/command/target_compile_features.html)`(example PRIVATE cxx_std_11)`. For more information on available C/C++ standards and features see [cmake-compile-features(7)](https://cmake.org/cmake/help/latest/manual/cmake-compile-features.7.html). + +This page was automatically generated from [tests/cxx-standard/cmake.toml](https://github.com/build-cpp/cmkr/tree/main/tests/cxx-standard/cmake.toml). diff --git a/docs/examples/globbing.md b/docs/examples/globbing.md new file mode 100644 index 0000000..5ff0b65 --- /dev/null +++ b/docs/examples/globbing.md @@ -0,0 +1,35 @@ +--- +# Automatically generated from tests/globbing/cmake.toml - DO NOT EDIT +layout: default +title: Globbing sources +permalink: /examples/globbing +parent: Examples +nav_order: 6 +--- + +# Globbing sources + + + +```toml +[project] +name = "globbing" +description = "Globbing sources" + +# Recursively glob in the mylib/ folder +[target.mylib] +type = "static" +alias = "mylib::mylib" +sources = ["mylib/**.hpp", "mylib/**.cpp"] +include-directories = ["mylib/include"] + +# Single-folder glob in example/src/ +[target.example] +type = "executable" +sources = ["example/src/*.cpp"] +link-libraries = ["mylib::mylib"] +``` + +As you can see in the example above you can use `**.ext` to glob recursively and `*.ext` to glob non-recursively. This **does not** generate `file(GLOB ...)` commands, but instead globs when cmkr is run. Files are sorted to give deterministic results regardless of the platform used. + +This page was automatically generated from [tests/globbing/cmake.toml](https://github.com/build-cpp/cmkr/tree/main/tests/globbing/cmake.toml). diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8565573..2cd8411 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -58,3 +58,23 @@ add_test( build ) +add_test( + NAME + cxx-standard + WORKING_DIRECTORY + "${CMAKE_CURRENT_LIST_DIR}/cxx-standard" + COMMAND + $ + build +) + +add_test( + NAME + globbing + WORKING_DIRECTORY + "${CMAKE_CURRENT_LIST_DIR}/globbing" + COMMAND + $ + build +) + diff --git a/tests/cmake.toml b/tests/cmake.toml index ebc12b2..19efbec 100644 --- a/tests/cmake.toml +++ b/tests/cmake.toml @@ -26,4 +26,16 @@ arguments = ["build"] name = "vcpkg" command = "$" working-directory = "vcpkg" -arguments = ["build"] \ No newline at end of file +arguments = ["build"] + +[[test]] +name = "cxx-standard" +command = "$" +working-directory = "cxx-standard" +arguments = ["build"] + +[[test]] +name = "globbing" +command = "$" +working-directory = "globbing" +arguments = ["build"] diff --git a/tests/cxx-standard/cmake.toml b/tests/cxx-standard/cmake.toml new file mode 100644 index 0000000..41250be --- /dev/null +++ b/tests/cxx-standard/cmake.toml @@ -0,0 +1,12 @@ +# Require a C++11 compiler for the target `example`. + +[project] +name = "cxx-standard" +description = "Changing C++ standard" + +[target.example] +type = "executable" +sources = ["src/main.cpp"] +compile-features = ["cxx_std_11"] + +# This is equivalent to CMake's [target_compile_features](https://cmake.org/cmake/help/latest/command/target_compile_features.html)`(example PRIVATE cxx_std_11)`. For more information on available C/C++ standards and features see [cmake-compile-features(7)](https://cmake.org/cmake/help/latest/manual/cmake-compile-features.7.html). \ No newline at end of file diff --git a/tests/cxx-standard/src/main.cpp b/tests/cxx-standard/src/main.cpp new file mode 100644 index 0000000..5d7ecde --- /dev/null +++ b/tests/cxx-standard/src/main.cpp @@ -0,0 +1,8 @@ +#include +#include + +int main() +{ + auto tpl = std::make_tuple(1, 2); + printf("Hello from C++11 %d\n", std::get<0>(tpl)); +} \ No newline at end of file diff --git a/tests/globbing/cmake.toml b/tests/globbing/cmake.toml new file mode 100644 index 0000000..4ec24bb --- /dev/null +++ b/tests/globbing/cmake.toml @@ -0,0 +1,18 @@ +[project] +name = "globbing" +description = "Globbing sources" + +# Recursively glob in the mylib/ folder +[target.mylib] +type = "static" +alias = "mylib::mylib" +sources = ["mylib/**.hpp", "mylib/**.cpp"] +include-directories = ["mylib/include"] + +# Single-folder glob in example/src/ +[target.example] +type = "executable" +sources = ["example/src/*.cpp"] +link-libraries = ["mylib::mylib"] + +# As you can see in the example above you can use `**.ext` to glob recursively and `*.ext` to glob non-recursively. This **does not** generate `file(GLOB ...)` commands, but instead globs when cmkr is run. Files are sorted to give deterministic results regardless of the platform used. \ No newline at end of file diff --git a/tests/globbing/example/src/main.cpp b/tests/globbing/example/src/main.cpp new file mode 100644 index 0000000..a53ccc6 --- /dev/null +++ b/tests/globbing/example/src/main.cpp @@ -0,0 +1,7 @@ +#include +#include + +int main() { + std::cout << mylib::message() << std::endl; + return 0; +} diff --git a/tests/globbing/mylib/include/mylib/mylib.hpp b/tests/globbing/mylib/include/mylib/mylib.hpp new file mode 100644 index 0000000..1cdf48f --- /dev/null +++ b/tests/globbing/mylib/include/mylib/mylib.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace mylib +{ +std::string message(); +} diff --git a/tests/globbing/mylib/src/mylib/mylib.cpp b/tests/globbing/mylib/src/mylib/mylib.cpp new file mode 100644 index 0000000..b667ff3 --- /dev/null +++ b/tests/globbing/mylib/src/mylib/mylib.cpp @@ -0,0 +1,6 @@ +#include + +std::string mylib::message() +{ + return "cmkr is awesome!"; +} diff --git a/tests/vcpkg/vcpkg.json b/tests/vcpkg/vcpkg.json index 2ed5f1a..ec00969 100644 --- a/tests/vcpkg/vcpkg.json +++ b/tests/vcpkg/vcpkg.json @@ -5,7 +5,7 @@ "dependencies": [ "fmt" ], - "description": "Example of using vcpkg", + "description": "Dependencies from vcpkg", "name": "vcpkg", "version-string": "" }