#!/bin/sh
set -e

CMAKE_ARGS="-DBUILD_TESTS:BOOL=True"

case "$CONFIG" in
full*)
    CMAKE_ARGS="-DBUILD_DOCUMENTATION:BOOL=True -DBUILD_EXAMPLES:BOOL=True -DWITH_OPUS:BOOL=True -DWITH_SPEEX:BOOL=True -DWITH_THEORA:BOOL=True -DWITH_VPX:BOOL=True"
    ;;
esac

case "$CONFIG" in
*debug*)
    CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE:STRING=Debug"
    ;;
esac

if [ "$(uname -s)" = "Darwin" ]; then
    # pick up cmake files from homebrew
    CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_PREFIX_PATH=/usr/local/opt/qt5"
else
    # This hides all the paths that contain custom travis binaries like the
    # updated version of cmake.
    export PATH=/usr/sbin:/usr/bin:/sbin:/bin
fi

# build with code coverage
if [ "$CONFIG" = "full-debug" ]; then
    export CXXFLAGS="-fprofile-arcs -ftest-coverage"
fi

# compile
mkdir build
cd build
cmake .. $CMAKE_ARGS
make

# run tests
make test
