# Appveyor OS list
# Windows Server 2012 R2 (x64) <== Appveyor default image
# Visual Studio 2015

# os: expands the build matrix to include multiple os's
os:
  - Windows Server 2012

# compiler: expands the build matrix to include multiple compilers (per os)
platform:
  - x64

configuration:
  - Release

# Only clone the top level commit; don't bother with history
shallow_clone: true

# environment: specifies additional global variables to define per row in build matrix
environment:
  global:
    CLSPARSE_ROOT: "%APPVEYOR_BUILD_FOLDER%\\bin\\nmake\\release"
    OPENCL_ROOT: "%APPVEYOR_BUILD_FOLDER%\\bin\\opencl"
    # BOOST_ROOT: "C:/Libraries/boost"   # boost 1.56, 32-bit only
    BOOST_ROOT: "C:\\Libraries\\boost_1_58_0"
    OPENCL_REGISTRY: "https://www.khronos.org/registry/cl"

init:
  - echo init step
  - cmake --version
  - C:\"Program Files (x86)"\"Microsoft Visual Studio 12.0"\VC\vcvarsall.bat %PLATFORM%
  # Uncomment the following to display Remote Desktop connection details
  # - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

# We need to create an opencl import library that clsparse can link against
# Vendor based OpenCL packages are hard to use because of download size, registration requirements
# and unattended installs not well supported
install:
  - echo install step
  - ps: mkdir $env:OPENCL_ROOT
  - ps: pushd $env:OPENCL_ROOT
  - ps: $opencl_registry = $env:OPENCL_REGISTRY
  # This downloads the source to the Khronos ICD library
  - git clone --depth 1 https://github.com/KhronosGroup/OpenCL-ICD-Loader.git
  - ps: mv ./OpenCL-ICD-Loader/* .
  # This downloads all the opencl header files
  # The cmake build files expect a directory called inc
  - ps: mkdir inc/CL
  - git clone --depth 1 https://github.com/KhronosGroup/OpenCL-Headers.git inc/CL
  - ps: wget $opencl_registry/api/2.1/cl.hpp -OutFile inc/CL/cl.hpp
  # - ps: dir; if( $lastexitcode -eq 0 ){ dir include/CL } else { Write-Output boom }
  # Create the static import lib in a directory called lib, so findopencl() will find it
  - ps: mkdir lib
  - ps: pushd lib
  - cmake -G "NMake Makefiles" ..
  - nmake
  - ps: popd
  # Switch to OpenCL 1.2 headers
  - ps: pushd inc/CL
  - git fetch origin opencl12:opencl12
  - git checkout opencl12
  - ps: popd
  # Rename the inc directory to include, so FindOpencl() will find it
  - ps: ren inc include
  - ps: popd

# before_build is used to run configure steps
before_build:
  - echo before_build step
  # Boost 1.58 is not installed in typical fashion, help FindBoost() find binary libs with BOOST_LIBRARYDIR
  - ps: $env:BOOST_LIBRARYDIR = "$env:BOOST_ROOT/lib64-msvc-12.0"
  - ps: mkdir $env:CLSPARSE_ROOT
  - ps: pushd $env:CLSPARSE_ROOT
  - cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DclSPARSE_BUILD64=ON -DBUILD_Boost=OFF -DBUILD_gMock=ON -DBUILD_clSPARSE=ON -DBUILD_SAMPLES=ON %APPVEYOR_BUILD_FOLDER%

# build_script invokes the compiler
build_script:
  - echo build_script step
  - nmake clSPARSE-samples
  - cd clSPARSE-build
  - nmake package

after_build:
  - echo after_build step
  - ps: ls $env:CLSPARSE_ROOT\clSPARSE-build
  - ps: mv $env:CLSPARSE_ROOT\clSPARSE-build\*.zip $env:APPVEYOR_BUILD_FOLDER
  - ps: popd

# Appyeyor will save a copy of the package in it's personal storage
artifacts:
  - path: '*.zip'
    name: binary_zip
    type: zip

# on_finish always executes regardless of passed or failed builds
on_finish:
  - echo on_finish step

# Appveyor will push the artifacts it has saved to GitHub 'releases' tab
deploy:
  provider: GitHub
  # This uses an personal OAuth token generated by kknox
  auth_token:
    secure: dRXIWJKpU7h2RsHX7RqmyYCtCw+Q9O3X5MArloY6p34GZC1w7bp+jQYTZqbdO7bw
  artifact: binary_zip
  draft: true
  prerelease: true
  on:
    appveyor_repo_tag: true

  # Uncomment the following to pause the VM and wait for RDP connetion to debug
  # - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
