cache:
  # This persistent cache is used to cache the building of
  # docker base images.
  directories:
    - $DOCKER_TRAVIS_CI_CACHE_DIR
sudo: required
language: cpp
services:
  - docker
env:
  global:
    # This environment variable tells the `travis_ci_linux_entry_point.sh`
    # script to look for a cached Docker image.
    - DOCKER_TRAVIS_CI_CACHE_DIR=$HOME/.cache/docker
  # Configurations
  matrix:
###############################################################################
# Ubuntu 16.04 LTS
###############################################################################
    # 64-bit UBSan Debug build
    - LINUX_BASE=ubuntu_16.04 C_COMPILER=/usr/bin/clang-3.9 CXX_COMPILER=/usr/bin/clang++-3.9 TARGET_ARCH=x86_64 Z3_BUILD_TYPE=Debug UBSAN_BUILD=1 RUN_UNIT_TESTS=SKIP
    # 64-bit ASan Debug build
    - LINUX_BASE=ubuntu_16.04 C_COMPILER=/usr/bin/clang-3.9 CXX_COMPILER=/usr/bin/clang++-3.9 TARGET_ARCH=x86_64 Z3_BUILD_TYPE=Debug ASAN_BUILD=1 RUN_UNIT_TESTS=SKIP ASAN_DSO=/usr/lib/clang/3.9/lib/linux/libclang_rt.asan-x86_64.so
    # Build for running unit tests under ASan/UBSan
    # FIXME: We should really be doing a debug build but the unit tests run too
    # slowly when we do that.
    - LINUX_BASE=ubuntu_16.04 C_COMPILER=/usr/bin/clang-3.9 CXX_COMPILER=/usr/bin/clang++-3.9 TARGET_ARCH=x86_64 Z3_BUILD_TYPE=RelWithDebInfo ASAN_BUILD=1 RUN_UNIT_TESTS=BUILD_AND_RUN ASAN_DSO=/usr/lib/clang/3.9/lib/linux/libclang_rt.asan-x86_64.so UBSAN_BUILD=1 RUN_API_EXAMPLES=0 RUN_SYSTEM_TESTS=0 DOTNET_BINDINGS=0 JAVA_BINDINGS=0 PYTHON_BINDINGS=0

    # 64-bit GCC 5.4 RelWithDebInfo
    - LINUX_BASE=ubuntu_16.04 C_COMPILER=/usr/bin/gcc-5 CXX_COMPILER=/usr/bin/g++-5 TARGET_ARCH=x86_64 Z3_BUILD_TYPE=RelWithDebInfo
    # 64-bit Clang 3.9 RelWithDebInfo
    - LINUX_BASE=ubuntu_16.04 C_COMPILER=/usr/bin/clang-3.9 CXX_COMPILER=/usr/bin/clang++-3.9 TARGET_ARCH=x86_64 Z3_BUILD_TYPE=RelWithDebInfo

    # Debug builds
    #
    # Note the unit tests for the debug builds are compiled but **not**
    # executed. This is because the debug build of unit tests takes a large
    # amount of time to execute compared to the optimized builds. The hope is
    # that just running the optimized unit tests is sufficient.
    #
    # 64-bit GCC 5.4 Debug
    - LINUX_BASE=ubuntu_16.04 C_COMPILER=/usr/bin/gcc-5 CXX_COMPILER=/usr/bin/g++-5 TARGET_ARCH=x86_64 Z3_BUILD_TYPE=Debug RUN_UNIT_TESTS=BUILD_ONLY
    # 64-bit Clang Debug
    - LINUX_BASE=ubuntu_16.04 C_COMPILER=/usr/bin/clang-3.9 CXX_COMPILER=/usr/bin/clang++-3.9 TARGET_ARCH=x86_64 Z3_BUILD_TYPE=Debug RUN_UNIT_TESTS=BUILD_ONLY

    # 32-bit GCC 5.4 RelWithDebInfo
    - LINUX_BASE=ubuntu32_16.04 C_COMPILER=/usr/bin/gcc-5 CXX_COMPILER=/usr/bin/g++-5 TARGET_ARCH=i686 Z3_BUILD_TYPE=RelWithDebInfo

    # Both of the two configurations below build the docs because the current
    # implementation uses python as part of the building process.
    # TODO: Teach one of the configurations to upload built docs somewhere.
    # Test with Python 3 and API docs
    - LINUX_BASE=ubuntu_16.04 PYTHON_EXECUTABLE=/usr/bin/python3 BUILD_DOCS=1
    # Test with LibGMP and API docs
    - LINUX_BASE=ubuntu_16.04 TARGET_ARCH=x86_64 USE_LIBGMP=1 BUILD_DOCS=1 PYTHON_EXECUTABLE=/usr/bin/python2.7

    # Unix Makefile generator build
    - LINUX_BASE=ubuntu_16.04 C_COMPILER=/usr/bin/gcc-5 CXX_COMPILER=/usr/bin/g++-5 TARGET_ARCH=x86_64 Z3_CMAKE_GENERATOR="Unix Makefiles"

    # LTO build
    - LINUX_BASE=ubuntu_16.04 C_COMPILER=/usr/bin/gcc-5 CXX_COMPILER=/usr/bin/g++-5 TARGET_ARCH=x86_64 USE_LTO=1

    # Static build. Note we have disable building the bindings because they won't work with a static libz3
    - LINUX_BASE=ubuntu_16.04 C_COMPILER=/usr/bin/gcc-5 CXX_COMPILER=/usr/bin/g++-5 TARGET_ARCH=x86_64 Z3_STATIC_BUILD=1 DOTNET_BINDINGS=0 JAVA_BINDINGS=0 PYTHON_BINDINGS=0

# macOS (a.k.a OSX) support
matrix:
  include:
    # For now just test a single configuration. macOS builds on TravisCI are
    # very slow so we should keep the number of configurations we test on this
    # OS to a minimum.
    - os: osx
      osx_image: xcode8.3
      env: Z3_BUILD_TYPE=RelWithDebInfo DOTNET_BINDINGS=0
script:
  # Use `travis_wait` when doing LTO builds because this configuration will
  # have long link times during which it will not show any output which
  # TravisCI might kill due to perceived inactivity.
  - if [ "X${USE_LTO}" = "X1" ]; then
      travis_wait 55 contrib/ci/scripts/travis_ci_entry_point.sh || exit 1;
    else
      contrib/ci/scripts/travis_ci_entry_point.sh || exit 1;
    fi