# Notes:
#   - Minimal appveyor.yml file is an empty file. All sections are optional.
#   - Indent each level of configuration with 2 spaces. Do not use tabs!
#   - All section names are case-sensitive.
#   - Section names should be unique on each level.

#---------------------------------#
#      general configuration      #
#---------------------------------#

# version format
version: 4.5.{build}

image:
  - Visual Studio 2022
  - Visual Studio 2019
  
# branches to build
branches:
  # whitelist
  only:
    - develop

  # blacklist
  # except:
  #   - gh-pages

# Do not build on tags (GitHub only)
skip_tags: true

#---------------------------------#
#    environment configuration    #
#---------------------------------#
environment:
  global:
    1_8: &1_8 1.8.23
    1_10: &1_10 1.10.11
    1_12: &1_14 1.14.3
    HDF5_1_8_VER: *1_8   
    HDF5_1_10_VER: *1_10
    HDF5_1_14_VER: *1_14
  matrix:
  - build_opt: -D CGNS_BUILD_SHARED:BOOL=OFF -D CGNS_USE_SHARED:BOOL=OFF -D CGNS_ENABLE_64BIT:BOOL=OFF
    HDF5_VER: *1_8
    HDF_DIR: "/Program Files/HDF_Group/HDF5/%HDF5_VER%/cmake"
  - build_opt: -D CGNS_BUILD_SHARED:BOOL=OFF -D CGNS_USE_SHARED:BOOL=OFF -D CGNS_ENABLE_64BIT:BOOL=ON
    HDF5_VER: *1_10
    HDF_DIR: "/Program Files/HDF_Group/HDF5/%HDF5_VER%/cmake"
  - build_opt: -D CGNS_BUILD_SHARED:BOOL=ON -D CGNS_USE_SHARED:BOOL=ON -D CGNS_ENABLE_64BIT:BOOL=ON
    HDF5_VER: *1_10
    HDF_DIR: "/Program Files/HDF_Group/HDF5/%HDF5_VER%/cmake"
  - build_opt: -D CGNS_BUILD_SHARED:BOOL=OFF -D CGNS_USE_SHARED:BOOL=OFF -D CGNS_ENABLE_64BIT:BOOL=ON
    HDF5_VER: *1_14
    HDF_DIR: "/Program Files/HDF_Group/HDF5/%HDF5_VER%/cmake"
  - build_opt: -D CGNS_BUILD_SHARED:BOOL=ON -D CGNS_USE_SHARED:BOOL=ON -D CGNS_ENABLE_64BIT:BOOL=ON
    HDF5_VER: *1_14
    HDF_DIR: "/Program Files/HDF_Group/HDF5/%HDF5_VER%/cmake"

for:
-
  matrix:
    only:
      - image: Visual Studio 2019
  environment:
      GENERATOR: "Visual Studio 16 2019"
      ARCH: "x64"
      SHORTGEN: "vs16"
-
  matrix:
    only:
      - image: Visual Studio 2017
  environment:
      GENERATOR: "Visual Studio 15 2017"
      ARCH: "x64"
      SHORTGEN: "vs15"
-
  matrix:
    only:
      - image: Visual Studio 2022
  environment:
      GENERATOR: "Visual Studio 17 2022"
      ARCH: "x64"
      SHORTGEN: "vs17"

# scripts that are called at very beginning, before repo cloning
init:
  - git config --global core.autocrlf input

# clone directory
clone_folder: c:\projects\CGNS

# scripts that run after cloning repository
install:
  # by default, all script lines are interpreted as batch
  #- echo This is batch
  # to run script as a PowerShell command prepend it with ps:
  #- ps: Write-Host 'This is PowerShell'
  # batch commands start from cmd:
  #- cmd: echo This is batch again
  #- cmd: set MY_VAR=12345

