Skip to content

Commit

Permalink
Github Actions
Browse files Browse the repository at this point in the history
Add some CMake presets and fix Github Actions workflows
  • Loading branch information
christiannicola committed Sep 28, 2023
1 parent 6a1dc59 commit b287b1d
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 29 deletions.
62 changes: 35 additions & 27 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: CMake on multiple platforms

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]

branches: ["master"]
jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
Expand All @@ -24,7 +20,7 @@ jobs:
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release]
build_type: [release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
Expand All @@ -43,27 +39,39 @@ jobs:
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- uses: seanmiddleditch/gha-setup-ninja@master

- if: matrix.os == 'windows-latest'
uses: ilammy/msvc-dev-cmd@v1

- if: matrix.os == 'ubuntu-latest'
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libglu1-mesa-dev xorg-dev gnome-desktop-testing libasound2-dev libpulse-dev libaudio-dev libjack-dev libsndio-dev libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libdbus-1-dev libibus-1.0-dev libudev-dev fcitx-libs-dev libpipewire-0.3-dev libwayland-dev libdecor-0-dev
version: 0.1
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
PRESET=unixlike-${{ matrix.c_compiler }}-${{ matrix.build_type }}
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}
if [ "${{ matrix.os }}" == "windows-latest" ]; then
PRESET=windows-${{ matrix.c_compiler }}-${{ matrix.build_type }}
fi
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
echo "preset=$PRESET" >> "$GITHUB_OUTPUT"
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake --preset=${{ steps.strings.outputs.preset }} -B ${{ steps.strings.outputs.build-output-dir }} -S ${{ github.workspace }}
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: >
cmake --build ${{ steps.strings.outputs.build-output-dir }}
151 changes: 151 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "conf-common",
"description": "General settings that apply to all configurations",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}"
},
{
"name": "conf-windows-common",
"description": "Windows settings for MSBuild toolchain that apply to msvc and clang",
"hidden": true,
"inherits": "conf-common",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"architecture": {
"value": "x64",
"strategy": "external"
},
"toolset": {
"value": "host=x64",
"strategy": "external"
}
},
{
"name": "conf-unixlike-common",
"description": "Unix-like OS settings for gcc and clang toolchains",
"hidden": true,
"inherits": "conf-common",
"condition": {
"type": "inList",
"string": "${hostSystemName}",
"list": ["Linux", "Darwin"]
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
},
{
"name": "windows-cl-release",
"displayName": "msvc Release",
"description": "Target Windows with the msvc compiler, release build type",
"inherits": "conf-windows-common",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "windows-cl-debug",
"displayName": "msvc Debug",
"description": "Target Windows with the msvc compiler, debug build type",
"inherits": "conf-windows-common",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "windows-clang-debug",
"displayName": "clang Debug",
"description": "Target Windows with the clang compiler, debug build type",
"inherits": "conf-windows-common",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl",
"CMAKE_BUILD_TYPE": "Debug"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"intelliSenseMode": "windows-clang-x64"
}
}
},
{
"name": "windows-clang-release",
"displayName": "clang Release",
"description": "Target Windows with the clang compiler, release build type",
"inherits": "conf-windows-common",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl",
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"intelliSenseMode": "windows-clang-x64"
}
}
},
{
"name": "unixlike-gcc-debug",
"displayName": "gcc Debug",
"description": "Target Unix-like OS with the gcc compiler, debug build type",
"inherits": "conf-unixlike-common",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "unixlike-gcc-release",
"displayName": "gcc Release",
"description": "Target Unix-like OS with the gcc compiler, release build type",
"inherits": "conf-unixlike-common",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "unixlike-clang-debug",
"displayName": "clang Debug",
"description": "Target Unix-like OS with the clang compiler, debug build type",
"inherits": "conf-unixlike-common",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "unixlike-clang-release",
"displayName": "clang Release",
"description": "Target Unix-like OS with the clang compiler, release build type",
"inherits": "conf-unixlike-common",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
}
]
}
2 changes: 0 additions & 2 deletions scratch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
add_compile_options(-Wall -Werror -O2)

# Add all source files to one variable
file(GLOB scratch_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
# Add all header files, including the ones from our dependencies into a variable
Expand Down

0 comments on commit b287b1d

Please sign in to comment.