language: generic

notifications:
    email: false
os:
  - linux

sudo: true #for beineri qt561
dist: trusty

before_install:
  - sudo add-apt-repository --yes ppa:beineri/opt-qt562-trusty
  - sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
  - sudo apt-get -qq update
  - sudo apt-get -qq install ${AF} qt56base qt56tools qt56svg  # qttools5-dev
  - sudo apt-get -qq install ${AF} cmake libhidapi-dev ${COMP}
  - sudo apt-get -qq remove gcc-4.8 g++-4.8 --purge

#cache:
#  - apt

before_cache:
  - brew cleanup

cache:
  directories:
    # https://stackoverflow.com/questions/39930171/cache-brew-builds-with-travis-ci
    - $HOME/Library/Caches/Homebrew
    - /usr/local/Homebrew/


script: |
    echo "${TRAVIS_OS_NAME}"
    if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
      source /opt/qt56/bin/qt56-env.sh ;
      export QMAKE=/opt/qt56/bin/qmake;
    fi
    if [ "$builder" == "qmake" ]; then 
      ${QMAKE} 
      if [ "${TRAVIS_OS_NAME}" == "osx" ]; then make || exit 1; fi
      if [ "${TRAVIS_OS_NAME}" == "linux" ]; then make CXX=${CXX} CC=${CC} LINK=${CXX} || exit 1 ; fi
    elif [ "$builder" == "cmake" ]; then 
      cmake -DERROR_ON_WARNING=ON . && make VERBOSE=1 || exit 1;
    fi

env:
  matrix:
    - builder=cmake CXX=clang++-3.8 CC=clang-3.8 COMP="clang-3.8 g++-5"
    - builder=qmake CXX=clang++-3.8 CC=clang-3.8 COMP="clang-3.8 g++-5"
    - builder=cmake CXX=g++-5 CC=gcc-5 COMP=g++-5
    - builder=qmake CXX=g++-5 CC=gcc-5 COMP=g++-5
    - builder=qmake CXX=g++-6 CC=gcc-6 COMP=g++-6
  global:
    - AF="-yq --no-install-suggests --no-install-recommends --force-yes" QMAKE=qmake


matrix:
  include:
    - os: osx
      osx_image: xcode8.3 #default
      before_install: &before
        - brew update
        - brew install qt5
        - brew unlink cmake
        - brew install cmake
        - export
      env: builder=cmake PATH="/usr/local/opt/qt5/bin:$PATH" CMAKE_PREFIX_PATH=/usr/local/lib/cmake MACOS_DEPLOYMENT_TARGET=10.9
    - os: osx
      osx_image: xcode8.3 #default
      before_install: *before
      env: builder=qmake PATH="/usr/local/opt/qt5/bin:$PATH" CMAKE_PREFIX_PATH=/usr/local/lib/cmake MACOS_DEPLOYMENT_TARGET=10.9
    - os: osx
      osx_image: xcode9.1
      before_install: *before
      env: builder=qmake PATH="/usr/local/opt/qt5/bin:$PATH" CMAKE_PREFIX_PATH=/usr/local/lib/cmake MACOS_DEPLOYMENT_TARGET=10.9
