stages:
  - build
  
Debian:
  tags:
    - docker
    - linux
  image: gcc
  cache:
    key: apt-cache
    paths:
    - apt-cache/
  before_script:
    - export APT_CACHE_DIR=`pwd`/apt-cache && mkdir -pv $APT_CACHE_DIR
    - apt-get update -yq 
    - apt-get -o dir::cache::archives="$APT_CACHE_DIR" install -y cmake libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-iostreams-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev libsdl2-dev libqt4-dev libopenal-dev libopenscenegraph-3.4-dev libunshield-dev libtinyxml-dev
  # - apt-get install -y libmygui-dev libbullet-dev  # to be updated to latest below because stretch is too old
    - curl -L http://archive.ubuntu.com/ubuntu/pool/universe/b/bullet/libbullet-dev_2.87+dfsg-2_amd64.deb -o libbullet-dev_2.87+dfsg-2_amd64.deb
    - curl -L http://archive.ubuntu.com/ubuntu/pool/universe/b/bullet/libbullet2.87_2.87+dfsg-2_amd64.deb -o libbullet2.87_2.87+dfsg-2_amd64.deb
    - curl -L http://archive.ubuntu.com/ubuntu/pool/universe/m/mygui/libmygui.openglplatform0debian1v5_3.2.2+dfsg-1_amd64.deb -o libmygui.openglplatform0debian1v5_3.2.2+dfsg-1_amd64.deb
    - curl -L http://archive.ubuntu.com/ubuntu/pool/universe/m/mygui/libmyguiengine3debian1v5_3.2.2+dfsg-1_amd64.deb -o libmyguiengine3debian1v5_3.2.2+dfsg-1_amd64.deb
    - curl -L http://archive.ubuntu.com/ubuntu/pool/universe/m/mygui/libmygui-dev_3.2.2+dfsg-1_amd64.deb -o libmygui-dev_3.2.2+dfsg-1_amd64.deb
    - dpkg --ignore-depends=libmygui.ogreplatform0debian1v5 -i *.deb 
  stage: build
  script: 
    - cores_to_use=$((`nproc`-2)); if (( $cores_to_use < 1 )); then cores_to_use=1; fi
    - mkdir build; cd build; cmake -DCMAKE_BUILD_TYPE=MinSizeRel ../
    - make -j$cores_to_use
    - DESTDIR=artifacts make install
  artifacts:
    paths:
      - build/artifacts/
MacOS:
  tags:
    - macos
    - xcode
  except:
    - branches # because our CI VMs are not public, MRs can't use them and timeout
  stage: build
  allow_failure: true
  script:
    - rm -fr build/*  #  remove anything in the build directory
    - CI/before_install.osx.sh
    - CI/before_script.osx.sh
    - cd build; make -j2 package
  artifacts:
    paths:
      - build/OpenMW-*.dmg

Windows:
  tags:
    - win10
    - msvc2017
  except:
    - branches # because our CI VMs are not public, MRs can't use them and timeout
  stage: build
  allow_failure: true
  script:
    # - env  # turn on for debugging
    - sh %CI_PROJECT_DIR%/CI/before_script.msvc.sh -c Release -p x64 -v 2017 -V
    - SET msBuildLocation="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe"
    - call %msBuildLocation% MSVC2017_64\OpenMW.sln /t:Build /p:Configuration=Release /m:%NUMBER_OF_PROCESSORS%
    - 7z a OpenMW_MSVC2017_64_%CI_BUILD_REF_NAME%_%CI_BUILD_ID%.zip %CI_PROJECT_DIR%\MSVC2017_64\Release\
  cache:
    paths:
    - deps
  artifacts:
    paths:
    - "*.zip"
