# taken from https://github.com/onqtam/doctest/blob/master/.github/workflows/main.yml

name: C/C++ CI
on:
  push:
  pull_request:
    types: [opened, reopened]


jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        include: [
          { system: MacOS,          runner: macos-latest },
          { system: Ubuntu-22,      runner: ubuntu-22.04 },
          { system: Ubuntu-latest,  runner: ubuntu-latest },
        ]
    name: ${{ matrix.system }} Build
    runs-on: ${{ matrix.runner }}
    steps:
    - uses: actions/checkout@v5
    - name: cmake
      run: cmake -DOJPH_BUILD_STREAM_EXPAND=ON ..
      working-directory: build
    - name: build
      run: make
      working-directory: build

  build_mac:
    strategy:
      fail-fast: false
      matrix:
        include: [
          { system: MacOS Dual Build, runner: macos-latest },
        ]
    name: ${{ matrix.system }} Build
    runs-on: ${{ matrix.runner }}
    steps:
    - uses: actions/checkout@v5
    - name: cmake
      run: cmake -DOJPH_BUILD_STREAM_EXPAND=ON -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DOJPH_ENABLE_TIFF_SUPPORT=OFF ..
      working-directory: build
    - name: build
      run: make
      working-directory: build

  build_windows:
    strategy:
      fail-fast: false
      matrix:
        include: [
          { system: Windows,  runner: windows-latest },
        ]
    name: ${{ matrix.system }} Build
    runs-on: ${{ matrix.runner }}
    steps:
    - uses: actions/checkout@v5
    - name: cmake
      run: cmake -G "Visual Studio 17 2022" -A x64 -DOJPH_ENABLE_TIFF_SUPPORT=OFF -DOJPH_BUILD_STREAM_EXPAND=ON ..
      working-directory: build
    - name: build
      run: cmake --build . --config Release
      working-directory: build

  build_msys2:
    strategy:
      fail-fast: false
      matrix:
        include: [
          { system: Windows-MSYS2,  runner: windows-latest },
        ]
    name: ${{ matrix.system }} Build
    runs-on: ${{ matrix.runner }}
    defaults:
      run:
        shell: msys2 {0}
    steps:
    - uses: actions/checkout@v5
    - uses: msys2/setup-msys2@v2
      with:
        msystem: UCRT64
        update: false
        pacboy: cc:p cmake:p libtiff:p
    - name: cmake
      run: cmake -DOJPH_BUILD_STREAM_EXPAND=ON ..
      working-directory: build
    - name: build
      run: cmake --build . --config Release
      working-directory: build

  build_windows_on_arm:
    strategy:
      fail-fast: false
      matrix:
        include: [
          { system: WindowsOnARM,  runner: windows-11-arm },
        ]
    name: ${{ matrix.system }} Build
    runs-on: ${{ matrix.runner }}
    steps:
    - uses: actions/checkout@v5
    - name: cmake
      run: cmake -G "Visual Studio 17 2022" -A ARM64 -DOJPH_ENABLE_TIFF_SUPPORT=OFF -DOJPH_BUILD_STREAM_EXPAND=ON ..
      working-directory: build
    - name: build
      run: cmake --build . --config Release
      working-directory: build

  test:
    strategy:
      fail-fast: false
      matrix:
        include: [
          { system: MacOS-Intel,    runner: macos-15-intel },
          { system: MacOS-latest,   runner: macos-latest },
          { system: Ubuntu-latest,  runner: ubuntu-latest },
        ]
    name: ${{ matrix.system }} Test
    runs-on: ${{ matrix.runner }}
    steps:
    - uses: actions/checkout@v5
    - name: cmake
      run: cmake -DOJPH_BUILD_TESTS=yes ..
      working-directory: build
    - name: build
      run: make
      working-directory: build
    - name: test
      run: ctest --output-on-failure
      working-directory: build

  test_windows:
    strategy:
      fail-fast: false
      matrix:
        include: [
          { system: Windows,  runner: windows-latest },
        ]
    name: ${{ matrix.system }} Test
    runs-on: ${{ matrix.runner }}
    steps:
    - uses: actions/checkout@v5
    - name: cmake
      run: cmake -G "Visual Studio 17 2022" -A x64 -DOJPH_ENABLE_TIFF_SUPPORT=OFF -DOJPH_BUILD_TESTS=ON ..
      working-directory: build
    - name: build
      run: cmake --build . --config Release
      working-directory: build
    - name: test
      run: ctest --output-on-failure -C Release
      working-directory: build

  test_msys2:
    strategy:
      fail-fast: false
      matrix:
        include: [
          { system: Windows-MSYS2,  runner: windows-latest },
        ]
    name: ${{ matrix.system }} Test
    runs-on: ${{ matrix.runner }}
    defaults:
      run:
        shell: msys2 {0}
    steps:
    - uses: actions/checkout@v5
    - uses: msys2/setup-msys2@v2
      with:
        msystem: UCRT64
        update: false
        pacboy: cc:p cmake:p python:p
    - name: cmake
      run: cmake -DOJPH_ENABLE_TIFF_SUPPORT=OFF -DOJPH_BUILD_TESTS=ON -DPython3_EXECUTABLE=${MINGW_PREFIX}/bin/python.exe ..
      working-directory: build
    - name: build
      run: cmake --build . --config Release
      working-directory: build
    - name: test
      run: ctest --output-on-failure -C Release
      working-directory: build

  test_windows_on_arm:
    strategy:
      fail-fast: false
      matrix:
        include: [
          { system: WindowsOnARM,  runner: windows-11-arm },
        ]
    name: ${{ matrix.system }} Test
    runs-on: ${{ matrix.runner }}
    steps:
    - uses: actions/checkout@v5
    - name: cmake
      run: cmake -G "Visual Studio 17 2022" -A ARM64 -DOJPH_ENABLE_TIFF_SUPPORT=OFF -DOJPH_BUILD_TESTS=ON ..
      working-directory: build
    - name: build
      run: cmake --build . --config Release
      working-directory: build
    - name: test
      run: ctest --output-on-failure -C Release
      working-directory: build

