language: cpp
sudo: false

matrix:
  include:
    - env: BUILD_TYPE=debug
    - env: BUILD_TYPE=release

    # GCC 6
    - env: C_COMPILER=gcc-6 CXX_COMPILER=g++-6
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - gcc-6
            - g++-6

    # Clang 3.8 address sanitizer
    - env: BUILD_TYPE=asan C_COMPILER=clang-3.8 CXX_COMPILER=clang++-3.8
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
            - llvm-toolchain-precise-3.8
          packages:
            - clang-3.8

    # mingw-w64 Win64 cross-compile
    - env: BUILD_TYPE=cross C_COMPILER=x86_64-w64-mingw32-gcc CXX_COMPILER=x86_64-w64-mingw32-g++
      addons:
        apt:
          packages:
            - mingw-w64
            - binutils-mingw-w64
            - binutils-mingw-w64-i686
            - binutils-mingw-w64-x86-64
            - gcc-mingw-w64
            - gcc-mingw-w64-i686
            - gcc-mingw-w64-x86-64
            - g++-mingw-w64
            - g++-mingw-w64-i686
            - g++-mingw-w64-x86-64

branches:
  only:
  - master

before_install:
  - if [ -n "${C_COMPILER}" ]; then export CC="${C_COMPILER}"; fi
  - if [ -n "${CXX_COMPILER}" ]; then export CXX="${CXX_COMPILER}"; fi
  - ${CXX} --version
  - cmake --version
  - mkdir build
  - cd build

before_script:
  - |-
    case "${BUILD_TYPE}" in
      "coverage")
        cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_COVERAGE=ON ..
        ;;
      "asan")
        cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZER=address ..
        ;;
      "ubsan")
        cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZER=undefined ..
        ;;
      "cross")
        cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw64.cmake -DCMAKE_EXE_LINKER_FLAGS="-static -s" ..
        ;;
      "release")
        cmake -DCMAKE_BUILD_TYPE=Release ..
        ;;
      *)
        cmake ..
        ;;
    esac


script:
  - make VERBOSE=1
  - if [ "x${BUILD_TYPE}" != "xcross" ]; then ctest -V; fi
