#!/bin/sh
# Copyright 2016 Ghislain Antony Vaillant
#
# This file is part of the autopkgtest testsuite for Field3D.

set -e

# Presence of $ADTTMP implies that someone will handle cleanup for us, so we
# can avoid duplicating the effort (signal handling, etc.) here.
if [ -z "$ADTTMP" ]
then
	echo "Required envvar \"$ADTTMP\"is not set" >&2
	exit 1
fi

# Copy example source code.
cp test/unit_tests/UnitTest.cpp "$ADTTMP"
cd "$ADTTMP"

# Create the CMake project.
cat <<EOF > CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
project(dummy)

set(Boost_COMPONENTS system thread)
find_package(Boost COMPONENTS \${Boost_COMPONENTS} REQUIRED)
include_directories(\${Boost_INCLUDE_DIRS})
link_directories(\${Boost_LIBRARY_DIRS})

find_package(HDF5 REQUIRED)
include_directories(\${HDF5_INCLUDE_DIRS})
link_directories(\${HDF5_LIBRARY_DIRS})

find_package(PkgConfig)
pkg_check_modules(ILMBASE QUIET IlmBase)
include_directories(\${ILMBASE_INCLUDE_DIRS})

link_libraries(Field3D
               \${Boost_LIBRARIES}
               \${HDF5_LIBRARIES}
               \${ILMBASE_LIBRARIES})

add_executable(unitTest UnitTest.cpp)

EOF

# Configure and build.
mkdir build && cd build
cmake ./..
echo "configure: OK"
make
echo "build: OK"
[ -x unitTest ] && ./unitTest
echo "run: OK"
