From b55540041ffd47abafc37abe1d959310e3a75835 Mon Sep 17 00:00:00 2001
From: Tim Kaune <tim.kaune@gmx.de>
Date: Wed, 19 Mar 2025 11:05:43 +0100
Subject: [PATCH] Add test and workflow presets

Cleanup hard-coded test configuration
Bump CMake package version number
---
 .github/workflows/build-and-test.yml |  12 +--
 CMakeLists.txt                       |  10 +--
 CMakePresets.json                    | 122 +++++++++++++++++++++++++++
 README.md                            |  61 +++++++++-----
 4 files changed, 165 insertions(+), 40 deletions(-)

diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml
index 8146ff5..5b485d3 100644
--- a/.github/workflows/build-and-test.yml
+++ b/.github/workflows/build-and-test.yml
@@ -7,18 +7,12 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: prepare
-        run: sudo apt-get install -y ninja-build
+        run: sudo apt-get install -y git cmake ninja-build
       - name: info
         run: |
           git version
           cmake --version
           ninja --version
       - uses: actions/checkout@v4
-      - name: configure
-        run: cmake --preset ninja
-      - name: build
-        run: cmake --build --preset ninja --verbose
-      - name: install
-        run: cmake --build --preset ninja --verbose --target install
-      - name: test
-        run: cmake --build --preset ninja --verbose --target check
+      - name: build-and-test
+        run: cmake --workflow --preset ci-ninja
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c613328..529c666 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,11 +25,11 @@ SOFTWARE.
 
 cmake_minimum_required(VERSION 3.25)
 
-set(CMAKE_MAXIMUM_SUPPORTED_VERSION 3.29)
+set(CMAKE_MAXIMUM_SUPPORTED_VERSION 3.31)
 
 include("./cmake/HandlePolicies.cmake" NO_POLICY_SCOPE)
 
-project(LoadStaticSharedTargets VERSION 1.6.0 LANGUAGES NONE)
+project(LoadStaticSharedTargets VERSION 1.7.0 LANGUAGES NONE)
 
 include(GNUInstallDirs)
 
@@ -37,10 +37,6 @@ string(COMPARE EQUAL "${CMAKE_PROJECT_NAME}" "${PROJECT_NAME}" IS_TOP_LEVEL)
 
 if (IS_TOP_LEVEL)
     include(CTest)
-
-    if (NOT DEFINED CMAKE_CTEST_ARGUMENTS)
-        set(CMAKE_CTEST_ARGUMENTS "--verbose")
-    endif ()
 endif ()
 
 option(LoadStaticSharedTargets_INCLUDE_PACKAGING "Include packaging rules for LoadStaticSharedTargets" "${IS_TOP_LEVEL}")
@@ -48,8 +44,6 @@ option(LoadStaticSharedTargets_INCLUDE_PACKAGING "Include packaging rules for Lo
 add_subdirectory(src)
 
 if (IS_TOP_LEVEL AND BUILD_TESTING)
-    add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} -V)
-
     add_subdirectory(tests EXCLUDE_FROM_ALL)
 endif ()
 
diff --git a/CMakePresets.json b/CMakePresets.json
index 64ba4f9..a3615fa 100644
--- a/CMakePresets.json
+++ b/CMakePresets.json
@@ -35,15 +35,137 @@
     }
   ],
   "buildPresets": [
+    {
+      "name": "verbose",
+      "hidden": true,
+      "verbose": true
+    },
     {
       "name": "ninja",
+      "inherits": [
+        "verbose"
+      ],
       "displayName": "Default Build using Ninja",
       "configurePreset": "ninja"
     },
+    {
+      "name": "ninja-install",
+      "inherits": [
+        "ninja"
+      ],
+      "displayName": "Default Build and Installation using Ninja",
+      "targets": [
+        "install"
+      ]
+    },
     {
       "name": "make",
+      "inherits": [
+        "verbose"
+      ],
       "displayName": "Default Build using Make",
       "configurePreset": "make"
+    },
+    {
+      "name": "make-install",
+      "inherits": [
+        "make"
+      ],
+      "displayName": "Default Build and Installation using Make",
+      "targets": [
+        "install"
+      ]
+    }
+  ],
+  "testPresets": [
+    {
+      "name": "verbose",
+      "hidden": true,
+      "output": {
+        "verbosity": "verbose"
+      }
+    },
+    {
+      "name": "ninja",
+      "inherits": [
+        "verbose"
+      ],
+      "displayName": "Default Test using Ninja",
+      "configurePreset": "ninja"
+    },
+    {
+      "name": "make",
+      "inherits": [
+        "verbose"
+      ],
+      "displayName": "Default Test using Make",
+      "configurePreset": "make"
+    }
+  ],
+  "workflowPresets": [
+    {
+      "name": "dev-ninja",
+      "displayName": "Developer Workflow using Ninja",
+      "steps": [
+        {
+          "type": "configure",
+          "name": "ninja"
+        },
+        {
+          "type": "build",
+          "name": "ninja-install"
+        }
+      ]
+    },
+    {
+      "name": "ci-ninja",
+      "displayName": "CI Workflow using Ninja",
+      "steps": [
+        {
+          "type": "configure",
+          "name": "ninja"
+        },
+        {
+          "type": "build",
+          "name": "ninja"
+        },
+        {
+          "type": "test",
+          "name": "ninja"
+        }
+      ]
+    },
+    {
+      "name": "dev-make",
+      "displayName": "Developer Workflow using Make",
+      "steps": [
+        {
+          "type": "configure",
+          "name": "make"
+        },
+        {
+          "type": "build",
+          "name": "make-install"
+        }
+      ]
+    },
+    {
+      "name": "ci-make",
+      "displayName": "CI Workflow using Make",
+      "steps": [
+        {
+          "type": "configure",
+          "name": "make"
+        },
+        {
+          "type": "build",
+          "name": "make"
+        },
+        {
+          "type": "test",
+          "name": "make"
+        }
+      ]
     }
   ]
 }
