language: cpp
dist: xenial

# see https://github.com/nlohmann/json/blob/develop/.travis.yml
matrix:
  include:

  - os: osx
    osx_image: xcode11.4
    compiler: clang
    env:
    - COMPILER=clang++
    - CMAKE_OPTIONS="-DNB_cxx_standard=17"

  # compile on ARM
  - os: linux
    arch: arm64
    compiler: gcc
    env:
    - COMPILER=g++-8
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=11"
    addons:
      apt:
        sources: ['ubuntu-toolchain-r-test']
        packages: ['g++-8']


  # compile on S390x
  - os: linux
    arch: s390x
    compiler: gcc
    env:
    - COMPILER=g++
    - CMAKE_OPTIONS="-DNB_sanitizer=OFF -DNB_cxx_standard=11"

  # g++-8
  - os: linux
    compiler: gcc
    env:
    - COMPILER=g++-8
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=11"
    addons:
      apt:
        sources: ['ubuntu-toolchain-r-test']
        packages: ['g++-8']

  # clang++-10
  - os: linux
    compiler: clang
    env:
    - COMPILER=clang++-10
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=11"
    addons:
      apt:
        sources:
        - ubuntu-toolchain-r-test
        - sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-10 main'
          key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
        packages:
        - clang-10

  - os: linux
    compiler: clang
    env:
    - COMPILER=clang++-10
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=14"
    addons:
      apt:
        sources:
        - ubuntu-toolchain-r-test
        - sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-10 main'
          key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
        packages:
        - clang-10

  - os: linux
    compiler: clang
    env:
    - COMPILER=clang++-10
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=17"
    addons:
      apt:
        sources:
        - ubuntu-toolchain-r-test
        - sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-10 main'
          key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
        packages:
        - clang-10

  # gcc 8
  - os: linux
    compiler: gcc
    env:
    - COMPILER=g++-8
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=14"
    addons:
      apt:
        sources: ['ubuntu-toolchain-r-test']
        packages: ['g++-8']

  - os: linux
    compiler: gcc
    env:
    - COMPILER=g++-8
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=17"
    addons:
      apt:
        sources: ['ubuntu-toolchain-r-test']
        packages: ['g++-8']

  # g++-8 32bit
  - os: linux
    compiler: gcc
    env:
    - COMPILER=g++-8
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=11"
    - CXXFLAGS="-m32"
    - LDFLAGS="-m32"
    addons:
      apt:
        sources: ['ubuntu-toolchain-r-test']
        packages: ['g++-8-multilib', 'linux-libc-dev:i386']

  - os: linux
    compiler: gcc
    env:
    - COMPILER=g++-8
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=14"
    - CXXFLAGS="-m32"
    - LDFLAGS="-m32"
    addons:
      apt:
        sources: ['ubuntu-toolchain-r-test']
        packages: ['g++-8-multilib', 'linux-libc-dev:i386']

  - os: linux
    compiler: gcc
    env:
    - COMPILER=g++-8
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=17"
    - CXXFLAGS="-m32"
    - LDFLAGS="-m32"
    addons:
      apt:
        sources: ['ubuntu-toolchain-r-test']
        packages: ['g++-8-multilib', 'linux-libc-dev:i386']

  # clang++-6.0
  - os: linux
    compiler: clang
    env:
    - COMPILER=clang++-6.0
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=11"
    addons:
      apt:
        sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-xenial-6.0']
        packages: ['g++-6', 'clang-6.0',]

  - os: linux
    compiler: clang
    env:
    - COMPILER=clang++-6.0
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=14"
    addons:
      apt:
        sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-xenial-6.0']
        packages: ['g++-6', 'clang-6.0',]

  - os: linux
    compiler: clang
    env:
    - COMPILER=clang++-6.0
    - CMAKE_OPTIONS="-DNB_sanitizer=ON -DNB_cxx_standard=17"
    addons:
      apt:
        sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-xenial-6.0']
        packages: ['g++-6', 'clang-6.0',]

install:
  - if [[ "${CODE_COVERAGE}" == "true" ]]; then gem install coveralls-lcov ; fi

script:
  # make sure CXX is correctly set
  - if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi

  # show OS/compiler version
  - uname -a
  - $CXX --version

  # build
  - cd build
  - cmake .. -DCMAKE_BUILD_TYPE=Release ${CMAKE_OPTIONS} && cmake --build . -- -j2

  # check file
  - file ./nb

  # run test
  - ./nb
  
  # coverage
  - |
    if [[ "${CODE_COVERAGE}" = "true" ]]; then
      cmake --build . --target lcov
    fi
