language: generic

sudo: false

# Save common build configurations as shortcuts, so we can reference them later.
addons_shortcuts:
  addons_clang35: &clang35
    apt:
      sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5' ]
      packages: [ 'clang-3.5', 'llvm-3.5-dev' ]
  addons_clang36: &clang36
    apt:
      sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6' ]
      packages: [ 'clang-3.6' ]
  addons_clang37: &clang37
    apt:
      sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7' ]
      packages: [ 'clang-3.7' ]
  addons_clang38: &clang38
    apt:
      sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.8' ]
      packages: [ 'clang-3.8']
  addons_clang39: &clang39
    apt:
      sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise' ]
      packages: [ 'clang-3.9']
  addons_gcc47: &gcc47
    apt:
      sources: [ 'ubuntu-toolchain-r-test' ]
      packages: [ 'g++-4.7' ]
  addons_gcc48: &gcc48
    apt:
      sources: [ 'ubuntu-toolchain-r-test' ]
      packages: [ 'g++-4.8' ]
  addons_gcc49: &gcc49
    apt:
      sources: [ 'ubuntu-toolchain-r-test' ]
      packages: [ 'g++-4.9' ]
  addons_gcc5: &gcc5
    apt:
      sources: [ 'ubuntu-toolchain-r-test' ]
      packages: [ 'g++-5' ]

matrix:
  include:
    - os: osx
      osx_image: xcode7
      env: TEST_GYP_BUILD=True
      compiler: clang
    - os: linux
      compiler: "clang35"
      env: CXX=clang++-3.5 COVERAGE=True
      addons: *clang35
    - os: linux
      compiler: "clang36"
      env: CXX=clang++-3.6
      addons: *clang36
    - os: linux
      compiler: "clang37"
      env: CXX=clang++-3.7
      addons: *clang37
    - os: linux
      compiler: "clang38"
      env: CXX=clang++-3.8
      addons: *clang38
    - os: linux
      compiler: "clang38"
      env: CXX=clang++-3.8 CXX_STD=c++14
      addons: *clang38
    # not whitelisted yet: https://github.com/travis-ci/apt-package-whitelist/issues/2764
    #- os: linux
    #  compiler: "clang39"
    #  env: CXX=clang++-3.9
    #  addons: *clang39
    - os: linux
      compiler: "gcc47"
      env: CXX=g++-4.7
      addons: *gcc47
    - os: linux
      compiler: "gcc48"
      env: CXX=g++-4.8
      addons: *gcc48
    - os: linux
      compiler: "gcc49"
      env: CXX=g++-4.9
      addons: *gcc49
    - os: linux
      compiler: "gcc49"
      env: CXX=g++-4.9 CXX_STD=c++14
      addons: *gcc49
    - os: linux
      compiler: "gcc5"
      env: CXX=g++-5 CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0"
      addons: *gcc5
    - os: linux
      compiler: "gcc5"
      env: CXX=g++-5 CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=1"
      addons: *gcc5

before_install:
 - echo ${CXX}
 - if [[ $(uname -s) == 'Linux' ]]; then
     export PYTHONPATH=$(pwd)/.local/lib/python2.7/site-packages;
   else
     export PYTHONPATH=$(pwd)/.local/lib/python/site-packages;
   fi
 - if [[ ${COVERAGE:-0} == 'True' ]]; then
     PYTHONUSERBASE=$(pwd)/.local pip install --user cpp-coveralls;
   fi

install:
 - make test
 - make bench
 - make sizes
 - scripts/run_compilation_failure_tests.sh
 - if [[ ${TEST_GYP_BUILD:-0} == 'True' ]]; then
     make clean;
     make gyp;
   fi

script:
 - if [[ ${COVERAGE:-0} == 'True' ]]; then
    make clean;
    make coverage;
    ./out/cov-test;
    cp unit*gc* test/;
    ./.local/bin/cpp-coveralls --gcov /usr/bin/llvm-cov-3.5 --gcov-options '\-lp' -i optional.hpp -i recursive_wrapper.hpp -i variant.hpp -i variant_io.hpp;
   fi
