cache:
  - cmake\dependencies -> appveyor.yml, **\CMakeLists.txt, cmake\dep-targets.cmake

## shallow_clone: true
## clone_depth: 50

environment:
  DIST_DIR: '%APPVEYOR_BUILD_FOLDER%\dist'
  CMAKE_DIST_DIR: C:/projects/simh/dist

  matrix:
    ##+
    ## The matrix is ordered by relative popularity/priority:
    ##-

    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
      SIMH_BUILD_FLAVOR: vs2022
      ## Static library support available in this vcpkg install.
      VCPKG_ROOT: C:\Tools\vcpkg

    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
      SIMH_BUILD_FLAVOR: vs2019
      ## Static library support available in this vcpkg install.
      VCPKG_ROOT: C:\Tools\vcpkg

    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
      SIMH_BUILD_FLAVOR: vs2017

    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
      SIMH_BUILD_FLAVOR: vs2022-xp

    ## These Appveyor VM images exist, aren't strictly needed to build XP-compatible
    ## executables.

    # - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
    #   SIMH_BUILD_FLAVOR: vs2019-xp

    # - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
    #   SIMH_BUILD_FLAVOR: vs2017-xp

    # - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
    #   SIMH_BUILD_FLAVOR: vs2015

    - APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu
      SIMH_BUILD_FLAVOR: ninja

    - APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004
      SIMH_BUILD_FLAVOR: unix

    ## Older image -- still needed?
    # - APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu1604
    #   SIMH_BUILD_FLAVOR: unix

    ## These images have cmake 3.12, which is too old. Could build if
    ## cmake were upgraded in the image in the before_build stanza, but
    ## that subverts the image's purpose.

    # - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
    #   SIMH_BUILD_FLAVOR: vs2013
    #
    # - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2012
    #   SIMH_BUILD_FLAVOR: vs2012
    #
    # - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2008
    #   SIMH_BUILD_FLAVOR: vs2008
    
    ## - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
    ##   SIMH_BUILD_FLAVOR: mingw
    ##   MINGW: C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0

    ## Here's how you would build with Ninja. It's going to build the same executables
    ## as the MinGW flavor, which is why it's skipped here.
    # - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
    #   SIMH_BUILD_FLAVOR: ninja
    #   MINGW: C:\msys64\mingw32\bin
    #
    # - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
    #   SIMH_BUILD_FLAVOR: 2017
    # - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
    #   SIMH_BUILD_FLAVOR: 2015

matrix:
  ## Bail if a job fails, don't start new ones.
  fast_finish: true

skip_commits:
  files:
    - 'doc/*'
    - '**/*.md'

configuration:
  - Debug
  - Release

build:
  parallel: true                  # enable MSBuild parallel builds
  verbosity: minimal

before_build:
  - cmd: |
      if "%SIMH_BUILD_FLAVOR%"=="ninja" ( choco install ninja )
      if not exist "cmake\dependencies" ( mkdir "cmake\dependencies" )

  - sh: |
      case "${APPVEYOR_BUILD_WORKER_IMAGE}" in
      Ubuntu*)
        ## .travis/deps.sh will try to install cmake, but that's not desirable
        sudo apt-get update -yqqm
        sudo apt-get install -ym pkg-config
        sudo apt-get install -ym libpcre3-dev
        sudo apt-get install -ym libegl1-mesa-dev libgles2-mesa-dev
        sudo apt-get install -ym libsdl2-dev libpcap-dev libvdeplug-dev
        sudo apt-get install -ym libsdl2-ttf-dev
        sudo apt-get install -ym libedit-dev
        ;;
      *)
        echo "Update before_build for ${APPVEYOR_BUILD_WORKER_IMAGE}"
        exit 99
      esac

build_script:
  ## Need to use cmd, per Appveyor support. PowerShell has issues with output.
  ## Specifically, when CMake prints the "old CMake version, won't CPack" warning,
  ## Appveyor terminates the build injudiciously. The workaround is cmd.
  ##
  ## LTO works reliably on VS 2022 and 2019. Hangs while building SEL32 on VS 2017.
  - cmd: |
      SETLOCAL EnableExtensions
      if not "%MINGW%"=="" ( set "PATH=%MINGW%;%PATH%" )
      if "%SIMH_BUILD_FLAVOR%"=="vs2022" set LTO=-lto
      if "%SIMH_BUILD_FLAVOR%"=="vs2019" set LTO=-lto
      powershell -File .\cmake\cmake-builder.ps1 -flavor %SIMH_BUILD_FLAVOR% -config %CONFIGURATION% %LTO% -parallel -clean -notest -noinstall -verbose

  - sh: |
      case "${APPVEYOR_BUILD_WORKER_IMAGE}" in
      Ubuntu1604)
        ## LTO support is either incompletely installed or not installed at all.
        LTO=
        ;;
      *)
        LTO="--lto"
        ;;
      esac
      cmake/cmake-builder.sh --flavor ${SIMH_BUILD_FLAVOR} --config ${CONFIGURATION} ${LTO} \
          --verbose --parallel --clean --notest --noinstall

test_script:
  #   - ps: |
  #       if ($isWindows) {
  #         Write-Output "cmake\cmake-builder.ps1 -testonly -config ${env:CONFIGURATION} -flavor ${env:SIMH_BUILD_FLAVOR}"
  #         cmake\cmake-builder.ps1 -testonly -config ${env:CONFIGURATION} -flavor ${env:SIMH_BUILD_FLAVOR}
  #       }

  - cmd: |
      powershell -File .\cmake\cmake-builder.ps1 -flavor %SIMH_BUILD_FLAVOR% -config %CONFIGURATION% -testonly

  - sh: |
      cmake/cmake-builder.sh --testonly --config ${CONFIGURATION} --flavor ${SIMH_BUILD_FLAVOR}

##+
## Don't package artifacts -- only GitHub does this now.
##-
# after_test:
# 
# artifacts:
#   - path: PACKAGES\*.zip

# notifications:
#   - provider: Email
#     to:
#       - Mark@infocomm.com
#       - lars@nocrew.org
#     on_build_success: false
