name: Build

on: 
  push:
    branches-ignore:
      - 'l10n_master'
  pull_request:
    branches:
      - '*'

jobs:
  windows:
    name: "Windows 64-bit"
    strategy:
      matrix: 
        runner: [ windows-2019 ]
        include:
          - runner: windows-2019
            id: windows2019
            windows_sdk: "10.0.18362.0"
            cmake_generator: "Visual Studio 16 2019"
            cmake_generator_platform: "x64"
    runs-on: ${{ matrix.runner }}
    env:
      CMAKE_GENERATOR: ${{ matrix.cmake_generator }}
      CMAKE_GENERATOR_PLATFORM: ${{ matrix.cmake_generator_platform }}
      CMAKE_GENERATOR_TOOLSET: "host=x64"
      CMAKE_SYSTEM_VERSION: ${{ matrix.windows_sdk }}
    steps:
    - name: "Clone Repository"
      uses: actions/checkout@v1
    - name: "Clone Submodules"
      shell: bash
      run: git submodule update --init --recursive
    - name: "Cache: Prerequisites"
      uses: actions/cache@v2
      with:
        path: |
          build/temp/qt-download/qt-download-prefix/src/qt.7z
          build/temp/obsdeps-download/obsdeps-download-prefix/src/obsdeps.7z
          build/temp/libobs-download/libobs-download-prefix/src/libobs.7z
        key: ${{ matrix.id }}
    - name: "Configure Project"
      shell: bash
      run: |
        cmake -H. -B"build/temp" -DCMAKE_INSTALL_PREFIX="build/distrib" -DCMAKE_PACKAGE_NAME="streamfx-${{ matrix.id }}" -DCMAKE_PACKAGE_PREFIX="build/package" -DOBS_DOWNLOAD=ON
    - name: "Build Project"
      shell: bash
      run: |
        cmake --build "build/temp" --config RelWithDebInfo --target INSTALL
    - name: "Package Project"
      shell: bash
      run: |
        mkdir build/package
        cmake --build "build/temp" --config RelWithDebInfo --target PACKAGE_7Z
        cmake --build "build/temp" --config RelWithDebInfo --target PACKAGE_ZIP
    - name: "Package Installer (Prereqs)"
      run: |
        curl "-kL" "https://cdn.xaymar.com/ci/innosetup-6.0.3.exe" "-f" "--retry" "5" "-o" "inno.exe"
        .\inno.exe /VERYSILENT /SP- /SUPPRESSMSGBOXES /NORESTART
    - name: "Package Installer (Compile)"
      run: |
        & 'C:\Program Files (x86)\Inno Setup 6\ISCC.exe' /Qp ".\build\temp\installer.iss"
    - name: "Upload Artifacts"
      uses: actions/upload-artifact@v1
      with:
        name: ${{ matrix.id }}
        path: build/package
  ubuntu:
    name: "Ubuntu 64-bit"
    strategy:
      matrix:
        ubuntu: [ bionic ]
        compiler: [ gcc, clang ]
        compiler-version: [ 8, 9, 10 ]
        exclude:
          - ubuntu: bionic
            compiler: gcc
            compiler-version: 10
          - ubuntu: bionic
            compiler: clang
            compiler-version: 8
        include:
          - ubuntu: bionic
            compiler: gcc
            compiler-version: 8
            compiler-cxx: g++
            runner: ubuntu-18.04
            packages: gcc-8 g++8
            extra_command: sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8
            id: ubuntu1804-gcc8
          - ubuntu: bionic
            compiler: gcc
            compiler-version: 9
            compiler-cxx: g++
            runner: ubuntu-latest
            packages: gcc-9 g++9
            extra_command: sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 800 --slave /usr/bin/g++ g++ /usr/bin/g++-9
            id: ubuntu1910-gcc9
          - ubuntu: bionic
            compiler: clang
            compiler-version: 9
            compiler-cxx: clang++
            runner: ubuntu-18.04
            packages: clang-9
            extra_command: ""
            id: ubuntu1804-clang9
          - ubuntu: bionic
            compiler: clang
            compiler-version: 10
            compiler-cxx: clang++
            runner: ubuntu-latest
            packages: clang-10
            extra_command: ""
            id: ubuntu1910-clang10
    runs-on: ${{ matrix.runner }}
    env:
      CMAKE_GENERATOR: "Ninja"
      CC: ${{ matrix.compiler }}
      CXX: ${{ matrix.compiler-cxx }}
    steps:
    - name: "Clone Repository"
      uses: actions/checkout@v1
    - name: "Prerequisites: Submodules"
      shell: bash
      run: git submodule update --init --recursive
    - name: "Prerequisites: Apt-Get"
      shell: bash
      run: |
        if [ "${{ matrix.compiler }}" == "clang" ]; then
          wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
          sudo add-apt-repository "deb http://apt.llvm.org/${{ matrix.ubuntu }}/ llvm-toolchain-${{ matrix.ubuntu }}-${{ matrix.compiler-version }} main"
        fi
        sudo apt-get -qq update
        sudo apt-get purge libjpeg9-dev:amd64 libjpeg8-dev:amd64 libjpeg-turbo8-dev:amd64
        sudo apt-get install \
          ${{ matrix.packages }} \
          build-essential \
          checkinstall \
          pkg-config \
          cmake \
          ninja-build \
          git \
          qt5-default libqwt-qt5-dev libqt5svg5-dev
        ${{ matrix.extra_command }}
    - name: "Cache: Prerequisites"
      uses: actions/cache@v2
      with:
        path: |
          build/temp/libobs-download/libobs-download-prefix/src/libobs.7z
        key: ${{ matrix.id }}
    - name: "Configure Project"
      shell: bash
      run: |
        cmake -H. -B"build/temp" -DCMAKE_INSTALL_PREFIX="build/distrib" -DCMAKE_PACKAGE_NAME="streamfx-${{ matrix.id }}" -DCMAKE_PACKAGE_PREFIX="build/package" -DOBS_DOWNLOAD=ON
    - name: "Build Project"
      shell: bash
      run: |
        cmake --build "build/temp" --config RelWithDebInfo --target install
    - name: "Package Project"
      shell: bash
      run: |
        mkdir build/package
        cmake --build "build/temp" --config RelWithDebInfo --target PACKAGE_7Z
        cmake --build "build/temp" --config RelWithDebInfo --target PACKAGE_ZIP
    - name: "Upload Artifacts"
      uses: actions/upload-artifact@v1
      with:
        name: ${{ matrix.id }}
        path: build/package