#!/bin/bash
set -e
if [ -z "$OMNI_HOME" ]; then
echo "OMNI_HOME is empty"
OMNI_HOME=/opt
fi
export OMNI_INCLUDE_PATH=$OMNI_HOME/lib/include
export OMNI_INCLUDE_PATH=$OMNI_INCLUDE_PATH:$OMNI_HOME/lib
export CPLUS_INCLUDE_PATH=$OMNI_INCLUDE_PATH:$CPLUS_INCLUDE_PATH
echo "OMNI_INCLUDE_PATH=$OMNI_INCLUDE_PATH"
CURRENT_DIR=$(cd "$(dirname "$BASH_SOURCE")"; pwd)
echo $CURRENT_DIR
cd ${CURRENT_DIR}
if [ -d build ]; then
rm -r build
fi
mkdir build
cd build
if [ $# != 0 ] ; then
options=""
if [ $1 = 'debug' ]; then
echo "-- Enable Debug"
options="$options -DCMAKE_BUILD_TYPE=Debug -DDEBUG_RUNTIME=ON"
elif [ $1 = 'trace' ]; then
echo "-- Enable Trace"
options="$options -DCMAKE_BUILD_TYPE=Debug -DTRACE_RUNTIME=ON"
elif [ $1 = 'release' ];then
echo "-- Enable Release"
options="$options -DCMAKE_BUILD_TYPE=Release"
elif [ $1 = 'test' ];then
echo "-- Enable Test"
options="$options -DCMAKE_BUILD_TYPE=Test"
elif [ $1 = 'coverage' ]; then
echo "-- Enable Coverage"
options="$options -DCMAKE_BUILD_TYPE=Debug -DDEBUG_RUNTIME=ON -DCOVERAGE=ON"
else
echo "-- Enable Release"
options="$options -DCMAKE_BUILD_TYPE=Release"
fi
cmake .. $options -DBUILD_CPP_TESTS=ON
else
echo "-- Enable Release"
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_CPP_TESTS=OFF
fi
make -j5
if [ $# != 0 ] ; then
if [ $1 = 'coverage' ]; then
./test/tptest --gtest_output=xml:test_detail.xml
lcov --d ../ --c --output-file test.info --rc lcov_branch_coverage=1
lcov --remove test.info '*/opt/lib/include/*' '*test/*' '*build/src/*' '*/usr/include/*' '*/usr/lib/*' '*/usr/lib64/*' '*/usr/local/include/*' '*/usr/local/lib/*' '*/usr/local/lib64/*' -o final.info --rc lcov_branch_coverage=1
genhtml final.info -o test_coverage --branch-coverage --rc lcov_branch_coverage=1
fi
fi
set +eu