name: Build (RISC OS)

on: [push, pull_request]

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
  cancel-in-progress: true

jobs:
  Build:
    name: ${{ matrix.platform.name }}
    runs-on: ubuntu-latest
    container: riscosdotinfo/riscos-gccsdk-4.7:latest

    strategy:
      fail-fast: false
      matrix:
        platform:
          - { name: CMake }

    steps:
    - name: Setup dependencies
      run: apt-get update && apt-get install -y cmake ninja-build
    - uses: actions/checkout@v4
    - name: Configure (CMake)
      if: ${{ contains(matrix.platform.name, 'CMake') }}
      run: |
        cmake -S . -B build -G Ninja \
          -Wdeprecated -Wdev -Werror \
          -DCMAKE_TOOLCHAIN_FILE=/home/riscos/env/toolchain-riscos.cmake \
          -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON \
          -DRISCOS:BOOL=ON \
          -DSDL_GCC_ATOMICS=OFF \
          -DSDL_TESTS=ON \
          -DSDL_INSTALL_TESTS=ON \
          -DSDL_DISABLE_INSTALL_DOCS=OFF \
          -DSDL_VENDOR_INFO="Github Workflow" \
          -DCMAKE_BUILD_TYPE=Release \
          -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/prefix_cmake
    - name: Build (CMake)
      if: ${{ contains(matrix.platform.name, 'CMake') }}
      run: cmake --build build --verbose
    - name: Install (CMake)
      if: ${{ contains(matrix.platform.name, 'CMake') }}
      run: |
        echo "SDL3_DIR=${{ github.workspace }}/prefix_cmake" >> $GITHUB_ENV
        cmake --install build/
        ( cd ${{ github.workspace }}/prefix_cmake; find ) | LC_ALL=C sort -u
    - name: Package (CPack)
      run: |
        cmake --build build/ --config Release --target package
    - name: Verify CMake configuration files
      run: |
        cmake -S cmake/test -B cmake_config_build -G Ninja \
          -DTEST_SHARED=OFF \
          -DCMAKE_TOOLCHAIN_FILE=/home/riscos/env/toolchain-riscos.cmake \
          -DCMAKE_PREFIX_PATH=${{ env.SDL3_DIR }} \
          -DCMAKE_BUILD_TYPE=Release \
          ${{ matrix.platform.test_args }}
        cmake --build cmake_config_build --verbose
    - uses: actions/upload-artifact@v4
      with:
        if-no-files-found: error
        name: SDL-riscos
        path: build/dist/SDL3*
