version: 0.4.0.{build}

platform:
  - x86
  - x64

configuration:
  - Release
  - Debug

environment:
  matrix:
    - VSVER: 12
#    - VSVER: 10

install:
  - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
        https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
        Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
        throw "There are newer queued builds for this pull request, failing early." }
  - date /T & time /T
  - set OPENSSL_VER=1_0_2e
  - ps: >-
      If ($env:Platform -Match "x86") {
        $env:VCVARS_PLATFORM="x86"
        $env:ENV_PLATFORM="x86"
        $env:NMAKE_ARCH=""
        $env:OPENSSL_PF="Win32"
      } Else {
        $env:VCVARS_PLATFORM="amd64"
        $env:ENV_PLATFORM="x64"
        $env:NMAKE_ARCH="BUILD_ON=WIN64 BUILD_FOR=WIN64"
        $env:OPENSSL_PF="Win64"
      }
  - ps: >-
      If (!(Test-Path -Path "C:\OpenSSL-${env:OPENSSL_PF}" )) {
          Start-FileDownload https://slproweb.com/download/${env:OPENSSL_PF}OpenSSL-${env:OPENSSL_VER}.exe -FileName C:\WinOpenSSL.exe
      C:\WinOpenSSL.exe /SILENT /VERYSILENT /SP- /SUPPRESSMSGBOXES /NORESTART
      }
  - ps: >-
      If ($env:Configuration -Like "*Debug*") {
        $env:NMAKE_EXTRA="DEBUG=yes ${env:NMAKE_EXTRA}"
      }
  - ps: $env:VSCOMNTOOLS=(Get-Content ("env:VS" + "$env:VSVER" + "0COMNTOOLS"))
  - echo "Using Visual Studio %VSVER%.0 at %VSCOMNTOOLS%"
  - call "%VSCOMNTOOLS%\..\..\VC\vcvarsall.bat" %VCVARS_PLATFORM%

build_script:
  - nmake /f Makefile.mak %NMAKE_ARCH% %NMAKE_EXTRA%
  - appveyor PushArtifact src\libp11.dll
  - appveyor PushArtifact src\libp11.lib
  - appveyor PushArtifact src\pkcs11.dll
  - appveyor PushArtifact src\pkcs11.lib
  - ps: >-
      If ($env:Configuration -Like "*Debug*") {
         Push-AppveyorArtifact src\libp11.pdb
         Push-AppveyorArtifact src\pkcs11.pdb
      }

cache:
  - C:\OpenSSL-Win32
  - C:\OpenSSL-Win64
