# Travis-CI build script for tlx

language: cpp

sudo: false

matrix:
  include:
    # gcc 4.7, Debug only
    - env: CMAKE_CC="gcc-4.7" CMAKE_CXX="g++-4.7" BUILD_TYPE="Debug" COMPILER_FLAGS=""
      os: linux
      addons: &gcc48
        apt:
          update: true
          sources:
            - ubuntu-toolchain-r-test
            - george-edison55-precise-backports # cmake 3.2.3
          packages:
            - cmake
            - cmake-data
            - g++-4.7

    # gcc 4.8, Debug only
    - env: CMAKE_CC="gcc-4.8" CMAKE_CXX="g++-4.8" BUILD_TYPE="Debug" COMPILER_FLAGS=""
      os: linux
      addons: &gcc48
        apt:
          update: true
          sources:
            - ubuntu-toolchain-r-test
            - george-edison55-precise-backports # cmake 3.2.3
          packages:
            - cmake
            - cmake-data
            - g++-4.8

    # gcc 4.9 with AddressSanitizer, Debug only
    - env: CMAKE_CC="gcc-4.9" CMAKE_CXX="g++-4.9" BUILD_TYPE="Debug" COMPILER_FLAGS="-fsanitize=address"
      os: linux
      addons: &gcc49
        apt:
          update: true
          sources:
            - ubuntu-toolchain-r-test
            - george-edison55-precise-backports # cmake 3.2.3
          packages:
            - cmake
            - cmake-data
            - g++-4.9

    # gcc 5.x, Debug & Release
    - env: CMAKE_CC="gcc-5" CMAKE_CXX="g++-5" BUILD_TYPE="Debug" COMPILER_FLAGS=""
      dist: trusty
      os: linux
      addons: &gcc5
        apt:
          update: true
          sources:
            - ubuntu-toolchain-r-test
            - george-edison55-precise-backports # cmake 3.2.3
          packages:
            - cmake
            - cmake-data
            - g++-5
            - doxygen
            - lcov

    - env: CMAKE_CC="gcc-5" CMAKE_CXX="g++-5" BUILD_TYPE="Release" COMPILER_FLAGS="" BUILD_DOXYGEN="1"
      os: linux
      addons: *gcc5

    - env: CMAKE_CC="gcc-5" CMAKE_CXX="g++-5" BUILD_TYPE="Release" COMPILER_FLAGS="" BUILD_COVERAGE="1"
      os: linux
      addons: *gcc5

    # 32-bit builds with gcc 5.x
    - env: CMAKE_CC="gcc-5" CMAKE_CXX="g++-5" BUILD_TYPE="Debug" COMPILER_FLAGS="-m32"
      os: linux
      addons: &gcc5_32
        apt:
          update: true
          sources:
            - ubuntu-toolchain-r-test
            - george-edison55-precise-backports # cmake 3.2.3
          packages:
            - g++-5-multilib
            - linux-libc-dev:i386
            - cmake
            - cmake-data

    - env: CMAKE_CC="gcc-5" CMAKE_CXX="g++-5" BUILD_TYPE="Release" COMPILER_FLAGS="-m32"
      os: linux
      addons: *gcc5_32

    # gcc 6.x, Debug & Release, Debug with UndefinedBehaviorSanitizer
    - env: CMAKE_CC="gcc-6" CMAKE_CXX="g++-6" BUILD_TYPE="Debug" COMPILER_FLAGS="-fopenmp"
      os: linux
      addons: &gcc6
        apt:
          update: true
          sources:
            - ubuntu-toolchain-r-test
            - george-edison55-precise-backports # cmake 3.2.3
          packages:
            - cmake
            - cmake-data
            - g++-6
            - doxygen

    - env: CMAKE_CC="gcc-6" CMAKE_CXX="g++-6" BUILD_TYPE="Release" COMPILER_FLAGS="-fopenmp"
      os: linux
      addons: *gcc6

    # gcc 7.x, Debug & Release, Debug with UndefinedBehaviorSanitizer
    - env: CMAKE_CC="gcc-7" CMAKE_CXX="g++-7" BUILD_TYPE="Debug" COMPILER_FLAGS=""
      os: linux
      addons: &gcc7
        apt:
          update: true
          sources:
            - ubuntu-toolchain-r-test
            - george-edison55-precise-backports # cmake 3.2.3
          packages:
            - cmake
            - cmake-data
            - g++-7
            - doxygen

    - env: CMAKE_CC="gcc-7" CMAKE_CXX="g++-7" BUILD_TYPE="Release" COMPILER_FLAGS=""
      os: linux
      addons: *gcc7

    # gcc 8.x, Debug & Release, Release with STL bounds checking
    - env: CMAKE_CC="gcc-8" CMAKE_CXX="g++-8" BUILD_TYPE="Debug" COMPILER_FLAGS=""
      os: linux
      addons: &gcc8
        apt:
          update: true
          sources:
            - ubuntu-toolchain-r-test
            - george-edison55-precise-backports # cmake 3.2.3
          packages:
            - cmake
            - cmake-data
            - g++-8
            - doxygen

    - env: CMAKE_CC="gcc-8" CMAKE_CXX="g++-8" BUILD_TYPE="Release" COMPILER_FLAGS="-D_GLIBCXX_DEBUG"
      os: linux
      addons: *gcc8

    # clang 3.7 without AddressSanitizer, Debug & Release
    - env: CMAKE_CC="clang-3.7" CMAKE_CXX="clang++-3.7" BUILD_TYPE="Debug" COMPILER_FLAGS=""
      os: linux
      addons: &clang37
        apt:
          update: true
          sources:
            - ubuntu-toolchain-r-test
            - llvm-toolchain-precise-3.7
            - george-edison55-precise-backports # cmake 3.2.3
          packages:
            - cmake
            - cmake-data
            - clang-3.7

    # clang 3.7 without AddressSanitizer (there are some system-dependent LeakSanitizer errors)
    - env: CMAKE_CC="clang-3.7" CMAKE_CXX="clang++-3.7" BUILD_TYPE="Release" COMPILER_FLAGS=""
      os: linux
      addons: *clang37

    # clang 4.0 without AddressSanitizer, Debug & Release
    - env: CMAKE_CC="clang-4.0" CMAKE_CXX="clang++-4.0" BUILD_TYPE="Debug" COMPILER_FLAGS=""
      os: linux
      dist: trusty
      addons: &clang40
        apt:
          update: true
          sources:
            - ubuntu-toolchain-r-test
            - llvm-toolchain-trusty-4.0
          packages:
            - cmake
            - cmake-data
            - clang-4.0

    # clang 4.0 without AddressSanitizer (there are some system-dependent LeakSanitizer errors)
    - env: CMAKE_CC="clang-4.0" CMAKE_CXX="clang++-4.0" BUILD_TYPE="Release" COMPILER_FLAGS=""
      os: linux
      dist: trusty
      addons: *clang40

    # clang 3.7 on MacOSX without AddressSanitizer, Debug & Release, not FULL_BUILD
    - env: CMAKE_CC="clang" CMAKE_CXX="clang++" BUILD_TYPE="Debug" COMPILER_FLAGS=""
      os: osx

    - env: CMAKE_CC="clang" CMAKE_CXX="clang++" BUILD_TYPE="Release" COMPILER_FLAGS=""
      os: osx

