version: '4.1.0-{build}'

branches:
  only:
    - master
    - development
    - /^v\d+\.\d+(\.\d+)?(-\S*)?$/

skip_commits:
  files:
    - '*.md'
    - LICENSE

environment:
  auth_token:
    secure: rLuHhO0prerqoGCYmfOoyxqcwwamCXtuZtl4Jzqeu3aGgflk0mnX1fogLq68YcRW
  matrix:
    - prepare_mode: YES
      name: win32-prepare
      platform: amd64_x86
      qt: msvc2015
    - prepare_mode: NO
      name: win32
      platform: amd64_x86
      qt: msvc2015
    - prepare_mode: NO
      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
      name: win64
      platform: amd64
      qt: msvc2017_64
    - prepare_mode: NO
      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
      name: win32
      platform: mingw
      qt: mingw492_32

clone_folder: c:\dev\qevercloud

init:
  - if not %platform%==mingw set PATH=C:\Qt\5.10\%qt%\bin;%PATH%
  - if %platform%==mingw set PATH=C:\MinGW\bin;C:\Program Files (x86)\CMake\bin;C:\Qt\5.5\%qt%\bin;%PATH%
  - if %platform%==mingw set ORIGPATH=%PATH%
  - if %platform%==mingw set PATH=%PATH:C:\Program Files\Git\usr\bin;=%
  - if %qt%==msvc2017_64 set BUILD_SUITE=VS2017_x64
  - if %qt%==msvc2015 set BUILD_SUITE=VS2015_x86
  - if %platform%==mingw set BUILD_SUITE=MinGW_x86
  - if %platform%==mingw set DEPLOYMENT_TARGET=qevercloud-windows-qt55-%BUILD_SUITE%.zip
  - if not %platform%==mingw set DEPLOYMENT_TARGET=qevercloud-windows-qt510-%BUILD_SUITE%.zip
  - if %platform%==amd64 call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
  - if %platform%==amd64_x86 call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %platform%
  - if not %platform%==mingw (set makefiles="NMake Makefiles") else (set makefiles="MinGW Makefiles")
  - if %platform%==mingw (set use_webkit=1) else (set use_webkit=0)
  - if %qt%==msvc2017_64 set PATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin";%PATH%
  - if %qt%==msvc2015 set PATH="C:\Program Files (x86)\MSBuild\14.0\Bin";%PATH%

install:
  - echo "Downloading ciuploadtool"
  - md c:\dev\ciuploadtool
  - cd c:\dev\ciuploadtool
  - curl -fsSL https://github.com/d1vanov/ciuploadtool/releases/download/continuous-master/ciuploadtool_windows_x86.zip -o ciuploadtool_windows_x86.zip
  - 7z x ciuploadtool_windows_x86.zip
  - if %prepare_mode%==YES c:\dev\ciuploadtool\ciuploadtool.exe -preponly -suffix="%APPVEYOR_REPO_BRANCH%"
  - ps: if ($env:prepare_mode -eq "YES") { throw "Failing in order to stop the current build matrix job early" }

before_build:
  - cd c:\dev\qevercloud
  - md build

build_script:
  - cd build
  - if %platform%==mingw cmake .. -G %makefiles% -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX="c:/dev/qevercloud/build/installdir" -DUSE_QT5_WEBKIT=%use_webkit% -DCMAKE_PREFIX_PATH="C:/Qt/5.5/%qt%"
  - if not %platform%==mingw cmake .. -G %makefiles% -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX="c:/dev/qevercloud/build/installdir" -DUSE_QT5_WEBKIT=%use_webkit% -DCMAKE_PREFIX_PATH="C:/Qt/5.10/%cd%"
  - cmake --build . --target all
  - cmake --build . --target check
  - cmake --build . --target install
  - if %platform%==mingw set PATH=%ORIGPATH%

after_build:
  - cd c:\dev\qevercloud\build\installdir
  - 7z a %DEPLOYMENT_TARGET% *
  - cp %DEPLOYMENT_TARGET% %APPVEYOR_BUILD_FOLDER%
  - cd %APPVEYOR_BUILD_FOLDER%
  - c:\dev\ciuploadtool\ciuploadtool.exe -suffix="%APPVEYOR_REPO_BRANCH%" %DEPLOYMENT_TARGET%

artifacts:
  - path: '*.zip'
    name: archive

matrix:
  allow_failures:
    - prepare_mode: YES
  # Disable until https://github.com/appveyor/ci/issues/1231 is fixed
  # fast_finish: true
