# 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:
    CLFFT_ROOT: "%APPVEYOR_BUILD_FOLDER%\\bin\\nmake\\release"
    OPENCL_ROOT: "%APPVEYOR_BUILD_FOLDER%\\bin\\opencl"
    FFTW_ROOT: "%APPVEYOR_BUILD_FOLDER%\\bin\\fftw"
    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 clfft 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 Installing OpenCL
  - 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

  - echo Installing FFTW
  - ps: mkdir $env:FFTW_ROOT
  - ps: pushd $env:FFTW_ROOT
  # This downloads the windows 64-bit pre-compiled dlls
  - ps: wget ftp://ftp.fftw.org/pub/fftw/fftw-3.3.4-dll64.zip -OutFile fftw-3.3.4-dll64.zip
  - ps: 7z x fftw-3.3.4-dll64.zip
#  - ps: pushd fftw-3.3.4-dll64
  - ps: lib /machine:x64 /def:libfftw3-3.def
  - ps: lib /machine:x64 /def:libfftw3f-3.def
  - ps: lib /machine:x64 /def:libfftw3l-3.def

# 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:CLFFT_ROOT
  - ps: pushd $env:CLFFT_ROOT
  - cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DBoost_NO_SYSTEM_PATHS=OFF -DOPENCL_ROOT=%OPENCL_ROOT% %APPVEYOR_BUILD_FOLDER%/src

# build_script invokes the compiler
build_script:
  - echo build_script step
  - nmake package

after_build:
  - echo after_build step
  - ps: ls $env:CLFFT_ROOT
  - ps: mv $env:CLFFT_ROOT\*.zip $env:APPVEYOR_BUILD_FOLDER

# 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
  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'))
