language: cpp
dist: trusty
sudo: false

addons:
  apt:
    packages:
    - cmake
    - bison
    - flex
    - swig
    - libmuparser-dev
    - liblapack-dev
    - libxml2-dev
    - libboost-math-dev
    - libtbb-dev
    - r-base-core
    - python-dev
    - python-scipy
    - python-matplotlib

matrix:
  include:
    - os: linux
      compiler: clang
      env: BUILD_PYTHON=ON
    - os: linux
      compiler: clang
      env: BUILD_PYTHON=OFF
    - os: osx
      compiler: clang

before_install:
  - if test "$TRAVIS_OS_NAME" = "osx"; then
        brew update &&
        brew tap homebrew/science &&
        brew install swig muparser R openblas bison flex &&
        export HOMEBREW_PREFIX=`brew --prefix`;
    fi

install:
# use system python
  - export PATH=/usr/bin:$PATH
# use latest hmat-oss
  - git clone https://github.com/jeromerobert/hmat-oss.git
  - pushd hmat-oss
  - if test "$TRAVIS_OS_NAME" = "linux"; then
       cmake -DCMAKE_INSTALL_PREFIX=~/.local
             -DHMAT_DISABLE_OPENMP=OFF . ;
    fi
  - if test "$TRAVIS_OS_NAME" = "osx"; then
        cmake -DCMAKE_INSTALL_PREFIX=~/.local
              -DCMAKE_MACOSX_RPATH=ON
              -DCBLAS_LIBRARIES=$HOMEBREW_PREFIX/opt/openblas/lib/libopenblas.dylib
              -DBLAS_LIBRARIES=$HOMEBREW_PREFIX/opt/openblas/lib/libopenblas.dylib
              -DLAPACK_LIBRARIES=$HOMEBREW_PREFIX/opt/openblas/lib/libopenblas.dylib
              -DCBLAS_INCLUDE_DIRS=$HOMEBREW_PREFIX/opt/openblas/include . ;
    fi
  - make install -j4
  - popd
# use latest nlopt
  - git clone https://github.com/stevengj/nlopt.git
  - pushd nlopt
  - cmake -DCMAKE_INSTALL_PREFIX=$HOME/.local -DBUILD_SHARED_LIBS:BOOL=ON -DBUILD_PYTHON=OFF -DBUILD_OCTAVE=OFF -DBUILD_GUILE=OFF -DCMAKE_MACOSX_RPATH=ON .
  - make install -j4
  - popd

# use tbb from sources for osx (not brew)
  - if test "$TRAVIS_OS_NAME" = "osx"; then
       git clone https://github.com/01org/tbb.git &&
       pushd tbb &&
       git checkout 2017_U5 &&
       make -j4 cfg=release stdlib=libc++ &&
       install -d $HOME/.local/lib &&
       install -d $HOME/.local/include &&
       cp `find . -name "*lib*" | grep tbb | grep release` $HOME/.local/lib &&
       cp -r ./include/tbb $HOME/.local/include &&
       popd;
   fi

before_script:
  - R CMD INSTALL --library=$PWD utils/rot_1.4.6.tar.gz
  - export R_LIBS=$PWD

script:
  - if test "$TRAVIS_OS_NAME" = "linux"; then
        cmake -DCMAKE_INSTALL_PREFIX=~/.local
              -DUSE_SPHINX=OFF
              -DHMAT_DIR=~/.local/lib/cmake/hmat
              -DNLOPT_LIBRARY=~/.local/lib/libnlopt.so
              -DNLOPT_INCLUDE_DIR=~/.local/include
              -DUSE_COTIRE=ON
              -DCOTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES="-j2"
              -DBUILD_PYTHON=${BUILD_PYTHON}
              . &&
        make install -j2;
    fi
  - if test "$TRAVIS_OS_NAME" = "osx"; then
        cmake -DCMAKE_INSTALL_PREFIX=~/.local
              -DCMAKE_MACOSX_RPATH=ON
              -DHMAT_DIR=~/.local/lib/cmake/hmat
              -DLAPACK_LIBRARIES="-framework Accelerate"
              -DNLOPT_LIBRARY=~/.local/lib/libnlopt.dylib
              -DNLOPT_INCLUDE_DIR=~/.local/include
              -DUSE_SPHINX=OFF
              -DBISON_EXECUTABLE=/usr/local/opt/bison/bin/bison
              -DFLEX_EXECUTABLE=/usr/local/opt/flex/bin/flex
              -DFLEX_INCLUDE_DIR=/usr/local/opt/flex/include
              -DPYTHON_EXECUTABLE=/usr/bin/python
              -DPYTHON_INCLUDE_DIR=/usr/include/python2.7
              -DPYTHON_LIBRARY=/usr/lib/libpython2.7.dylib
              -DUSE_COTIRE=ON
              -DCOTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES="-j4"
              . &&
        make install -j4;
    fi
  - if test "${BUILD_PYTHON}" = "OFF"; then
        make tests -j2 && ctest -R cppcheck -j2 --output-on-failure --timeout 100;
    else
        ctest -R pyinstallcheck -j4 --output-on-failure --timeout 100;
    fi

after_success:
  - exit 0
  - test "$TRAVIS_PULL_REQUEST" = "false" -a "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_OS_NAME" = "linux" || exit 0
  - git clone https://${GH_TOKEN}@github.com/openturns/openturns.github.io.git
  - cp -r ~/.local/share/openturns/doc/html/* openturns.github.io
  - cd openturns.github.io
  - touch .nojekyll
  - git config user.email "support@travis-ci.com"
  - git config user.name "Travis CI"
  - git add -A .
  - git commit -a -m "Travis build $TRAVIS_BUILD_NUMBER"
  - git push --quiet origin master > /dev/null 2>&1

env:
  global:
    secure: azF2AfkEALFgd16Xh0XcAglAtExD5BhsMSPOcHFUftgDGrlsgsjD4p505UxrAOYYX5Exchne5D9pSV8gFlxKl5OIoVkJhSkvLRKANJKzdM95TnUqeJy6zplcEOvDPKdww37mKzJy/a9MduOqORqMeVErvpiEpYwrdiH1GUBHrvAp4NUSPhR5Ea/6d3TdOmaF1j0N8Bb66ZHn9SGThLM0ZEHk9iXHB5E9U0Y8dq7eDifD20hWGfIRiIksyWRyP+a/8WAnqf0mYPPkP1qEssexCHlF3tB2ZVyXBF84/laujOasWu1uApjjEhJADE6E3Rnv7BYMB6pvmiVMF/CZ07rflqgI5MjnYplg8ZShS//UuYUlGi7NwKztMob/5GUjp6PHYBbc0t1sjgqzxJhuN80Km51M7n4zvjQs7EyHeu61BxWQe0NwpKN17OavUucYL6yN9R3L/JLEg9EJnKFNo+CXnzMH28luCn1SgfNU9iuk3B4Lwa4IY6bm0lAHm/WvHIOfQFNuqzH/1QtY9dM0iLCl8IcvO7buYkmEip9i+XdSn7HURAjmUsStonwGBDSONQgiuSOJE8GUaPCOpr5+tDrTa/TxWr3y1xMv1uORcWMp4ulm7XGrjSxDsfCRhPx56AjWA9uf+xbnnYApHlyoYGETEsff3RbH91FBriuHAZVH5Dw=
