From be387141b553f91a36045e383cb1def091072131 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sun, 9 Jul 2023 19:24:32 +0200 Subject: [PATCH] Add a 'Compiler flags' example to the documentation --- docs/examples/compile-options.md | 31 ++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 10 ++++++++++ tests/cmake.toml | 6 ++++++ tests/compile-options/cmake.toml | 15 +++++++++++++++ tests/compile-options/src/main.cpp | 5 +++++ 5 files changed, 67 insertions(+) create mode 100644 docs/examples/compile-options.md create mode 100644 tests/compile-options/cmake.toml create mode 100644 tests/compile-options/src/main.cpp diff --git a/docs/examples/compile-options.md b/docs/examples/compile-options.md new file mode 100644 index 0000000..f219622 --- /dev/null +++ b/docs/examples/compile-options.md @@ -0,0 +1,31 @@ +--- +# Automatically generated from tests/compile-options/cmake.toml - DO NOT EDIT +layout: default +title: Compiler flags +permalink: /examples/compile-options +parent: Examples +nav_order: 9 +--- + +# Compiler flags + +Example project that sets compiler/linker flags for various platforms. + +```toml +[project] +name = "compile-options" +description = "Compiler flags" + +[target.hello] +type = "executable" +sources = ["src/main.cpp"] +msvc.compile-options = ["/W2"] +gcc.compile-options = ["-Wall"] +clang.compile-options = ["-Wall"] +``` + +The `hello` target uses [conditions](/cmake-toml#conditions) to set different compiler flags depending on the platform. See the [targets](/cmake-toml/#targets) documentation for other things you can set. + +_Note_: In general you only want to specify flags _required_ to compile your code without errors. + +This page was automatically generated from [tests/compile-options/cmake.toml](https://github.com/build-cpp/cmkr/tree/main/tests/compile-options/cmake.toml). diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bc4bbf6..7478c3d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -100,3 +100,13 @@ if(MSVC) # msvc ) endif() +add_test( + NAME + compile-options + WORKING_DIRECTORY + "${CMAKE_CURRENT_LIST_DIR}/compile-options" + COMMAND + "$" + build +) + diff --git a/tests/cmake.toml b/tests/cmake.toml index cddec8f..6d20721 100644 --- a/tests/cmake.toml +++ b/tests/cmake.toml @@ -52,3 +52,9 @@ name = "msvc-runtime" working-directory = "msvc-runtime" command = "$" arguments = ["build"] + +[[test]] +name = "compile-options" +working-directory = "compile-options" +command = "$" +arguments = ["build"] \ No newline at end of file diff --git a/tests/compile-options/cmake.toml b/tests/compile-options/cmake.toml new file mode 100644 index 0000000..af59748 --- /dev/null +++ b/tests/compile-options/cmake.toml @@ -0,0 +1,15 @@ +# Example project that sets compiler/linker flags for various platforms. + +[project] +name = "compile-options" +description = "Compiler flags" + +[target.hello] +type = "executable" +sources = ["src/main.cpp"] +msvc.compile-options = ["/W2"] +gcc.compile-options = ["-Wall"] +clang.compile-options = ["-Wall"] + +# The `hello` target uses [conditions](/cmake-toml#conditions) to set different compiler flags depending on the platform. See the [targets](/cmake-toml/#targets) documentation for other things you can set. +# _Note_: In general you only want to specify flags _required_ to compile your code without errors. diff --git a/tests/compile-options/src/main.cpp b/tests/compile-options/src/main.cpp new file mode 100644 index 0000000..84b6c59 --- /dev/null +++ b/tests/compile-options/src/main.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + puts("Hello from cmkr!"); +}