name: CI

on: [push, pull_request]

jobs:
  ubuntu-build:
    name: Linux CI
    strategy:
      matrix:
        image:
          - "ubuntu:20.04"
          - "ubuntu:22.04"
          - "ubuntu:24.04"
        backend:
          - Pulseaudio
          - Portaudio
          - Gr-audio
    runs-on: ubuntu-latest
    container:
      image: ${{ matrix.image }}
      env:
        DEBIAN_FRONTEND: noninteractive
    steps:
      - name: Install dependencies
        run: |
          apt-get update -qq
          apt-get install -y \
            cmake \
            libboost-dev \
            libpulse-dev \
            portaudio19-dev \
            libsndfile-dev \
            liblog4cpp5-dev \
            gnuradio-dev \
            gr-osmosdr \
            liborc-0.4-dev \
            appstream \
            desktop-file-utils
      - name: Install Qt5
        if: matrix.image == 'ubuntu:20.04'
        run: |
          apt-get install -y \
            qt5-default \
            libqt5svg5-dev
      - name: Install Qt6
        if: matrix.image != 'ubuntu:20.04'
        run: |
          apt-get install -y \
            qt6-base-dev \
            libqt6svg6-dev \
            libqt6svgwidgets6 \
            libgl-dev
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Configure
        run: |
          mkdir build
          cd build
          cmake -DLINUX_AUDIO_BACKEND:STRING=${{ matrix.backend }} ..
      - name: Compile
        working-directory: build
        run: make -j4
      - name: Validate desktop entry
        run: desktop-file-validate dk.gqrx.gqrx.desktop
      - name: Validate appstream metadata
        run: appstreamcli validate dk.gqrx.gqrx.appdata.xml
  macos-build:
    name: MacOS CI
    strategy:
      matrix:
        os: [macos-13, macos-latest]
        backend: [Portaudio, Gr-audio]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Install dependencies
        run: |
          # for https://github.com/actions/runner-images/issues/9272
          sudo chown -R runner:admin /usr/local/
          brew update
          brew install airspy boost gnuradio hackrf libbladerf librtlsdr pybind11 six uhd qt@6 || true

          cd /tmp
          git clone https://gitea.osmocom.org/sdr/gr-osmosdr.git
          cd gr-osmosdr
          mkdir build
          cd build
          cmake -DCMAKE_CXX_FLAGS=-Wno-register ..
          LIBRARY_PATH=/usr/local/opt/icu4c/lib make -j4
          sudo make install
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Configure
        run: mkdir build && cd build && cmake -DOSX_AUDIO_BACKEND:STRING=${{ matrix.backend }} ..
      - name: Compile
        working-directory: build
        run: make -j4
  windows-build:
    runs-on: windows-latest
    name: Windows CI
    defaults:
      run:
        shell: msys2 {0}
    steps:
    - name: Setup MSYS2
      uses: msys2/setup-msys2@v2
      with:
        msystem: MINGW64
        update: true
        install: >-
          git
          make
        pacboy: >-
          toolchain:p
          cmake:p
          ninja:p
          libusb:p
          boost:p
          qt6-base:p
          qt6-svg:p
          spdlog:p
          volk:p
          libsndfile:p
          fftw:p
    - name: Clone and build GNU Radio
      working-directory: ${{ runner.temp }}
      run: |
        git clone --depth 1 https://github.com/gnuradio/gnuradio.git
        cd gnuradio
        cmake -S . -B build \
          -DCMAKE_INSTALL_PREFIX=${RUNNER_TEMP}/msys64/mingw64 \
          -DENABLE_DEFAULT=OFF \
          -DENABLE_COMMON_PCH=ON \
          -DENABLE_GNURADIO_RUNTIME=ON \
          -DENABLE_GR_ANALOG=ON \
          -DENABLE_GR_AUDIO=ON \
          -DENABLE_GR_BLOCKS=ON \
          -DENABLE_GR_DIGITAL=ON \
          -DENABLE_GR_FFT=ON \
          -DENABLE_GR_FILTER=ON \
          -DENABLE_GR_NETWORK=ON
        cmake --build build
        cmake --install build
    - name: Clone and build gr-osmosdr
      working-directory: ${{ runner.temp }}
      run: |
        git clone https://gitea.osmocom.org/sdr/gr-osmosdr.git
        cd gr-osmosdr
        cmake -S . -B build \
          -DCMAKE_INSTALL_PREFIX=${RUNNER_TEMP}/msys64/mingw64 \
          -DENABLE_DEFAULT=OFF \
          -DENABLE_FILE=ON
        cmake --build build
        cmake --install build
    - name: Checkout code
      uses: actions/checkout@v4
    - name: Configure, compile & install
      run: |
        cmake -S . -B build \
          -DCMAKE_INSTALL_PREFIX=C:/gqrx
        cmake --build build
        cmake --install build
