language: cpp
matrix:
  include:
    - compiler: clang
      os: linux
      env: SWIGLANG=
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG= GCC=4.4
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG= GCC=4.6
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG= GCC=4.7
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG= GCC=4.8
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG= GCC=4.9
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG= GCC=6
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG= GCC=7
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG= GCC=8
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG= GCC=9
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=csharp
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=d VER=2.066.0
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=d VER=2.086.1
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=go VER=1.3
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=go VER=1.8
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=go VER=1.12
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=guile
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=java
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=javascript ENGINE=node VER=0.10
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=javascript ENGINE=node VER=4 CPP11=1
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=javascript ENGINE=node VER=6 CPP11=1
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=javascript ENGINE=node VER=8 CPP11=1
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=javascript ENGINE=node VER=10 CPP11=1
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=javascript ENGINE=jsc
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=javascript ENGINE=v8
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=lua
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=lua VER=5.3
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=mzscheme
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=ocaml
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=octave SWIGJOBS=-j2
      sudo: required
      dist: xenial   # Octave v4.0.0
    - compiler: gcc
      os: linux
      env: SWIGLANG=octave SWIGJOBS=-j2 CPP11=1
      sudo: required
      dist: bionic   # Octave v4.2.2
    - compiler: gcc
      os: linux
      env: SWIGLANG=perl5
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=php VER=7.0
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=php VER=7.1
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=php VER=7.2
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=php VER=7.3
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python # 2.7
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python PY3=3 VER=3.2
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python PY3=3 VER=3.3
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python PY3=3 VER=3.4
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python PY3=3 VER=3.5
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python PY3=3 VER=3.6
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python PY3=3 VER=3.7
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python PY3=3 VER=3.8
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python SWIG_FEATURES=-builtin
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python SWIG_FEATURES="-builtin -O"
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=python SWIG_FEATURES=-builtin GCC=6 CPP11=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=python SWIG_FEATURES=-builtin GCC=6 CPP11=1 PY3=3 VER=3.8
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.4
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.5
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.7
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.8
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python SWIG_FEATURES="-builtin -O" PY3=3 VER=3.8
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.8 SWIGOPTPY3=
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python SWIG_FEATURES=-O
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=python SWIG_FEATURES=-O PY3=3 VER=3.8
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=r
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=ruby VER=1.9
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=ruby VER=2.0
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=ruby VER=2.1
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=ruby VER=2.2
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=ruby VER=2.3
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=ruby VER=2.4
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=ruby VER=2.5
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=ruby VER=2.6
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=ruby VER=2.7
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=scilab
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=tcl
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=csharp CPP11=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=go VER=1.6 CPP11=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=java CPP11=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=python CPP11=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=r CPP11=1 # Note: making 'R CMD SHLIB' use a different compiler is non-trivial
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=ruby CPP11=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=tcl CPP11=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=csharp GCC=6 CPP14=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=go VER=1.6 GCC=6 CPP14=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=java GCC=6 CPP14=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=python GCC=6 CPP14=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=ruby GCC=6 CPP14=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=tcl GCC=6 CPP14=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=java GCC=7 CPP14=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=python GCC=7 CPP14=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=csharp GCC=8 CPP17=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=java GCC=8 CPP17=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=python GCC=8 CPP17=1 PY3=3 VER=3.8
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=csharp GCC=9 CPP17=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=java GCC=9 CPP17=1
      sudo: required
      dist: xenial
    - os: linux
      env: SWIGLANG=python GCC=9 CPP17=1 PY3=3 VER=3.8
      sudo: required
      dist: xenial
    - os: linux
      arch: s390x
      env: SWIGLANG=ruby CPP11=1
      sudo: required
      dist: xenial
    - compiler: gcc
      os: osx
      env: SWIGLANG=
    - compiler: clang
      os: osx
      env: SWIGLANG=
    - compiler: clang
      os: osx
      env: SWIGLANG=csharp
    - compiler: clang
      os: osx
      env: SWIGLANG=go
    - compiler: clang
      os: osx
      env: SWIGLANG=guile CSTD=c11
    - compiler: clang
      os: osx
      env: SWIGLANG=java
    - compiler: clang
      os: osx
      env: SWIGLANG=lua
    - compiler: clang
      os: osx
      env: SWIGLANG=octave SWIGJOBS=-j2 CPP11=1
    - compiler: clang
      os: osx
      env: SWIGLANG=perl5
    - compiler: clang
      os: osx
      env: SWIGLANG=python
    - compiler: clang
      os: osx
      env: SWIGLANG=python PY3=3
    - compiler: clang
      os: osx
      env: SWIGLANG=ruby
    - compiler: clang
      os: osx
      env: SWIGLANG=tcl
    - compiler: clang
      os: osx
      env: SWIGLANG=java CPP17=1
      osx_image: xcode10.2
    - compiler: clang
      os: osx
      env: SWIGLANG=python PY3=3 CPP17=1
      osx_image: xcode10.2

  allow_failures:
    # Newer version of D not yet working/supported
    - compiler: gcc
      os: linux
      env: SWIGLANG=d VER=2.086.1
      sudo: required
      dist: xenial
    # seg fault in director_basic testcase
    - compiler: gcc
      os: linux
      env: SWIGLANG=php VER=7.2
      sudo: required
      dist: xenial
    # Experimental languages
    - compiler: gcc
      os: linux
      env: SWIGLANG=mzscheme
      sudo: required
      dist: xenial
    - compiler: gcc
      os: linux
      env: SWIGLANG=ocaml
      sudo: required
      dist: xenial

