language: cpp

install:
    - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq; fi
    - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install valgrind; fi

matrix:

  # ----- Linux / GCC -----
  include:
    - os: linux
      name: "Linux / GCC (Debug)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-8
      env:
        - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Debug" DOUBLE_PRECISION="False"

    - os: linux
      name: "Linux / GCC (Release)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-8
      env:
        - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Release" DOUBLE_PRECISION="False"

    - os: linux
      name: "Linux / GCC (Debug, Double Precision)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-8
      env:
        - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Debug" DOUBLE_PRECISION="True"

    - os: linux
      name: "Linux / GCC (Release, Double Precision)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-8
      env:
        - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Release" DOUBLE_PRECISION="True"
    - os: linux
      name: "Linux / GCC (Debug, Profiler)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-8
      env:
        - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Debug" DOUBLE_PRECISION="False" Profiler="True"
    - os: linux
      name: "Linux / GCC (Release, Profiler)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-8
      env:
        - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Release" DOUBLE_PRECISION="False" Profiler="True"
    - os: linux
      name: "Linux / GCC (Debug, Code Coverage)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-8
            - lcov
      env:
        - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Debug" DOUBLE_PRECISION="False" CODE_COVERAGE="True"
    - os: linux
      name: "Linux / GCC (Debug, Valgrind)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-8
            - valgrind
      env:
        - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Debug" DOUBLE_PRECISION="False" VALGRIND="True"

    # ----- OS X / GCC -----
    - os: osx
      name: "OS X / GCC (Debug)"
      osx_image: xcode11
      env:
       - MATRIX_EVAL="brew install gcc@8 && CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Debug" DOUBLE_PRECISION="False"
    - os: osx
      name: "OS X / GCC (Release)"
      osx_image: xcode11
      env:
       - MATRIX_EVAL="brew install gcc@8 && CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Release" DOUBLE_PRECISION="False"
    - os: osx
      name: "OS X / GCC (Debug, Double Precision)"
      osx_image: xcode11
      env:
       - MATRIX_EVAL="brew install gcc@8 && CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Debug" DOUBLE_PRECISION="True"
    - os: osx
      name: "OS X / GCC (Release, Double Precision)"
      osx_image: xcode11
      env:
       - MATRIX_EVAL="brew install gcc@8 && CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Release" DOUBLE_PRECISION="True"
    - os: osx
      name: "OS X / GCC (Debug, Profiler)"
      osx_image: xcode11
      env:
       - MATRIX_EVAL="brew install gcc@8 && CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Debug" DOUBLE_PRECISION="False" PROFILER="True"
    - os: osx
      name: "OS X / GCC (Release, Profiler)"
      osx_image: xcode11
      env:
       - MATRIX_EVAL="brew install gcc@8 && CC=gcc-8 && CXX=g++-8" BUILD_TYPE="Release" DOUBLE_PRECISION="False" PROFILER="True"

    # ----- Linux / Clang -----
    - os: linux
      name: "Linux / Clang (Debug)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
            - llvm-toolchain-precise-3.8
          packages:
            - clang-3.8
            - g++-7
      env:
        - MATRIX_EVAL="CC=clang-3.8 && CXX=clang++-3.8" BUILD_TYPE="Debug" DOUBLE_PRECISION="False"

    - os: linux
      name: "Linux / Clang (Release)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
            - llvm-toolchain-precise-3.8
          packages:
            - clang-3.8
            - g++-7
      env:
        - MATRIX_EVAL="CC=clang-3.8 && CXX=clang++-3.8" BUILD_TYPE="Release" DOUBLE_PRECISION="False"

    - os: linux
      name: "Linux / Clang (Debug, Double Precision)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
            - llvm-toolchain-precise-3.8
          packages:
            - clang-3.8
            - g++-7
      env:
        - MATRIX_EVAL="CC=clang-3.8 && CXX=clang++-3.8" BUILD_TYPE="Debug" DOUBLE_PRECISION="True"

    - os: linux
      name: "Linux / Clang (Release, Double Precision)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
            - llvm-toolchain-precise-3.8
          packages:
            - clang-3.8
            - g++-7
      env:
        - MATRIX_EVAL="CC=clang-3.8 && CXX=clang++-3.8" BUILD_TYPE="Release" DOUBLE_PRECISION="True"
    - os: linux
      name: "Linux / Clang (Debug, Double Precision, Profiler)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
            - llvm-toolchain-precise-3.8
          packages:
            - clang-3.8
            - g++-7
      env:
        - MATRIX_EVAL="CC=clang-3.8 && CXX=clang++-3.8" BUILD_TYPE="Debug" DOUBLE_PRECISION="True" PROFILER="True"
    - os: linux
      name: "Linux / Clang (Release, Double Precision, Profiler)"
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
            - llvm-toolchain-precise-3.8
          packages:
            - clang-3.8
            - g++-7
      env:
        - MATRIX_EVAL="CC=clang-3.8 && CXX=clang++-3.8" BUILD_TYPE="Release" DOUBLE_PRECISION="True" PROFILER="True"

    # ----- OS X / Clang -----
    - os: osx
      name: "OS X / Clang (Debug)"
      osx_image: xcode11
      env:
        - BUILD_TYPE="Debug" DOUBLE_PRECISION="False"

    - os: osx
      name: "OS X / Clang (Release)"
      osx_image: xcode11
      env:
        - BUILD_TYPE="Release" DOUBLE_PRECISION="False"

    - os: osx
      name: "OS X / Clang (Debug, Double Precision)"
      osx_image: xcode11
      env:
        - BUILD_TYPE="Debug" DOUBLE_PRECISION="True"

    - os: osx
      name: "OS X / Clang (Release, Double Precision)"
      osx_image: xcode11
      env:
        - BUILD_TYPE="Release" DOUBLE_PRECISION="True"

    - os: osx
      name: "OS X / Clang (Debug, Profiler)"
      osx_image: xcode11
      env:
        - BUILD_TYPE="Debug" DOUBLE_PRECISION="False" PROFILER="True"

    - os: osx
      name: "OS X / Clang (Release, Profiler)"
      osx_image: xcode11
      env:
        - BUILD_TYPE="Release" DOUBLE_PRECISION="False" PROFILER="True"

before_install:
  - eval "${MATRIX_EVAL}"

branches:
  only:
    - master
    - develop

script:
    - mkdir build_rp3d
    - cd build_rp3d
    - cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} —DRP3D_DOUBLE_PRECISION_ENABLED=${DOUBLE_PRECISION} -DRP3D_COMPILE_TESTS=True -DRP3D_PROFILING_ENABLED=${PROFILER} -DRP3D_CODE_COVERAGE_ENABLED=${CODE_COVERAGE} ../
    - make -j2 && make test ARGS="-V"
    - if [ "${VALGRIND}" == "True" ]; then
        valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --error-exitcode=1 test/tests;
      fi
    - if [ "${CODE_COVERAGE}" == "False" ]; then
        sudo make install;
        cd ../;
        mkdir build_helloworld;
        cd build_helloworld;
        cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ../helloworld/;
        make -j2;
      fi


after_success:
 
 # Generate code coverage report
 - if [ "${CODE_COVERAGE}" == "True" ]; then
     bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports";
   fi
