# This is the configuration file for AppVeyor builds.
# Look at the following for reference:
# https://www.appveyor.com/docs/appveyor-yml

# Notes:
#   - Minimal appveyor.yml file is an empty file. All sections are optional.
#   - Indent each level of configuration with 2 spaces. Do not use tabs!
#   - All section names are case-sensitive.
#   - Section names should be unique on each level.

#---------------------------------#
#      general configuration      #
#---------------------------------#

# version format
version: 1.0.{build}

#---------------------------------#
#   environment configuration     #
#   and build matrix              #
#---------------------------------#

environment:
  vsversion: none
  arch: default
  matrix:
  # Visual Studio builds
#  - platform: vs
#    vsversion: 2008
#    arch: x86
  - platform: vs
    vsversion: 2010
    arch: x86
  - platform: vs
    vsversion: 2012
    arch: x86
  - platform: vs
    vsversion: 2013
    arch: x86
  - platform: vs
    vsversion: 2015
    arch: x86
  - platform: vs
    vsversion: 2017
    arch: x86
    APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
  - platform: vs
    vsversion: 2010
    arch: x64
  - platform: vs
    vsversion: 2012
    arch: x64
  - platform: vs
    vsversion: 2013
    arch: x64
  - platform: vs
    vsversion: 2015
    arch: x64
  - platform: vs
    vsversion: 2017
    arch: x64
    APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
  - platform: vs
    vsversion: 2012
    arch: ARM
  - platform: vs
    vsversion: 2013
    arch: ARM
  - platform: vs
    vsversion: 2015
    arch: ARM
  - platform: vs
    vsversion: 2017
    arch: ARM
    APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
  # Other compilers than Visual Studio
  - platform: msvc
  - platform: cygwin
  - platform: mingw32
  - platform: mingw64msys

# clone directory
clone_folder: c:\projects\check

# build Configuration, i.e. Debug, Release, etc.
configuration: Release


#---------------------------------#
#   scripts that are called at    #
#   the very beginning, before    #
#   repo cloning                  #
#---------------------------------#

init:
  - git config --global core.autocrlf input


#---------------------------------#
#   scripts to run before build   #
#---------------------------------#

before_build:
  - cd c:\projects\check
  - echo Directory before starting build...
  - dir
  - echo Starting pre-build step...
  # Remove the following from the path, as it will interfere with
  # the MinGW builds
  - set PATH=%PATH:C:\Program Files\Git\usr\bin;=%
  - if %platform%==msvc call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
  - if %platform%==msvc cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=%P%
  - if %platform%==vs (
      set "makecommand=Visual Studio"
    )
  - set "vcx=false"
  - set "vcs=false"
  - if %platform%==vs (
      set "vcx=true"
    )
  - if %vsversion%==2005 (
      set "vcs=true"
    )
  - if %vsversion%==2008 (
      set "vcs=true"
    )
  - if %vcs%==true (
      set "vcx=false"
    )
  - if %vsversion%==2005 (
      set "makecommand=%makecommand% 8 %vsversion%"
    )
  - if %vsversion%==2008 (
      set "makecommand=%makecommand% 9 %vsversion%"
    )
  - if %vsversion%==2010 (
      set "makecommand=%makecommand% 10 %vsversion%"
    )
  - if %vsversion%==2012 (
      set "makecommand=%makecommand% 11 %vsversion%"
    )
  - if %vsversion%==2013 (
      set "makecommand=%makecommand% 12 %vsversion%"
    )
  - if %vsversion%==2015 (
      set "makecommand=%makecommand% 14 %vsversion%"
    )
  - if %vsversion%==2017 (
      set "makecommand=%makecommand% 15 %vsversion%"
    )
  - if %arch%==x64 (
      set "makecommand=%makecommand% Win64"
    )
  - if %arch%==ARM (
      set "makecommand=%makecommand% ARM"
    )
  - if %platform%==vs cmake -G "%makecommand%" -DCMAKE_INSTALL_PREFIX=%P%
  - if %platform%==cygwin set PATH=C:\cygwin\bin;%PATH%
  - if %platform%==cygwin bash -c "autoreconf -i"
  - if %platform%==cygwin bash -c "./configure"
  - if %platform%==mingw32 set PATH=C:\MinGW\bin;%PATH%
  - if %platform%==mingw32 cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=%P%
  - if %platform%==mingw64msys set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%
  - if %platform%==mingw64msys bash -c "autoreconf -i"
  - if %platform%==mingw64msys bash -c "./configure"


#---------------------------------#
#   build code and unit tests     #
#---------------------------------#

build_script:
  - echo Directory before running build step...
  - dir
  - echo Building code...
  - if %platform%==msvc nmake
  - if %platform%==cygwin bash -c "make"
  - if %platform%==mingw32 mingw32-make
  - if %platform%==mingw64msys bash -c "make"
  - if %vcx%==true msbuild /p:Platform=%arch% "ALL_BUILD.vcxproj"
  # Build for VS2008 (prior to the vsxproj file format), only 32 bit
  # Options see https://msdn.microsoft.com/en-us/library/ms164311.aspx
  - if %vcs%==true msbuild /p:Configuration=Release /p:Platform=Win32 /nologo /v:d "check.sln"


#---------------------------------#
#   run unit test for all x86     #
#   and x64 architecture builds   #
#---------------------------------#

test_script:
  - set "testplatform=%platform%"
  # Can not run ARM builds on x86/x64 build images
  - if %arch%==ARM (
      set "testplatform=none"
    )
  - echo Project directory before running test step...
  - dir
  - echo tests directory before running test step...
  - dir tests
  - echo Running unit tests...
  - if %testplatform%==msvc nmake test VERBOSE=1 CTEST_OUTPUT_ON_FAILURE=TRUE
  - if %testplatform%==vs ctest --extra-verbose -C Release
  - if %testplatform%==cygwin bash -c "make check"
  - if %testplatform%==mingw32 tests\check_check.exe
  - if %testplatform%==mingw64msys bash -c "tests/check_check"
  - if %testplatform%==none echo Can not test for %arch% here


#---------------------------------#
#   build and test completed      #
#---------------------------------#

on_finish:
  - echo Project directory after running tests...
  - dir
  - echo tests directory after running tests...
  - dir tests
  - if %platform%==cygwin bash -c "cat tests/test-suite.log || true"

