# Linux and Mac Build Configuration for Travis

language: cpp

os:
  - linux
  - osx

# Use Ubuntu 14.04 LTS (Trusty) as the Linux testing environment.
sudo: false
dist: trusty

env:
  - GLSLANG_BUILD_TYPE=Release
  - GLSLANG_BUILD_TYPE=Debug

compiler:
  - clang
  - gcc

matrix:
  fast_finish: true # Show final status immediately if a test fails.
  exclude:
    # Skip GCC builds on Mac OS X.
    - os: osx
      compiler: gcc
  include:
    # Additional build using Android NDK.
    - env: BUILD_NDK=ON

cache:
  apt: true

branches:
  only:
    - master

addons:
  apt:
    packages:
      - clang-3.6
      - ninja-build

install:
  # Install ninja on Mac OS X.
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update && brew install ninja; fi
  # Make sure that clang-3.6 is selected on Linux.
  - if [[ "$TRAVIS_OS_NAME" == "linux" && "$CC" == "clang" ]]; then
      export CC=clang-3.6 CXX=clang++-3.6;
    fi
  # Download Android NDK and Android CMake toolchain file.
  - if [[ "$BUILD_NDK" == "ON" ]]; then
      git clone --depth=1 https://github.com/urho3d/android-ndk.git $HOME/android-ndk;
      export ANDROID_NDK=$HOME/android-ndk;
      git clone --depth=1 https://github.com/taka-no-me/android-cmake.git $HOME/android-cmake;
      export TOOLCHAIN_PATH=$HOME/android-cmake/android.toolchain.cmake;
    fi

before_script:
  - git clone https://github.com/google/googletest.git External/googletest

script:
  - mkdir build && cd build
  # For Android, do release building using NDK without testing.
  # For Linux and macOS, do debug/release building with testing.
  - if [[ "$BUILD_NDK" == "ON" ]]; then
      cmake -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_PATH}
            -DANDROID_NATIVE_API_LEVEL=android-12
            -DCMAKE_BUILD_TYPE=Release
            -DANDROID_ABI="armeabi-v7a with NEON"
            -DBUILD_TESTING=OFF
            -GNinja ..;
      ninja;
    else
      cmake -DCMAKE_BUILD_TYPE=${GLSLANG_BUILD_TYPE}
            -DCMAKE_INSTALL_PREFIX=`pwd`/install
            -GNinja ..;
      ninja install;
      ctest --output-on-failure &&
      cd ../Test && ./runtests;
    fi
