image: Visual Studio 2019

platform:
- x64

environment:
  matrix:
  - VS_VERSION: Visual Studio 16 2019

shallow_clone: true

build_script:
  - echo build_script
  - set "BUILD_FOLDER=%APPVEYOR_BUILD_FOLDER:\=/%"
  - if "%platform%" == "x64" SET VS_FULL=%VS_VERSION%
  - if "%platform%" == "x64" SET VS_ARCH=x64
  - if "%platform%" == "x86" SET VS_FULL=%VS_VERSION%
  - if "%platform%" == "x86" SET VS_ARCH=Win32 
  - if "%platform%" == "x86" SET SDK=release-1928
  - if "%platform%" == "x64" SET SDK=release-1928-x64
  - if "%platform%" == "x64" call "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build/vcvars64.bat"
  - if "%platform%" == "x86" call "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build/vcvars32.bat"
  - echo "%VS_FULL%"
  - set SDK_ZIP=%SDK%-dev.zip
  - set SDK_URL=http://download.gisinternals.com/sdk/downloads/%SDK_ZIP%
  - echo "%SDK_ZIP%"
  - echo "%SDK_URL%"
  - mkdir sdk
  - cd sdk
  - appveyor DownloadFile "%SDK_URL%"
  - 7z x "%SDK_ZIP%" > nul
  - cd %APPVEYOR_BUILD_FOLDER%
  - set SDK_PREFIX=%BUILD_FOLDER%/sdk/%SDK%
  - set SDK_INC=%BUILD_FOLDER%/sdk/%SDK%/include
  - set SDK_LIB=%BUILD_FOLDER%/sdk/%SDK%/lib
  - set SDK_BIN=%BUILD_FOLDER%/sdk/%SDK%/bin
  - set REGEX_DIR=%BUILD_FOLDER%/sdk/support/regex-0.12

  - cd %SDK_LIB%
  - copy "%SDK_LIB%/libfcgi.lib" "%SDK_LIB%/fcgi.lib" /Y
  - copy "%SDK_LIB%/apr-1.lib" "%SDK_LIB%/apr-1-1.lib" /Y
  - copy "%SDK_LIB%/libapr-1.lib" "%SDK_LIB%/apr-1.lib" /Y > nul
  - copy "%SDK_LIB%/aprutil-1.lib" "%SDK_LIB%/aprutil-1-1.lib" /Y > nul
  - copy "%SDK_LIB%/libaprutil-1.lib" "%SDK_LIB%/aprutil-1.lib" /Y > nul

  - cd %APPVEYOR_BUILD_FOLDER%

  - mkdir build
  - cd build
  - cmake -G "%VS_FULL%" -A %VS_ARCH% 
        -DWITH_APACHE=OFF 
        -DWITH_FCGI=ON 
        -DWITH_PCRE=ON 
        -DWITH_TIFF=OFF 
        -DCMAKE_PREFIX_PATH=%SDK_PREFIX% ..
  - cmake --build . --config Release

  - copy "Release\*dll" "%SDK_BIN%" /Y > nul
  - copy "cgi\Release\*exe" "%SDK_BIN%" /Y > nul
  - copy "util\Release\*exe" "%SDK_BIN%" /Y > nul

after_build:
  - cd %SDK_BIN%
  - 7z a %APPVEYOR_BUILD_FOLDER%\mapcache.zip mapcache.dll
        mapcache.fcgi.exe mapcache_seed.exe %APPVEYOR_BUILD_FOLDER%\mapcache.xml

test_script:
  - cd %SDK_BIN%
  - set MAPCACHE_CONFIG_FILE=%APPVEYOR_BUILD_FOLDER%\mapcache.xml
  - set PATH_INFO="/"
  - set REQUEST_METHOD=GET
  - set QUERY_STRING="SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image/png&SRS=EPSG:4326&BBOX=0,0,10,10&WIDTH=256&HEIGHT=256&LAYERS=test&TRANSPARENT=TRUE"
  - mapcache.fcgi.exe
  - mapcache_seed.exe -h

deploy: off

artifacts:
  - path: mapcache.zip
    name: mapcache
    type: zip
