From a80907c3e486d84b1731bf9e9c5c351e195399c7 Mon Sep 17 00:00:00 2001 From: Tim Kaune <tim.kaune@gmx.de> Date: Fri, 21 Mar 2025 10:15:48 +0100 Subject: [PATCH] Remove choice of generator from project presets Move it to the user presets instead. --- .github/workflows/build-and-test.yml | 4 +- CMakePresets.json | 132 ++++++--------------------- CMakePresetsCommon.json | 50 ++++++++++ CMakeUserPresets.template.json | 99 ++++++++++++++++++++ README.md | 36 +++----- 5 files changed, 193 insertions(+), 128 deletions(-) create mode 100644 CMakePresetsCommon.json create mode 100644 CMakeUserPresets.template.json diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 5b485d3..4fb2aa1 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -15,4 +15,6 @@ jobs: ninja --version - uses: actions/checkout@v4 - name: build-and-test - run: cmake --workflow --preset ci-ninja + run: | + cp "./CMakeUserPresets.template.json" "./CMakeUserPresets.json" + cmake --workflow --preset user-test diff --git a/CMakePresets.json b/CMakePresets.json index a3615fa..2a17ff4 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -5,165 +5,85 @@ "minor": 25, "patch": 0 }, + "include": [ + "./CMakePresetsCommon.json" + ], "configurePresets": [ { - "name": "default", + "name": "config", "hidden": true, "binaryDir": "${sourceDir}/build", - "cacheVariables": { - "CMAKE_INSTALL_PREFIX": "${sourceDir}/install" - }, "warnings": { "dev": false } }, { - "name": "ninja", - "inherits": [ - "default" - ], - "generator": "Ninja", - "displayName": "Default Build Configuration using Ninja" - }, - { - "name": "make", + "name": "default", "inherits": [ - "default" + "install", + "config" ], - "generator": "Unix Makefiles", - "displayName": "Default Build Configuration using Makefiles" + "displayName": "Default Build Configuration" } ], "buildPresets": [ { - "name": "verbose", - "hidden": true, - "verbose": true - }, - { - "name": "ninja", + "name": "default", "inherits": [ "verbose" ], - "displayName": "Default Build using Ninja", - "configurePreset": "ninja" + "displayName": "Default Build", + "configurePreset": "default" }, { - "name": "ninja-install", + "name": "default-install", "inherits": [ - "ninja" - ], - "displayName": "Default Build and Installation using Ninja", - "targets": [ + "default", "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" - ] + "displayName": "Default Build and Installation" } ], "testPresets": [ { - "name": "verbose", - "hidden": true, - "output": { - "verbosity": "verbose" - } - }, - { - "name": "ninja", - "inherits": [ - "verbose" - ], - "displayName": "Default Test using Ninja", - "configurePreset": "ninja" - }, - { - "name": "make", + "name": "default", "inherits": [ "verbose" ], - "displayName": "Default Test using Make", - "configurePreset": "make" + "displayName": "Default Test", + "configurePreset": "default" } ], "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", + "name": "default", + "displayName": "Default Workflow", "steps": [ { "type": "configure", - "name": "ninja" + "name": "default" }, { "type": "build", - "name": "ninja" + "name": "default" }, { "type": "test", - "name": "ninja" - } - ] - }, - { - "name": "dev-make", - "displayName": "Developer Workflow using Make", - "steps": [ - { - "type": "configure", - "name": "make" - }, - { - "type": "build", - "name": "make-install" + "name": "default" } ] }, { - "name": "ci-make", - "displayName": "CI Workflow using Make", + "name": "default-install", + "displayName": "Install Workflow", "steps": [ { "type": "configure", - "name": "make" + "name": "default" }, { "type": "build", - "name": "make" - }, - { - "type": "test", - "name": "make" + "name": "default-install" } ] } diff --git a/CMakePresetsCommon.json b/CMakePresetsCommon.json new file mode 100644 index 0000000..8bde42f --- /dev/null +++ b/CMakePresetsCommon.json @@ -0,0 +1,50 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 + }, + "configurePresets": [ + { + "name": "install", + "hidden": true, + "cacheVariables": { + "CMAKE_INSTALL_PREFIX": "${sourceDir}/install" + } + }, + { + "name": "ninja", + "hidden": true, + "generator": "Ninja" + }, + { + "name": "make", + "hidden": true, + "generator": "Unix Makefiles" + } + ], + "buildPresets": [ + { + "name": "verbose", + "hidden": true, + "verbose": true + }, + { + "name": "install", + "hidden": true, + "targets": [ + "install" + ] + } + ], + "testPresets": [ + { + "name": "verbose", + "hidden": true, + "output": { + "verbosity": "verbose" + } + } + ] +} diff --git a/CMakeUserPresets.template.json b/CMakeUserPresets.template.json new file mode 100644 index 0000000..14104dd --- /dev/null +++ b/CMakeUserPresets.template.json @@ -0,0 +1,99 @@ +{ + "version": 6, + "include": [ + "./CMakePresets.json" + ], + "configurePresets": [ + { + "name": "user-config", + "hidden": true, + "cacheVariables": { + } + }, + { + "name": "user-default", + "inherits": [ + "user-config", + "ninja", + "default" + ], + "displayName": "User Build Configuration" + } + ], + "buildPresets": [ + { + "name": "user-default", + "inherits": [ + "default" + ], + "displayName": "User Build", + "configurePreset": "user-default" + }, + { + "name": "user-default-install", + "inherits": [ + "user-default", + "default-install" + ], + "displayName": "User Build and Installation" + } + ], + "testPresets": [ + { + "name": "user-default", + "inherits": [ + "default" + ], + "displayName": "User Test", + "configurePreset": "user-default" + } + ], + "workflowPresets": [ + { + "name": "user-default", + "displayName": "User Default Workflow", + "steps": [ + { + "type": "configure", + "name": "user-default" + }, + { + "type": "build", + "name": "user-default" + } + ] + }, + { + "name": "user-install", + "displayName": "User Install Workflow", + "steps": [ + { + "type": "configure", + "name": "user-default" + }, + { + "type": "build", + "name": "user-default-install" + } + ] + }, + { + "name": "user-test", + "displayName": "User Test Workflow", + "steps": [ + { + "type": "configure", + "name": "user-default" + }, + { + "type": "build", + "name": "user-default" + }, + { + "type": "test", + "name": "user-default" + } + ] + } + ] +} diff --git a/README.md b/README.md index 42d3b8e..835c108 100644 --- a/README.md +++ b/README.md @@ -87,34 +87,28 @@ 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 --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 +2. Go to this directory and type `cp ./CMakeUserPresets.template.json + ./CMakeUserPresets.json`. +3. Next, type `cmake --workflow --list-presets`. A list of available build + workflows will be shown to you. +4. For configuring, building and installing the project, type `cmake --workflow + --preset user-install`. 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 ### + You can specify a different install location by setting the + `CMAKE_INSTALL_PREFIX` variable in the `"user-config"` preset in your + `./CMakeUserPresets.json`: -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" + ```json + "cacheVariables": { + "CMAKE_INSTALL_PREFIX": "$env{HOME}/.local" + } ``` - 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 ### + Please refer to the [CMake Documentation about presets][1] for further details. -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. +5. For running the tests, type `cmake --workflow --preset user-test`. [1]: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html -- GitLab