#########################
# project configuration #
#########################

# C++ project
language: cpp

dist: trusty
sudo: required
group: edge


################
# build matrix #
################

matrix:
  include:

  # Coverity (only for branch coverity_scan)

  - os: linux
    compiler: clang
    before_install: echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt
    addons:
      apt:
        sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
        packages: ['g++-6', 'clang-3.6', 'ninja-build']
      coverity_scan:
        project:
          name: "nlohmann/json"
          description: "Build submitted via Travis CI"
        notification_email: niels.lohmann@gmail.com
        build_command_prepend: "mkdir coverity_build ; cd coverity_build ; cmake .. ; cd .."
        build_command: "make -C coverity_build"
        branch_pattern: coverity_scan
    env:
      - SPECIAL=coverity
      - COMPILER=clang++-3.6
        # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
        #   via the "travis encrypt" command using the project repo's public key
      - secure: "m89SSgE+ASLO38rSKx7MTXK3n5NkP9bIx95jwY71YEiuFzib30PDJ/DifKnXxBjvy/AkCGztErQRk/8ZCvq+4HXozU2knEGnL/RUitvlwbhzfh2D4lmS3BvWBGS3N3NewoPBrRmdcvnT0xjOGXxtZaJ3P74TkB9GBnlz/HmKORA="

  # OSX / Clang

  - os: osx
    osx_image: xcode10.2

  # Linux / GCC

  - os: linux
    compiler: gcc
    env: COMPILER=g++-6
    addons:
      apt:
        sources: ['ubuntu-toolchain-r-test']
        packages: ['g++-6', 'ninja-build']

################
# build script #
################

script:
  # get CMake and Ninja (only for systems with brew - macOS)
  - |
     if [[ (-x $(which brew)) ]]; then
       brew update
       brew install cmake ninja
       brew upgrade cmake
       cmake --version
     fi

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

  # append CXX_STANDARD to CMAKE_OPTIONS if required
  - CMAKE_OPTIONS+=${CXX_STANDARD:+ -DCMAKE_CXX_STANDARD=$CXX_STANDARD -DCMAKE_CXX_STANDARD_REQUIRED=ON}

  # build configuration
  - CMAKE_OPTIONS+=" -DCMAKE_BUILD_TYPE=Release"

  # compile and execute unit tests
  - mkdir -p build && cd build
  - cmake .. ${CMAKE_OPTIONS} -DJSON_BuildTests=On -GNinja && cmake --build .
  - ctest --timeout 2700 -V -j
  - cd ..

  # check if homebrew works (only checks develop branch)   
  - if [ `which brew` ]; then   
    brew update ;   
    brew tap nlohmann/json ;    
    brew install nlohmann_json --HEAD ;    
    brew test nlohmann_json ;    
    fi
