name: CMake

on:
  push:
    branches:
      - 'master'
  pull_request:
    branches: [ master ]

env:
  BUILD_TYPE: RelWithDebInfo

jobs:
  Ubuntu:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Add OpenMW PPA Dependencies
        run: sudo add-apt-repository ppa:openmw/openmw; sudo apt-get update

      - name: Install Building Dependencies
        run: sudo CI/install_debian_deps.sh gcc openmw-deps openmw-deps-dynamic

      - name: Prime ccache
        uses: hendrikmuhs/ccache-action@v1
        with:
          key: ${{ matrix.os }}-${{ env.BUILD_TYPE }}
          max-size: 1000M

      - name: Configure
        run: cmake . -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DOPENMW_USE_SYSTEM_RECASTNAVIGATION=1 -DUSE_SYSTEM_TINYXML=1 -DBUILD_UNITTESTS=1 -DCMAKE_INSTALL_PREFIX=install

      - name: Build
        run: make -j3

      - name: Test
        run: ./openmw_test_suite

          #    - name: Install
          #      shell: bash
          #      run: cmake --install .

          #    - name: Create Artifact
          #      shell: bash
          #      working-directory: install
          #      run: |
          #        ls -laR
          #        7z a ../build_artifact.7z .

  #    - name: Upload Artifact
  #      uses: actions/upload-artifact@v1
  #      with:
  #        path: ./build_artifact.7z
  #        name: build_artifact.7z

  MacOS:
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v2

      - name: Install Building Dependencies
        run: CI/before_install.osx.sh

      - name: Prime ccache
        uses: hendrikmuhs/ccache-action@v1
        with:
          key: ${{ matrix.os }}-${{ env.BUILD_TYPE }}
          max-size: 1000M

      - name: Configure
        run: |
          rm -fr build  # remove the build directory
          CI/before_script.osx.sh
      - name: Build
        run: |
          cd build 
          make -j $(sysctl -n hw.logicalcpu) package