diff --git a/README.md b/README.md
index 08b0b99..57da35a 100644
--- a/README.md
+++ b/README.md
@@ -26,9 +26,9 @@ SOFTWARE.
 # LoadStaticSharedTargets #
 
 This CMake module contains a macro for loading static or shared exported library
-targets in a CMake package config file. Static or shared targets can be
-explicitly (via `COMPONENTS`) or implicitly (via `BUILD_SHARED_LIBS`) imported
-with the `find_package()` command.
+targets in a CMake package config file. Static or shared targets can be imported
+explicitly (via `COMPONENTS`) or implicitly (via `BUILD_SHARED_LIBS`) with the
+`find_package()` command.
 
 ## Prerequisites ##
 
@@ -63,7 +63,7 @@ $ brew install cmake ninja
 #### MacPorts ####
 
 ```shell
-$ sudo port -vb install cmake-devel ninja
+$ sudo port -v install cmake ninja
 ```
 
 ### Windows ###
@@ -87,27 +87,42 @@ process.
 
 1. Clone the git repository or download the source code archive and unpack it to
    an arbitrary directory (e.g. `load-static-shared-targets`).
-2. Go to this directory and type `cmake --list-presets`. A list of available
-   build configurations will be shown to you.
-3. For configuring the project, type `cmake --preset ninja`. This will populate
-   the `./build` directory with a CMake configuration tree. By default, the
-   configured installation directory is `./install`. You can specify a different
-   install location by setting the `CMAKE_INSTALL_PREFIX` variable:
+2. Go to this directory and type `cmake --workflow --list-presets`. A list of
+   available build workflows will be shown to you.
+3. For configuring, building and installing the project, type `cmake --workflow
+   --preset dev-ninja`. This will populate the `./build` directory with a CMake
+   configuration tree, execute the build and install the project. By default,
+   the configured installation directory is `./install`.
+4. For running the tests, type `cmake --workflow --preset ci-ninja`.
+
+### How to customize the build from the command line ###
+
+1. You can specify a different install location by using the configure preset
+   directly while setting the `CMAKE_INSTALL_PREFIX` variable:
 
    ```shell
    $ cmake --preset ninja -D "CMAKE_INSTALL_PREFIX=/path/to/install/prefix"
    ```
 
-4. Now, you can build with `cmake --build --preset ninja`. You should see some
-   informative terminal output.
-5. Finally, install the built artifacts to the configured install prefix with
-   `cmake --build --preset ninja --target install`. If the configured install
-   prefix is a system-wide location (like `/usr/local`), installing might
-   require `sudo`.
+   If the configured install prefix is a system-wide location (like
+   `/usr/local`), installing might require `sudo`.
+
+2. Now, you can build manually with `cmake --build --preset ninja-install`. You
+   should see some informative terminal output.
+
+### How to customize the build using user presets ###
+
+Create the file `./CMakeUserPresets.json` and build your own configure, build,
+test or workflow presets by inheriting from the project's default presets.
+Please refer to the [CMake Documentation about presets][1] for details.
+
+[1]: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html
+
+## How to use ##
 
-Now, the `LoadStaticSharedTargets` module is installed and you can use it in
-other projects. The installed `LoadStaticSharedTargets` package is discoverable
-by CMake as __LoadStaticSharedTargets__. In the `CMakeLists.txt` of the other
+With the `LoadStaticSharedTargets` module installed, you can use it in other
+projects. The installed `LoadStaticSharedTargets` package is discoverable by
+CMake as __LoadStaticSharedTargets__. In the `CMakeLists.txt` of the other
 project, do the following:
 
 ```cmake
@@ -116,9 +131,9 @@ include(FetchContent)
 FetchContent_Declare(
     LoadStaticSharedTargets
     GIT_REPOSITORY "https://github.com/lepus2589/LoadStaticSharedTargets.git"
-    GIT_TAG v1.5.2
+    GIT_TAG v1.7.0
     SYSTEM
-    FIND_PACKAGE_ARGS 1.5.2 CONFIG NAMES LoadStaticSharedTargets
+    FIND_PACKAGE_ARGS 1.7.0 CONFIG NAMES LoadStaticSharedTargets
 )
 set(LoadStaticSharedTargets_INCLUDE_PACKAGING TRUE)
 FetchContent_MakeAvailable(LoadStaticSharedTargets)
@@ -151,8 +166,8 @@ load_static_shared_targets(
 )
 ```
 
-This adds the LoadStaticSharedTargets module to the `CMAKE_MODULE_PATH` variable
-which enables the include by name only.
+The `find_package()` command adds the LoadStaticSharedTargets module to the
+`CMAKE_MODULE_PATH` variable which enables the `include()` by name only.
 
 ## Further Reading ##
 
-- 
GitLab