Skip to content

Commit

Permalink
add multi-configs for IDEs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukka committed May 6, 2023
1 parent 3596637 commit 427e080
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 50 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/hosted-ninja-vcpkg_submod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# from cache (e.g., already previously built).
# - Finally builds the sources with Ninja, and tests as well.
name: hosted-ninja-vcpkg_submod-autocache
on:
on:
push:
workflow_dispatch:
schedule:
Expand Down Expand Up @@ -49,11 +49,15 @@ jobs:
with:
vcpkgJsonGlob: 'vcpkg.json'

# Note: if the preset misses the "configuration", it is possible to explicitly select the
# configuration with the additional `--config` flag, e.g.:
# buildPreset: 'ninja-vcpkg'
# buildPresetAdditionalArgs: "[`--config`, `Release`]"
# testPreset: 'ninja-vcpkg'
# testPresetAdditionalArgs: "[`--config`, `Release`]"
- name: Run CMake+vcpkg+Ninja+CTest to build packages and generate/build/test the code.
uses: lukka/run-cmake@v10
with:
configurePreset: 'ninja-multiconfiguration-vcpkg'
buildPreset: 'ninja-multiconfiguration-vcpkg'
buildPresetAdditionalArgs: "[`--config`, `Release`]"
testPreset: 'ninja-multiconfiguration-vcpkg'
testPresetAdditionalArgs: "[`--config`, `Release`]"
configurePreset: 'ninja-multi-vcpkg'
buildPreset: 'ninja-vcpkg-release'
testPreset: 'test-release'
14 changes: 9 additions & 5 deletions .github/workflows/hosted-pure-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# It is called "pure workflow" because it is an example which minimizes the usage of
# custom GitHub Actions, but leverages directly the tools that could be easily run on
# your development machines (i.e. CMake, vcpkg, Ninja) to ensure a perfectly identical
# and reproducible local build (on your development machine) and a remote build on
# and reproducible local build (on your development machine) and a remote build on
# build agents.
name: hosted-pure-workflow
on:
Expand Down Expand Up @@ -83,18 +83,22 @@ jobs:
# Run CMake to generate Ninja project files, using the vcpkg's toolchain file to resolve and install
# the dependencies as specified in vcpkg.json. Note that the vcpkg's toolchain is specified
# in the CMakePresets.json file.
# This step also runs vcpkg with Binary Caching leveraging GitHub Action cache to
# This step also runs vcpkg with Binary Caching leveraging GitHub Action cache to
# store the built packages artifacts.
- name: Restore from cache the dependencies and generate project files
run: |
cmake --preset ninja-multiconfiguration-vcpkg
cmake --preset ninja-multi-vcpkg
# Build (Release configuration only) the whole project with Ninja (which is spawn by CMake).
#
# Note: if the preset misses the "configuration", it is possible to explicitly select the
# configuration with the `--config` flag, e.g.:
# run: cmake --build --preset ninja-vcpkg --config Release
- name: Build (Release configuration)
run: |
cmake --build --preset ninja-multiconfiguration-vcpkg --config Release
cmake --build --preset ninja-vcpkg-release
# Test the whole project with CTest, again Release configuration only.
- name: Test (Release configuration)
run: |
ctest --preset ninja-multiconfiguration-vcpkg --config Release
ctest --preset test-release
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(test)
project(cpp_template)

# Find dependencies provided by vcpkg (via vcpkg.cmake)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
Expand Down
104 changes: 68 additions & 36 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,73 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "ninja-multiconfiguration-vcpkg",
"displayName": "Ninja Multi-Config",
"description": "Configure with vcpkg toolchain and generate Ninja project files for all configurations",
"binaryDir": "${sourceDir}/builds/${presetName}",
"generator": "Ninja Multi-Config",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"type": "FILEPATH",
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "ninja-multi-vcpkg",
"displayName": "Ninja Multi-Config",
"description": "Configure with vcpkg toolchain and generate Ninja project files for all configurations",
"binaryDir": "${sourceDir}/builds/${presetName}",
"generator": "Ninja Multi-Config",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"type": "FILEPATH",
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
},
"environment": {
"VCPKG_ROOT": "./vcpkg"
}
}
},
"environment": {
"VCPKG_ROOT": "./vcpkg"
],
"buildPresets": [
{
"name": "ninja-vcpkg-debug",
"configurePreset": "ninja-multi-vcpkg",
"displayName": "Build (Debug)",
"description": "Build with Ninja/vcpkg (Debug)",
"configuration": "Debug"
},
{
"name": "ninja-vcpkg-release",
"configurePreset": "ninja-multi-vcpkg",
"displayName": "Build (Release)",
"description": "Build with Ninja/vcpkg (Release)",
"configuration": "Release"
},
{
"name": "ninja-vcpkg",
"configurePreset": "ninja-multi-vcpkg",
"displayName": "Build",
"description": "Build with Ninja/vcpkg"
}
],
"testPresets": [
{
"name": "test-ninja-vcpkg",
"configurePreset": "ninja-multi-vcpkg",
"hidden": true
},
{
"name": "test-debug",
"description": "Test (Debug)",
"displayName": "Test (Debug)",
"configuration": "Debug",
"inherits": [
"test-ninja-vcpkg"
]
},
{
"name": "test-release",
"description": "Test (Release)",
"displayName": "Test (Release)",
"configuration": "Release",
"inherits": [
"test-ninja-vcpkg"
]
}
}
],
"buildPresets": [
{
"name": "ninja-multiconfiguration-vcpkg",
"configurePreset": "ninja-multiconfiguration-vcpkg",
"displayName": "Build ninja-multiconfiguration-vcpkg",
"description": "Build with Ninja the configuration specified with --config"
}
],
"testPresets": [
{
"name": "ninja-multiconfiguration-vcpkg",
"configurePreset": "ninja-multiconfiguration-vcpkg",
"description": "Test with Ninja the provided configuration with --config"
}
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The main idea of this `C++` project template is to show how to obtain a _perfect

The major `C++` IDEs should already support `CMakePresets.json` and require no particular configuration.

For example [Visual Studio Code](https://code.visualstudio.com/) with the [CMake Tools extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) let you to open the root folder of this repository, and select in the status bar the CMake preset (e.g. `ninja-multiconfiguration-vcpkg`), as show in the following image:
For example [Visual Studio Code](https://code.visualstudio.com/) with the [CMake Tools extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) let you to open the root folder of this repository, and select in the status bar the CMake preset (e.g. `ninja-multi-vcpkg`), as show in the following image:

![CMake's preset selection in the status bar of Visual Studio Code](./img/vscode_cmakepresets_selection.png)

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// main.cpp
#include <sqlite3.h>
#include <stdio.h>
#include <cstdio>
#include <fmt/core.h>

// main function!
Expand Down

0 comments on commit 427e080

Please sign in to comment.