From cab3af2cc0e49fa4444aaa8a785f5f1d5d664083 Mon Sep 17 00:00:00 2001 From: luca <681992+lukka@users.noreply.github.com> Date: Thu, 22 Dec 2022 00:48:51 -0800 Subject: [PATCH] multiconfiguration sample --- .../workflows/hosted-ninja-vcpkg_submod.yml | 21 +++++++++----- .github/workflows/hosted-pure-workflow.yml | 14 ++++----- CMakePresets.json | 29 +++++-------------- README.md | 5 +++- 4 files changed, 32 insertions(+), 37 deletions(-) diff --git a/.github/workflows/hosted-ninja-vcpkg_submod.yml b/.github/workflows/hosted-ninja-vcpkg_submod.yml index c424d0d..fa62b7f 100644 --- a/.github/workflows/hosted-ninja-vcpkg_submod.yml +++ b/.github/workflows/hosted-ninja-vcpkg_submod.yml @@ -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: @@ -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 @@ -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 diff --git a/.github/workflows/hosted-pure-workflow.yml b/.github/workflows/hosted-pure-workflow.yml index 8a436be..3a1dd23 100644 --- a/.github/workflows/hosted-pure-workflow.yml +++ b/.github/workflows/hosted-pure-workflow.yml @@ -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 diff --git a/CMakePresets.json b/CMakePresets.json index 7fbd77a..31fb571 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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}", @@ -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" } ] } \ No newline at end of file diff --git a/README.md b/README.md index 7a2b9b8..cde2487 100644 --- a/README.md +++ b/README.md @@ -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).