Skip to content

Discover tests in CMake to be found by workflow #5

Discover tests in CMake to be found by workflow

Discover tests in CMake to be found by workflow #5

name: CMake on multiple platforms
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
build_type: [ Debug ]
c_compiler: [ gcc, clang ]
include:
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
steps:
- uses: actions/checkout@v4
- 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: Install GCC 14
if: matrix.os == 'ubuntu-latest' && matrix.c_compiler == 'gcc'
run: |
sudo apt-get update
sudo apt-get install -y gcc-14 g++-14
echo "C_COMPILER=gcc-14" >> $GITHUB_ENV
echo "CXX_COMPILER=g++-14" >> $GITHUB_ENV
- name: Install Clang 20
if: matrix.os == 'ubuntu-latest' && matrix.c_compiler == 'clang'
run: |
wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/plucky/ llvm-toolchain-plucky-20 main"
sudo apt-get update
sudo apt-get install -y clang-20
echo "C_COMPILER=clang-20" >> $GITHUB_ENV
echo "CXX_COMPILER=clang++-20" >> $GITHUB_ENV
- 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=${{ env.CXX_COMPILER }} -DCMAKE_C_COMPILER=${{ env.C_COMPILER }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DSIMPLY_INSTALL_PRE_COMMIT_HOOKS=OFF -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 }} --config ${{ matrix.build_type }}
- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}