name: macOS CMake

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

jobs:
  cmake_build_on_macos:
    runs-on: macos-15
    concurrency:
      group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
      cancel-in-progress: true
    steps:
      - uses: actions/checkout@v6

      - name: Install build tools
        run: |
          export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
          brew update --quiet
          brew install --force --overwrite cmake llvm lld ninja

      - name: Configure
        run: |
          export LLVM_PREFIX="$(brew --prefix llvm)"
          export LLD_PREFIX="$(brew --prefix lld)"
          export CXX="$LLVM_PREFIX/bin/clang++"
          export CPPFLAGS="-I$LLVM_PREFIX/include"
          export LDFLAGS="-L$LLVM_PREFIX/lib -L$LLVM_PREFIX/lib/c++ -Wl,-rpath,$LLVM_PREFIX/lib/c++ -fuse-ld=$LLD_PREFIX/bin/ld64.lld"
          cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug

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

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