# install hdf5
  - set PATH=C:\Program Files\Git\mingw64\bin;%PATH%
  - mkdir 1.8
  - cd 1.8
  - set HDF5_1_8_VER=%HDF5_1_8_VER%
  - curl -O https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.23/bin/windows/hdf5-%HDF5_1_8_VER%-Std-win10_64-%SHORTGEN%.zip
  - ps: Expand-Archive hdf5-$($env:HDF5_1_8_VER)-Std-win10_64-$($env:SHORTGEN).zip -DestinationPath .
  - cd hdf
  - msiexec /i HDF5-%HDF5_1_8_VER%-win64.msi /quiet /qn /norestart /log install.log
  - type install.log
  - cd ..\..
  - mkdir 1.10
  - cd 1.10
  - set HDF5_1_10=%HDF5_1_10_VER%
  - curl -O https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.11/bin/windows/hdf5-%HDF5_1_10_VER%-Std-win10_64-%SHORTGEN%.zip
  - ps: Expand-Archive hdf5-$($env:HDF5_1_10_VER)-Std-win10_64-$($env:SHORTGEN).zip -DestinationPath .
  - cd hdf
  - msiexec /i HDF5-%HDF5_1_10_VER%-win64.msi /quiet /qn /norestart /log install.log
  - type install.log
  - cd ..\..
  - mkdir 1.14
  - cd 1.14
  - set HDF5_1_14=%HDF5_1_14_VER%
  - curl -O https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.3/bin/windows/hdf5-%HDF5_1_14_VER%-Std-win10_64-%SHORTGEN%.zip
  - ps: Expand-Archive hdf5-$($env:HDF5_1_14_VER)-Std-win10_64-$($env:SHORTGEN).zip -DestinationPath .
  - cd hdf
  - msiexec /i HDF5-%HDF5_1_14_VER%-win64.msi /quiet /qn /norestart /log install.log
  - type install.log
  - cd ..\..

#---------------------------------#
#       build configuration       #
#---------------------------------#

# build platform, i.e. x86, x64, Any CPU. This setting is optional.
platform: Any CPU

# to add several platforms to build matrix:
#platform:
#  - x86
#  - Any CPU

# build Configuration, i.e. Debug, Release, etc.
configuration:
  - Release

# scripts to run before build
before_build:
  - echo Running cmake...
  - mkdir c:\projects\CGNS_BUILD
  - cd c:\projects\CGNS_BUILD
  - cmake --version
  - SET HDF5_DIR=/Program Files/HDF_Group/HDF5/%HDF5_VER%/cmake
  - cmake -G "%GENERATOR%" -A "%ARCH%" ^
     %build_opt% ^
     -D CMAKE_C_FLAGS:STRING="" ^
     -D CMAKE_BUILD_TYPE:STRING=Release ^
     -D HDF5_NEED_ZLIB:BOOL=ON ^
     -D CMAKE_STATIC_LINKER_FLAGS:STRING="" ^
     -D CGNS_ENABLE_HDF5:BOOL=ON ^
     -D CGNS_ENABLE_TESTS:BOOL=ON ^
     -D CGNS_ENABLE_LFS:BOOL=OFF ^
     -D CGNS_BUILD_CGNSTOOLS:BOOL=OFF ^
     -D CGNS_ENABLE_SCOPING:BOOL=OFF ^
     -D CGNS_ENABLE_FORTRAN:BOOL=OFF ^
     -D CGNS_ENABLE_PARALLEL:BOOL=OFF ^
     -D CMAKE_INSTALL_PREFIX:PATH="." c:\projects\CGNS

build_script:
  - cmd: cmake --build . --config "%configuration%"

test_script:
  - cmd: set PATH=C:\projects\CGNS_BUILD\src\%configuration%;%PATH%
  - cmd: set PATH=C:\Program Files\HDF_Group\HDF5\%HDF5_VER%\bin;%PATH%
  - cmd: ctest -C %configuration%

after_test:
  - cmd: cmake --install . --config "%configuration%"
