#!/bin/sh

ADD_DEFINITION() {
    KEY=$1
    VALUE=$(eval "echo \${${KEY}}")
    if [ -n "${VALUE}" ]
    then
	DEFINITIONS="${DEFINITIONS} -D${KEY}=${VALUE}"
    fi
}

USE() {
    KEY=$1
    VALUE=$(eval "echo \${${KEY}}")
    [ "${VALUE}" = "true" ]
}

LOCATION=$(dirname $0)

if [ -f /etc/debian_version ]
then
  NEEDED_PACKAGES="g++ libqt4-dev libsqlite3-dev libboost-filesystem-dev libboost-test-dev"
  dpkg -s ${NEEDED_PACKAGES} ||
  sudo apt-get install ${NEEDED_PACKAGES}
fi

if [ -f ~/.auto_cmake ]
then
  . ~/.auto_cmake
fi

DEFINITIONS=""

ADD_DEFINITION BOOST_ROOT
ADD_DEFINITION QT_QMAKE_EXECUTABLE
if USE CCACHE
then
	DEFINITIONS="${DEFINITIONS} -DCMAKE_CXX_COMPILER=/usr/lib/ccache/g++  -DCMAKE_C_COMPILER=/usr/lib/ccache/gcc"
fi

eval "cmake -DCMAKE_CXX_COMPILER=/usr/lib/ccache/g++ ${DEFINITIONS} ${LOCATION}"
