# This template installs CMake (if doesn't exist in the systems)

steps:
  - bash: |
      set -ex
      if [ -x "`command -v cmake`" ]; then
        echo `command -v cmake` `cmake --version` installed
      else
        curl -O https://cmake.org/files/v3.4/cmake-3.4.1-Darwin-x86_64.tar.gz
        tar xf cmake-3.4.1-Darwin-x86_64.tar.gz
        export CMAKE_BIN_PATH="`pwd`/cmake-3.4.1-Darwin-x86_64/CMake.app/Contents/bin"
        echo "##vso[task.prependpath]$CMAKE_BIN_PATH"
      fi
    displayName: "Install CMake (macOS)"
    condition: eq(variables['Agent.OS'], 'Darwin')

  - bash: |
      set -ex
      if [ -x "`command -v cmake`" ]; then
        echo `command -v cmake` `cmake --version` installed
      else
        curl -O https://cmake.org/files/v3.4/cmake-3.4.1-Linux-x86_64.tar.gz
        tar xf cmake-3.4.1-Linux-x86_64.tar.gz
        export CMAKE_BIN_PATH="`pwd`/cmake-3.4.1-Linux-x86_64/CMake.app/Contents/bin"
        echo "##vso[task.prependpath]$CMAKE_BIN_PATH"
      fi
    displayName: "Install CMake (Linux)"
    condition: eq(variables['Agent.OS'], 'Linux')

  - bash: |
      set -ex
      if [ -x "`command -v cmake`" ]; then
        echo `command -v cmake` `cmake --version` installed
      else
        chocolatey install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
      fi
    displayName: "Install CMake (Windows)"
    condition: eq(variables['Agent.OS'], 'Windows_NT')

  - bash: |
      set -ex
      cmake --version
    displayName: CMake version
