name: re3 cmake (Linux)

on:
  workflow_dispatch:
  pull_request:
  push:
    branches: [ main, master ]
  release:
    types: [ published ]

jobs:
  build-linux:
    runs-on: ubuntu-22.04

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          submodules: recursive
          fetch-depth: 0

      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends \
            build-essential cmake ninja-build \
            libglfw3-dev libopenal-dev libmpg123-dev

      - name: Configure
        run: |
          cmake -S . -B build -G Ninja \
            -DCMAKE_BUILD_TYPE=Release \
            -DRE3_AUDIO=OAL \
            -DLIBRW_PLATFORM=GL3 \
            -DLIBRW_GL3_GFXLIB=GLFW \
            -DRE3_WITH_OPUS=False \
            -DRE3_VENDORED_LIBRW=True \
            -DRE3_INSTALL=True

      - name: Build
        run: cmake --build build --parallel $(nproc)

      - name: Create binary package (cpack)
        working-directory: ./build
        run: cpack -G TXZ

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: "linux-amd64-gl3-oal"
          path: build/*.tar.xz
          if-no-files-found: error
