version: '{branch}-{build}'
image: Visual Studio 2015
clone_folder: C:\projects\oiio
test: off
configuration:
    - Release
    # - Debug
platform:
    - x64
# branches:
#   only:
#     - master
environment:
  matrix:
    - CMAKE_PLATFORM: "Visual Studio 14 2015 Win64"
      PYTHON_DIR: "C:\\Python27-x64"
      tbs_arch: "x64"
      tbs_tools: "msvc14"
      tbs_static_runtime: 0

cache:
  - C:\tools\vcpkg\installed
  #- C:\tools\vcpkg -> appveyor.yml
  #- C:\projects\ext -> appveyor.yml
  # The -> means that the cache dir is discarded if appveyor.yml has changed

install:
  - ps: $OIIO_INSTALL_BEGIN=Get-Date
  - cinstall: python
  - git submodule update --init --recursive
  - set CMAKE_PREFIX_PATH=C:/Sys;%APPVEYOR_BUILD_FOLDER%/ext;c:/tools/vcpkg/installed/%platform%-windows
  - set CMAKE_LIBRARY_PATH=C:/Sys/lib;%APPVEYOR_BUILD_FOLDER%/ext/lib
  - set CMAKE_INCLUDE_PATH=C:/Sys/include;%APPVEYOR_BUILD_FOLDER%/ext/include
  - mkdir c:\sys
  - mkdir ext
  - cd ext
  - mkdir lib
  - mkdir include

  # Boost
  # 1.63 is already installed on appveyor, just use it
  - set BOOST_ROOT=C:\Libraries\boost_1_66_0
  - set CMAKE_PREFIX_PATH=%CMAKE_PREFIX_PATH%;%BOOST_ROOT%

  # Install a bunch of vcpkg dependencies. We rely on the run-to-run caching
  # of these, but if the cache is flushed, it takes too long to rebuild them
  # all, so we stage it.
  - vcpkg list
  - vcpkg update
  # - vcpkg help triplet

  # Dependencies that don't take too long, just build them unconditionally.
  - vcpkg install zlib:"%platform%"-windows
  - vcpkg install tiff:"%platform%"-windows
  - vcpkg install libpng:"%platform%"-windows
  - vcpkg install openexr:"%platform%"-windows
  - vcpkg install freetype:"%platform%"-windows
  - vcpkg install giflib:"%platform%"-windows
  - vcpkg install libwebp:"%platform%"-windows
  - vcpkg install openjpeg:"%platform%"-windows
  - vcpkg install ptex:"%platform%"-windows
  - vcpkg install libraw:x64-windows

  # These are all deps for qt, install these first to isolate from the
  # huge time it takes qt to build
  - vcpkg install double-conversion:x64-windows
  - vcpkg install harfbuzz:x64-windows
  - vcpkg install libpq:x64-windows
  - vcpkg install openssl:x64-windows
  - vcpkg install pcre2:x64-windows
  - vcpkg install ragel:x64-windows
  - vcpkg install sqlite3:x64-windows

  # Qt
  - set CMAKE_PREFIX_PATH=%CMAKE_PREFIX_PATH%;C:\Qt\5.12


  # Expensive optional deps only build if there's plenty of time left.
  # If we run out the clock, the cache won't be saved.
  # - ps: |
  #       $OIIO_BUILD_NOW=Get-Date
  #       if (($OIIO_BUILD_NOW-$OIIO_INSTALL_BEGIN).TotalMinutes -gt 15) {
  #           Add-AppveyorMessage -Message "OIIO low on time, skippping dependency qt5-base"
  #       } else {
  #           vcpkg install qt5-base:x64-windows
  #       }

  # Wish list:
  #   OpenCV
  #   ffmpeg
  #   OpenColorIO

  - cd ..
  - dir C:\Sys
  # - dir C:\Sys\include
  # - dir C:\Sys\lib
  - vcpkg list
  - dir c:\tools\vcpkg
  - dir c:\tools\vcpkg\installed\x64-windows
  - dir C:\projects\oiio\ext
  - dir C:\projects\oiio\ext\include
  - dir C:\projects\oiio\ext\lib


build_script:
  - echo Running cmake...
  - cd c:\projects\oiio
  - mkdir build
  - mkdir build\windows64
  - cd build\windows64
  - cmake -G "%CMAKE_PLATFORM%" -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake \
      -DPYTHON_INCLUDE_DIR:PATH=%PYTHON_DIR%/include -DPYTHON_LIBRARY:FILEPATH=%PYTHON_DIR%/libs/python27.lib -DPYTHON_EXECUTABLE:FILEPATH=%PYTHON_DIR%/python.exe -DCMAKE_LIBRARY_PATH=%CMAKE_LIBRARY_PATH% -DCMAKE_INCLUDE_PATH=%CMAKE_INCLUDE_PATH%  -DCMAKE_PREFIX_PATH=%CMAKE_PREFIX_PATH% -DOPENEXR_ROOT_DIR=C:\projects\oiio\ext -DVERBOSE=1 -DBUILD_MISSING_DEPS=1 ../..
  - dir c:\projects\oiio
  - dir c:\projects\oiio\build
  - dir c:\projects\oiio\build\windows64
  - cmake --build . --config %CONFIGURATION%


matrix:
    fast_finish: true
