platform:
  - x64

branches:
  only:
    - master # This will still build PRs.

image:
  - Visual Studio 2017
  - Visual Studio 2019

environment:
  matrix:
    - arch: x86
    - arch: x64

install:
  # Configuration for Meson
  - cmd: if %arch%==x86 (set PYTHON_ROOT=C:\python37) else (set PYTHON_ROOT=C:\python37-x64)
  - cmd: echo Using Python at %PYTHON_ROOT%
  - cmd: set PATH=%cd%;%PYTHON_ROOT%;%PYTHON_ROOT%\Scripts;%PATH%
  - cmd: pip install ninja meson

  # Enable using MSVC through command line.
  - cmd: if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" ( call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" %arch% )
  - cmd: if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2019" ( call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" %arch% )

build_script:
  - cmd: echo Building on image %APPVEYOR_BUILD_WORKER_IMAGE%, arch %arch%.

  # Build with CMake (builds both static and shared library).
  - cmd: if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" ( SET "GENERATOR_VS_VERSION=Visual Studio 15 2017" )
  - cmd: if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2019" ( SET "GENERATOR_VS_VERSION=Visual Studio 16 2019" )
  - cmd: if "%arch%"=="x86" ( SET "GENERATOR_VS_ARCH=Win32" )
  - cmd: if "%arch%"=="x64" ( SET "GENERATOR_VS_ARCH=x64" )
  - cmd: cmake -G "%GENERATOR_VS_VERSION%" -A %GENERATOR_VS_ARCH% .
  - cmd: cmake --build . --config Release

  # Build with Meson.
  # Static library.
  - cmd: meson setup --backend=ninja -Ddefault_library=static meson-build-static .
  - cmd: meson compile -v -C meson-build-static
  # Shared library.
  - cmd: meson setup --backend=ninja -Ddefault_library=shared meson-build-shared .
  - cmd: meson compile -v -C meson-build-shared

test_script:
  # Test what CMake built.
  - cmd: bin\Release\runTests.exe

  # Test what Meson built.
  - cmd: meson test -C meson-build-static
  - cmd: meson test -C meson-build-shared
