image: Visual Studio 2017

environment:
  MSYSTEM: MINGW64  # use MSYS2 shell
  matrix:
  - CFG: MINGW64
    UPLOAD: ON
  - CFG: MSVC

cache: c:\tools\vcpkg\installed\

install:
  # upgrade git for vcpkg: https://github.com/appveyor/ci/issues/2097
  - if %CFG% == MSVC (choco upgrade git -y & vcpkg install mpir:x64-windows)

build_script:
  - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
  - cd %APPVEYOR_BUILD_FOLDER% && mkdir build && cd build
  # disable slow LTO
  - if %CFG% == MSVC (cmake ../src
      -DCMAKE_BUILD_TYPE=Release
      -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake
      -DLEAN_EXTRA_CXX_FLAGS=/GL-
      -DLEAN_EXTRA_LINKER_FLAGS_MSVC=/LTCG:OFF
      -G "NMake Makefiles" &&
      cmake --build .)
  - if %CFG% == MINGW64 (C:\msys64\usr\bin\bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER/build &&
      OPTIONS='';
      if [[ $APPVEYOR_SCHEDULED_BUILD == True ]]; then . ../script/setup_nightly.sh; fi &&
      cmake ../src -DINCLUDE_MSYS2_DLLS=ON -DCMAKE_BUILD_TYPE=Release $OPTIONS -G 'Unix Makefiles' &&
      cmake --build . &&
      cpack")

test_script:
  - C:\msys64\usr\bin\bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER/build && ctest -j4 --output-on-failure"
  # # don't test packages when building nightly
  # - C:\msys64\usr\bin\bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER/packages &&
  #     if [[ ! -f ../build/nightly.sh ]]; then
  #       ../bin/leanpkg configure &&
  #       for d in _target/deps/*; do (cd $d; ../../../../bin/leanpkg test || exit 1); done;
  #     fi"
  # - C:\msys64\usr\bin\bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER &&
  #     if [[ $UPLOAD == ON && $GH_TOKEN && $APPVEYOR_BRANCH == master ]]; then
  #       . build/nightly.sh &&
  #       bash script/deploy_nightly.sh build/lean-*-windows.zip;
  #     fi"

artifacts:
  - path: build\lean-*-windows.zip
    name: binary

deploy:
  description: 'Lean release'
  provider: GitHub
  auth_token:
    secure: d+yPrDEAbiNrcf3a0PDNYEn/ieOOP6M7cP9zje+QkJEjHFdjBjWMe8b3qrC1hrus
  artifact: binary
  draft: false
  prerelease: false
  on:
    appveyor_repo_tag: true
    UPLOAD: ON
