###################################
#   Widelands.org                 #
#                                 #
#   Appveyor build configuration  #
###################################

image: Visual Studio 2019

init:
  - cmd: "IF \"%PLATFORM%\" == \"x86\" (set MINGWPATH=C:\\msys64\\mingw32\\bin& set MINGWSUFFIX=i686& set MINGWINCLUDE=C:\\msys64\\mingw32\\include& set BITS=32) ELSE (set MINGWPATH=C:\\msys64\\mingw64\\bin& set MINGWSUFFIX=x86_64& set MINGWINCLUDE=C:\\msys64\\mingw64\\include& set BITS=64)"

install:
  # Installing various utilities
  # As of 2019-12-06 we have to install 'chocolatey-core.extension' beforehand.
  # Otherwise installing 'InnoSetup' will fail.
  - choco install -y chocolatey-core.extension
  - choco install -y InnoSetup
  - cmd: "set PATH=%MINGWPATH%;C:\\msys64\\usr\\bin;C:\\Program Files (x86)\\Inno Setup 5;%PATH%"
  - cmd: "set CC=%MINGWPATH%\\gcc.exe"
  - cmd: "set CXX=%MINGWPATH%\\g++.exe"
  - cmd: "set CURL_VERSION=7.73.0"
  # deleting broken repo from mirrorlist
  # - cmd: "bash --login -c \"sed -i 7,8d C:/msys64/etc/pacman.d/mirrorlist.msys\""
  # - cmd: "bash --login -c \"sed -i 7,8d C:/msys64/etc/pacman.d/mirrorlist.mingw32\""
  # - cmd: "bash --login -c \"sed -i 7,8d C:/msys64/etc/pacman.d/mirrorlist.mingw64\""
  # Update msys2 system (twice, first run does system packages)
  - cmd: "bash --login -c \"pacman -Suuyy --noconfirm\""
  # deleting broken repo from mirrorlist again
  # - cmd: "bash --login -c \"sed -i 7,8d C:/msys64/etc/pacman.d/mirrorlist.msys\""
  # - cmd: "bash --login -c \"sed -i 7,8d C:/msys64/etc/pacman.d/mirrorlist.mingw32\""
  # - cmd: "bash --login -c \"sed -i 7,8d C:/msys64/etc/pacman.d/mirrorlist.mingw64\""
  - cmd: "bash --login -c \"pacman -Suuyy --noconfirm\""
  # Installed required libs
  - cmd: "bash --login -c \"pacman --noconfirm -S mingw-w64-%MINGWSUFFIX%-ninja mingw-w64-%MINGWSUFFIX%-boost mingw-w64-%MINGWSUFFIX%-curl mingw-w64-%MINGWSUFFIX%-SDL2_ttf mingw-w64-%MINGWSUFFIX%-SDL2_mixer mingw-w64-%MINGWSUFFIX%-SDL2_image mingw-w64-%MINGWSUFFIX%-glew\""
  # Fix CURL
  - cmd: "bash --login -c \"curl -Lo curl.zip \\\"https://curl.haxx.se/windows/dl-%CURL_VERSION%/curl-%CURL_VERSION%-win%BITS%-mingw.zip\\\" && unzip curl.zip && mv --force curl-%CURL_VERSION%-win%BITS%-mingw/lib/libcurl.a C:/msys64/mingw%BITS%/lib/\""

shallow_clone: false

branches:
  only:
    - master

build_script:
  - cmd: cd %APPVEYOR_BUILD_FOLDER%
  - cmd: md build
  - cmd: cd build
  # detect revision
  - cmd: set /p WIDELANDS_VERSION_STRING=<%APPVEYOR_BUILD_FOLDER%\WL_RELEASE
  - cmd: "cmake -G \"Ninja\" -DBoost_NO_BOOST_CMAKE=ON -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DOPTION_BUILD_WINSTATIC=ON -DOPTION_BUILD_WEBSITE_TOOLS=OFF -DOPTION_ASAN=OFF -DOPTION_BUILD_CODECHECK=OFF -DCMAKE_JOB_POOLS=\"linking=1\" -DCMAKE_JOB_POOL_LINK=linking %APPVEYOR_BUILD_FOLDER%"
  - cmd: "cmake --build ."
on_success:
  - cmd: strip -sv %APPVEYOR_BUILD_FOLDER%\build\src\widelands.exe
  - cmd: ISCC /q /o%APPVEYOR_BUILD_FOLDER% /fWidelands-%PLATFORM%-%WIDELANDS_VERSION_STRING% c:\projects\widelands\utils\win32\innosetup\Widelands.iss
  - appveyor PushArtifact %APPVEYOR_BUILD_FOLDER%\Widelands-%PLATFORM%-%WIDELANDS_VERSION_STRING%.exe

artifacts:
  - path: Widelands-$(PLATFORM)-$(WIDELANDS_VERSION_STRING).exe
    name: Widelands Setup

platform:
  - x64
  - x86

configuration:
  - Release