before_install:
  - date -u
  - uname -a
  - if test "$TRAVIS_OS_NAME" = "linux"; then lscpu; grep "model name" /proc/cpuinfo || echo 'Unknown CPU model'; grep "MemTotal" /proc/meminfo || echo 'Unknown system memory amount'; fi
  - if test "$TRAVIS_OS_NAME" = "osx"; then sysctl -a | grep brand_string; fi
  # Travis overrides CC environment with compiler predefined values
  - if test -n "$GCC"; then export CC="gcc-$GCC" && export CXX="g++-$GCC"; fi
install:
  - if test "$TRAVIS_OS_NAME" = "linux"; then source Tools/travis-linux-install.sh; fi
  - if test "$TRAVIS_OS_NAME" = "osx"; then source Tools/travis-osx-install.sh; fi
  - ls -la $(which $CC) $(which $CXX) && $CC --version && $CXX --version
script:
  - echo 'Configuring...' && echo -en 'travis_fold:start:script.1\\r'
  - if test -n "$CPP11"; then CONFIGOPTS+=(--enable-cpp11-testing --without-maximum-compile-warnings "CXXFLAGS=-std=c++11 -Wall -Wextra" "CFLAGS=-std=c11 -Wall -Wextra") && export CSTD=c11 && export CPPSTD=c++11; fi
  - if test -n "$CPP14"; then CONFIGOPTS+=(--enable-cpp11-testing --without-maximum-compile-warnings "CXXFLAGS=-std=c++14 -Wall -Wextra" "CFLAGS=-std=c11 -Wall -Wextra") && export CSTD=c11 && export CPPSTD=c++14; fi
  - if test -n "$CPP17"; then CONFIGOPTS+=(--enable-cpp11-testing --without-maximum-compile-warnings "CXXFLAGS=-std=c++17 -Wall -Wextra" "CFLAGS=-std=c17 -Wall -Wextra") && export CSTD=c17 && export CPPSTD=c++17; fi
  - if test -n "$SWIGLANG"; then CONFIGOPTS+=(--without-alllang --with-$WITHLANG); fi
  - echo "${CONFIGOPTS[@]}"
  - ./autogen.sh && mkdir -p build/build && cd build/build && ../../configure "${CONFIGOPTS[@]}"
  - echo -en 'travis_fold:end:script.1\\r'
  - make -s $SWIGJOBS
  - ./swig -version && ./swig -pcreversion
  - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-ccache; fi
  - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-errors-test-suite; fi
  - echo 'Installing...' && echo -en 'travis_fold:start:script.2\\r'
  - if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi
  - echo -en 'travis_fold:end:script.2\\r'
  # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic.
  - if test -n "$SWIGLANG"; then cflags=$($TRAVIS_BUILD_DIR/Tools/testflags.py --language $SWIGLANG --cflags --std=$CSTD --compiler=$CC) && echo $cflags; fi
  - if test -n "$SWIGLANG"; then cxxflags=$($TRAVIS_BUILD_DIR/Tools/testflags.py --language $SWIGLANG --cxxflags --std=$CPPSTD --compiler=$CC) && echo $cxxflags; fi
  - if test -n "$SWIGLANG"; then make -s check-$SWIGLANG-version; fi
  - if test -n "$SWIGLANG"; then make check-$SWIGLANG-enabled; fi
  - if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-examples CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi
  - if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-test-suite CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi
  - echo 'Cleaning...' && echo -en 'travis_fold:start:script.3\\r'
  - make check-maintainer-clean && ../../configure $CONFIGOPTS
  - echo -en 'travis_fold:end:script.3\\r'
