name: Linux CMake

on:
  workflow_dispatch:
  push:
    branches: main
    tags-ignore: '*.*'
    paths:
      - '.github/workflows/cmake-linux.yml'
      - 'CMakeLists.txt'
      - 'cmake/**'
      - 'include/**'
      - 'src/*pp'
      - 'src/linux/*pp'
  pull_request:
    branches: main
    paths:
      - '.github/workflows/cmake-linux.yml'
      - 'CMakeLists.txt'
      - 'cmake/**'
      - 'include/**'
      - 'src/*pp'
      - 'src/linux/*pp'

jobs:
  build:
    name: ${{ matrix.compiler }}-${{ matrix.version }}
    runs-on: ubuntu-24.04
    concurrency:
      group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ matrix.compiler }}-${{ matrix.version }}
      cancel-in-progress: true
    strategy:
      matrix:
        include:
          - compiler: clang
            version: 19
          - compiler: clang
            version: 20
          - compiler: clang
            version: 21
          - compiler: gcc
            version: 14
    steps:
      - uses: actions/checkout@v6

      - name: Install clang ${{ matrix.version }}
        if: ${{ matrix.compiler == 'clang' }}
        run: wget -qO - https://apt.llvm.org/llvm.sh | sudo bash -s -- ${{ matrix.version }} all

      - name: Configure
        run: |
          if [[ "${{ matrix.compiler }}" == "clang" ]]; then
            export CC=clang-${{ matrix.version }}
            export CXX=clang++-${{ matrix.version }}
            export CXXFLAGS="-stdlib=libc++"
            export LDFLAGS="-fuse-ld=lld -rtlib=compiler-rt -unwindlib=libunwind"
          else
            export CC=gcc-${{ matrix.version }}
            export CXX=g++-${{ matrix.version }}
          fi
          cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug

      - name: Compile
        run: cmake --build build --verbose

      - name: Test
        run: ctest --test-dir build