env:
  global:
    # LeakSanitizer suppressions
    - LSAN_OPTIONS="suppressions=$PWD/misc/leak_sanitizer.supp"
    # die on ThreadSanitizer errors
    - TSAN_OPTIONS="halt_on_error=1"

before_script:

  # print out some version numbers
  - $CMAKE_CXX --version
  - cmake --version

  # enable -Werror on all ci builds
  - COMPILER_FLAGS="$COMPILER_FLAGS -Werror"

  # gcov coverage
  - if [ -n "$BUILD_COVERAGE" -a -n "$COVERALLS_REPO_TOKEN" ]; then
      pip install --user cpp-coveralls;
      CMAKE_ARGS="$CMAKE_ARGS -DTLX_USE_GCOV=ON";
    fi

  # configure
  - mkdir build
  - cd build
  - cmake
      -DCMAKE_BUILD_TYPE="$BUILD_TYPE"
      -DCMAKE_C_COMPILER="$CMAKE_CC" -DCMAKE_CXX_COMPILER="$CMAKE_CXX"
      -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS"
      -DTLX_BUILD_TESTS=ON -DTLX_TRY_COMPILE_HEADERS=ON
      -DTLX_MORE_TESTS=ON
      $CMAKE_ARGS ..

script:
  - make -j2 && ctest -V

# Generate and deploy documentation
after_success:
  - cd $TRAVIS_BUILD_DIR
  - if [ -n "$BUILD_DOXYGEN" -a "$TRAVIS_REPO_SLUG" == "tlx/tlx" -a "$TRAVIS_BRANCH" == "master" ]; then
      ./misc/mk-doxygen-travis.sh;
    fi
  - if [ -n "$BUILD_COVERAGE" -a -n "$COVERALLS_REPO_TOKEN" ]; then
      coveralls --exclude tests --gcov-options '\-lp';
    fi
