language: cpp
sudo: true
cache: apt
dist: trusty
addons:
  apt:
    sources: &apt_sources
      - ubuntu-toolchain-r-test
      - sourceline: 'ppa:kalakris/cmake' # cmake 2.8 for precise
      - sourceline: 'ppa:adrozdoff/cmake' # cmake 3 for trusty
      - sourceline: 'ppa:h-rayflood/llvm'
    packages: &default_packages
      - cmake
      - libgmp-dev
      - libmpfr-dev
      - libgoogle-perftools-dev
      - g++-4.9
      - clang-3.4

matrix:
  include:
   - os: linux
     dist: precise
     env:
       CMAKE_CXX_COMPILER=g++-4.9
       CMAKE_BUILD_TYPE=Release
       TARGET=build/lean-@LEAN_VERSION_MAJOR@.@LEAN_VERSION_MINOR@.@LEAN_VERSION_PATCH@-linux.tar.gz
       UPLOAD=ON
       STATIC=ON

   - os: linux
     env:
       CMAKE_CXX_COMPILER=clang++-3.4
       CMAKE_BUILD_TYPE=Release
       TCMALLOC=ON

   - os: linux
     addons: &gcc6_addons
       apt:
         sources: *apt_sources
         packages:
           - *default_packages
           - g++-6
           - gcc-6
     env:
       CMAKE_CXX_COMPILER=g++-6
       CMAKE_BUILD_TYPE=Release
       TCMALLOC=ON

   - os: linux
     addons: *gcc6_addons
     env:
       CMAKE_CXX_COMPILER=g++-6
       CMAKE_BUILD_TYPE=Release
       TESTCOV=ON

   - os: linux
     addons: *gcc6_addons
     env:
       CMAKE_CXX_COMPILER=g++-6
       CMAKE_BUILD_TYPE=Release
       MULTI_THREAD=OFF

   - os: linux
     env:
       CMAKE_CXX_COMPILER=clang++-3.4
       CMAKE_BUILD_TYPE=Debug
       LEAN_EXTRA_MAKE_OPTS=-t0
       TCMALLOC=ON

   - os: linux
     dist: precise
     env:
       CMAKE_CXX_COMPILER=g++-4.9
       CMAKE_BUILD_TYPE=Debug

   - os: osx
     env:
       CMAKE_CXX_COMPILER=clang++
       CMAKE_BUILD_TYPE=Release
       TARGET=build/lean-@LEAN_VERSION_MAJOR@.@LEAN_VERSION_MINOR@.@LEAN_VERSION_PATCH@-darwin.zip
       UPLOAD=ON
       PACKAGE=TRUE

   - os: osx
     env:
       CMAKE_CXX_COMPILER=g++
       CMAKE_BUILD_TYPE=Debug

before_install:
  - if [[ $TRAVIS_OS_NAME == osx ]]; then
      brew update &&
      brew install gcc &&
      brew install gmp &&
      brew install mpfr;
    fi

script:
  - mkdir -p build
  - cd build
  - if [[ $TESTCOV != ON ]]; then TESTCOV=OFF; fi
  - if [[ $TCMALLOC != ON ]]; then TCMALLOC=OFF; fi
  - if [[ $STATIC != ON ]]; then STATIC=OFF; fi
  - if [[ $MULTI_THREAD != OFF ]]; then MULTI_THREAD=ON; fi
  - cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE
          -DCMAKE_CXX_COMPILER=$CMAKE_CXX_COMPILER
          -DTESTCOV=$TESTCOV
          -DTCMALLOC=$TCMALLOC
          -DMULTI_THREAD=$MULTI_THREAD
          -DSTATIC=$STATIC
          -DLEAN_EXTRA_MAKE_OPTS=$LEAN_EXTRA_MAKE_OPTS
          ../src || exit
  - make -j2 || exit
  - cpack
  # TODO(gabriel): add smaller test subset for debug and emscripten builds
  - if [[ $CMAKE_BUILD_TYPE == Release ]]; then
      yes "A" | ctest -j2;
    else
      yes "A" | ctest -j2 -I 100,600,10;
    fi
  - if [[ $PACKAGE == TRUE ]]; then make package; fi
  - cd ..

after_script:
  - if [[ $TESTCOV == ON ]]; then bash <(curl -s https://codecov.io/bash) -x gcov-6; fi

notifications:
  email:
    recipients:
     - lean-build@googlegroups.com
    on_success: change
    on_failure: always

deploy:
  provider: releases
  api_key:
    secure: NeTKs0tb0hM9yC1lJyc7Y8ev1rfEe9tpY8bS20hUivNKcX8S0HjJh/xtx/3LgrhcqVP0xKuDPE0YNQk3E9SO1ni2ESjIFIVXI/hpDLNjxjfaeW7rcpYcc7dy7ynEP23HnAOMr4PMHs0T/ATsJHKyDXTUi4yrQToBBTQUFvCKgo8=
  file: $TARGET
  skip_cleanup: true
  overwrite: true
  on:
    condition: $UPLOAD = ON
    repo: leanprover/lean
    tags: true
