Skip to content

Commit

Permalink
multiconfiguration sample
Browse files Browse the repository at this point in the history
  • Loading branch information
lukka committed Dec 28, 2022
1 parent a16b186 commit cab3af2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 37 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/hosted-ninja-vcpkg_submod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
# SPDX short identifier: MIT
#
# The peculiarity of this workflow is that assumes vcpkg stored as a submodule of this repository.
# This workflow does the following:
# - Restores vcpkg artifacts from cache.
# - Sets up vcpkg if needed, then run CMake with CMakePreset.json using a configuration
# The workflow runs on x86 and ARM.
# Workflow steps:
# - Restores vcpkg artifacts from cache, or setup vcpkg once and cache it on the GitHub cloud based cache.
# - Runs CMake with CMakePreset.json using a presest configuration
# that leverages the vcpkg's toolchain file. This will automatically run vcpkg to install dependencies
# described by the vcpkg.json manifest file. It will be a no-op if those are restored from cache.
# - Finally builds the sources with Ninja.
# - Finally builds the sources with Ninja, and tests as well.
name: hosted-ninja-vcpkg_submod-autocache
on:
push:
Expand All @@ -23,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest, buildjet-2vcpu-ubuntu-2204-arm]

# env:
# [OPTIONAL] Define the vcpkg's triplet
Expand All @@ -50,6 +51,10 @@ jobs:
uses: lukka/run-cmake@v10
id: runcmake
with:
configurePreset: 'ninja-multi-vcpkg'
buildPreset: 'ninja-multi-vcpkg-debug'
testPreset: 'ninja-multi-vcpkg-debug'
configurePreset: 'ninja-multiconfiguration-vcpkg'
buildPreset: 'ninja-multiconfiguration-vcpkg'
buildPresetAdditionalArgs: "[`--config`, `Release`]"
testPreset: 'ninja-multiconfiguration-vcpkg'
testPresetAdditionalArgs: "[`--config`, `Release`]"
env:
VCPKG_FORCE_SYSTEM_BINARIES: 1
14 changes: 7 additions & 7 deletions .github/workflows/hosted-pure-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ 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.
- name: Install dependencies and generate project files
run: |
cmake --preset ninja-multi-vcpkg
cmake --preset ninja-multiconfiguration-vcpkg
# Build the whole project with Ninja (which is spawn by CMake). Debug configuration.
- name: Build (Debug)
# Build (Release configuration only) the whole project with Ninja (which is spawn by CMake).
- name: Build (Release configuration)
run: |
cmake --build --preset ninja-multi-vcpkg-debug
cmake --build --preset ninja-multiconfiguration-vcpkg --config Release
# Test the whole project with CTest.
- name: Test (Debug)
# Test the whole project with CTest, again Release configuration only.
- name: Test (Release configuration)
run: |
ctest --preset ninja-multi-vcpkg-debug
ctest --preset ninja-multiconfiguration-vcpkg --config Release
29 changes: 8 additions & 21 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"configurePresets": [
{
"name": "ninja-multi-vcpkg",
"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}",
Expand All @@ -22,30 +22,17 @@
],
"buildPresets": [
{
"name": "ninja-multi-vcpkg-debug",
"configurePreset": "ninja-multi-vcpkg",
"displayName": "Build ninja-multi-vcpkg-debug",
"description": "Build ninja-multi-vcpkg Debug configuration",
"configuration": "Debug"
},
{
"name": "ninja-multi-vcpkg-release",
"configurePreset": "ninja-multi-vcpkg",
"displayName": "Build ninja-multi-vcpkg-release",
"description": "Build ninja-multi-vcpkg Release configuration",
"configuration": "RelWithDebInfo"
"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-multi-vcpkg-debug",
"configurePreset": "ninja-multi-vcpkg",
"configuration": "Debug"
},
{
"name": "ninja-multi-vcpkg-release",
"configurePreset": "ninja-multi-vcpkg",
"configuration": "RelWithDebInfo"
"name": "ninja-multiconfiguration-vcpkg",
"configurePreset": "ninja-multiconfiguration-vcpkg",
"description": "Test with Ninja the provided configuration with --config"
}
]
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
## C++ project template

[![hosted-ninja-vcpkg_submod-autocache](https://github.com/lukka/CppCMakeVcpkgTemplate/actions/workflows/hosted-ninja-vcpkg_submod.yml/badge.svg)](https://github.com/lukka/CppCMakeVcpkgTemplate/actions/workflows/hosted-ninja-vcpkg_submod.yml)[![hosted-pure-workflow](https://github.com/lukka/CppCMakeVcpkgTemplate/actions/workflows/hosted-pure-workflow.yml/badge.svg)](https://github.com/lukka/CppCMakeVcpkgTemplate/actions/workflows/hosted-pure-workflow.yml)
[![hosted-ninja-vcpkg_submod-autocache](https://github.com/lukka/CppCMakeVcpkgTemplate/actions/workflows/hosted-ninja-vcpkg_submod.yml/badge.svg)](https://github.com/lukka/CppCMakeVcpkgTemplate/actions/workflows/hosted-ninja-vcpkg_submod.yml)
[![hosted-pure-workflow](https://github.com/lukka/CppCMakeVcpkgTemplate/actions/workflows/hosted-pure-workflow.yml/badge.svg)](https://github.com/lukka/CppCMakeVcpkgTemplate/actions/workflows/hosted-pure-workflow.yml)

This repository contains a `C++` based project template that leverages [vcpkg](https://github.com/microsoft/vcpkg) and [CMake](https://www.cmake.org)'s [CMakePresets.json](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) to build and test the source code.

Supports `Linux`/`macOS`/`Windows` on `x64` and `arm64`.

Advantages:
- `CMakePresets.json` allows to run the same build either _locally on your IDE_ and on _GitHub runners_.
- `vcpkg` greatly helps in pulling and building the needed dependencies (e.g. libraries).
Expand Down

0 comments on commit cab3af2

Please sign in to comment.