language: cpp
dist: trusty
sudo: required
group: edge

git:
  submodules: false

matrix:
  include:
    # - os: linux
    #   compiler: gcc
    #   env:
    #     - COMPILER=g++-4.9
    #   addons:
    #     apt:
    #       sources:
    #         - sourceline: 'ppa:mhier/libboost-latest'
    #         - ubuntu-toolchain-r-test
    #       packages:
    #         - g++-4.9 boost1.74 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libavahi-client-dev avahi-daemon expat

    - os: linux
      compiler: gcc
      env:
        - COMPILER=g++-5
      addons:
        apt:
          sources:
            - sourceline: 'ppa:mhier/libboost-latest'
            - ubuntu-toolchain-r-test
          packages:
            - g++-5 boost1.74 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libpulse-dev libavahi-client-dev avahi-daemon expat

    - os: linux
      compiler: gcc
      env:
        - COMPILER=g++-6
      addons:
        apt:
          sources:
            - sourceline: 'ppa:mhier/libboost-latest'
            - ubuntu-toolchain-r-test
          packages:
            - g++-6 boost1.74 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libpulse-dev libavahi-client-dev avahi-daemon expat

    - os: linux
      compiler: gcc
      env:
        - COMPILER=g++-7
      addons:
        apt:
          sources:
            - sourceline: 'ppa:mhier/libboost-latest'
            - ubuntu-toolchain-r-test
          packages:
            - g++-7 boost1.74 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libpulse-dev libavahi-client-dev avahi-daemon expat

    - os: linux
      compiler: gcc
      env:
        - COMPILER=g++-8
      addons:
        apt:
          sources:
            - sourceline: 'ppa:mhier/libboost-latest'
            - ubuntu-toolchain-r-test
          packages:
            - g++-8 boost1.74 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libpulse-dev libavahi-client-dev avahi-daemon expat

    - os: linux
      compiler: gcc
      env:
        - COMPILER=g++-9
      addons:
        apt:
          sources:
            - sourceline: 'ppa:mhier/libboost-latest'
            - ubuntu-toolchain-r-test
          packages:
            - g++-9 boost1.74 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libpulse-dev libavahi-client-dev avahi-daemon expat


    - os: linux
      compiler: clang
      env:
        - COMPILER=clang++-3.9
        - CXXFLAGS=-stdlib=libc++
        - CC=clang-3.9
      addons:
        apt:
          sources:
            - sourceline: 'ppa:mhier/libboost-latest'
            - llvm-toolchain-trusty-3.9
          packages:
            - clang-3.9 boost1.74 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libpulse-dev libavahi-client-dev avahi-daemon expat

    - os: linux
      compiler: clang
      env:
        - COMPILER=clang++-4.0
        - CXXFLAGS=-stdlib=libc++
        - CC=clang-4.0
      addons:
        apt:
          sources:
            - sourceline: 'ppa:mhier/libboost-latest'
            - llvm-toolchain-trusty-4.0
          packages:
            - clang-4.0 boost1.74 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libpulse-dev libavahi-client-dev avahi-daemon expat

    - os: linux
      compiler: clang
      env:
        - COMPILER=clang++-5.0
        - CXXFLAGS=-stdlib=libc++
        - CC=clang-5.0
      addons:
        apt:
          sources:
            - sourceline: 'ppa:mhier/libboost-latest'
            - llvm-toolchain-trusty-5.0
          packages:
            - clang-5.0 boost1.74 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libpulse-dev libavahi-client-dev avahi-daemon expat

    - os: linux
      compiler: clang
      env:
        - COMPILER=clang++-6.0
        - CXXFLAGS=-stdlib=libc++
      addons:
        apt:
          sources:
            - sourceline: 'ppa:mhier/libboost-latest'
            - llvm-toolchain-trusty-6.0
            - ubuntu-toolchain-r-test
          packages:
            - clang-6.0 boost1.74 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libpulse-dev libavahi-client-dev avahi-daemon expat

    - os: linux
      compiler: clang
      env:
        - COMPILER=clang++-7
        - CXXFLAGS=-stdlib=libc++
      addons:
        apt:
          sources:
            - sourceline: 'ppa:mhier/libboost-latest'
            - llvm-toolchain-trusty-7
            - ubuntu-toolchain-r-test
          packages:
            - clang-7 boost1.74 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libpulse-dev libavahi-client-dev avahi-daemon expat

    # build on osx
    
    # xcode 9 is running into a timeout
    # - os: osx
    #  osx_image: xcode9.4
    #  env:
    #    - MATRIX_EVAL="brew update && brew unlink python@2 && brew upgrade boost && brew install flac opus libvorbis libsoxr expat"

    - os: osx
      osx_image: xcode10.3
      env:
        - MATRIX_EVAL="brew update && brew install flac opus libvorbis libsoxr expat"

    - os: osx
      osx_image: xcode11
      env:
        - MATRIX_EVAL="brew update && brew install flac opus libvorbis libsoxr expat"

    # build on windows
    - os: windows

before_install:
    - eval "${MATRIX_EVAL}"
    - |
      (
        if [ "$TRAVIS_OS_NAME" = 'windows' ]; then
          curl -LfsS -o /tmp/travis-wait-enhanced.zip "https://github.com/crazy-max/travis-wait-enhanced/releases/download/v1.1.0/travis-wait-enhanced_1.1.0_windows_x86_64.zip"
          7z x /tmp/travis-wait-enhanced.zip -y -o/usr/bin/ travis-wait-enhanced.exe -r
          travis-wait-enhanced --version # we use this tool so travis doesn't timeout when there's no output for > 10 minutes (vcpkg has no verbose option). travis_wait also fixes this issue, but it swallows the output
          if [ ! -f "vcpkg/vcpkg.exe" ]; then # if not in cache from a previous run
            git clone https://github.com/Microsoft/vcpkg.git
            ./vcpkg/bootstrap-vcpkg.bat
            travis-wait-enhanced --interval=1m --timeout=30m -- ./vcpkg/vcpkg.exe install libflac libvorbis soxr opus boost-asio --triplet x64-windows
          else
            ./vcpkg/vcpkg.exe update # make sure dependencies are up to date
          fi          
        fi
      )

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

  - mkdir build
  - cd build
  - |
    (
      if [ "$TRAVIS_OS_NAME" != 'windows' ]; then
        cmake -DCMAKE_BUILD_TYPE=Release -DWERROR=ON .. && make && sudo make install
      else
        cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows -DCMAKE_BUILD_TYPE=Release -DWERROR=ON ..
        cmake --build . --config Release
      fi
     )
cache:
  directories:
  - vcpkg