environment:
  ARMADILLO_DOWNLOAD: "https://sourceforge.net/projects/arma/files/armadillo-9.800.6.tar.xz"
  BLAS_LIBRARY: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll.a"
  BLAS_LIBRARY_DLL: "%APPVEYOR_BUILD_FOLDER%/OpenBLAS.0.2.14.1/lib/native/lib/x64/libopenblas.dll"

  matrix:
    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
      VSVER: Visual Studio 15 2017 Win64
      MSBUILD: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe

    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
      VSVER: Visual Studio 16 2019
      MSBUILD: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe

    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
      VSVER: Visual Studio 17 2022
      MSBUILD: C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe

configuration: Release

install:
  - ps: nuget install OpenBLAS -o "${env:APPVEYOR_BUILD_FOLDER}"

build_script:
  # First, download and build Armadillo.
  - cd ..
  - appveyor DownloadFile %ARMADILLO_DOWNLOAD% -FileName armadillo.tar.xz
  - 7z x armadillo.tar.xz -so -txz | 7z x -si -ttar > nul
  - cd armadillo-9.800.6 && mkdir build && cd build
  - >
    cmake -G "%VSVER%"
    -DBLAS_LIBRARY:FILEPATH=%BLAS_LIBRARY%
    -DLAPACK_LIBRARY:FILEPATH=%BLAS_LIBRARY%
    -DCMAKE_PREFIX:FILEPATH="%APPVEYOR_BUILD_FOLDER%/armadillo"
    -DBUILD_SHARED_LIBS=OFF
    -DCMAKE_BUILD_TYPE=Release ..
  - >
    "%MSBUILD%" "armadillo.sln"
    /m /verbosity:quiet /p:Configuration=Release;Platform=x64
  - cd ../..

  # Now build ensmallen.
  - cd ensmallen && mkdir build && cd build
  - >
    cmake -G "%VSVER%"
    -DARMADILLO_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%/../armadillo-9.800.6/include/
    -DARMADILLO_LIBRARIES=%BLAS_LIBRARY%
    -DLAPACK_LIBRARY=%BLAS_LIBRARY%
    -DBLAS_LIBRARY=%BLAS_LIBRARY%
    -DCMAKE_BUILD_TYPE=Release ..
  - >
    "%MSBUILD%" "ensmallen.sln"
    /m /verbosity:minimal /nologo /p:BuildInParallel=false

  # Run tests after copying libraries.
  - ps: cp C:\projects\ensmallen\OpenBLAS.0.2.14.1\lib\native\bin\x64\*.* C:\projects\ensmallen\build\
  - ctest -C Release -V --output-on-failure .
