#!/bin/sh
# Copyright 2015 Ghislain Antony Vaillant
#
# This file is part of the autopkgtest testsuite for Boost.Compute.

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 -a /usr/share/doc/libcompute-doc/examples/* "$ADTTMP"
cd "$ADTTMP"

# Create the CMake project.
cat <<EOF > CMakeLists.txt
# ---------------------------------------------------------------------------
#  Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
#
#  Distributed under the Boost Software License, Version 1.0
#  See accompanying file LICENSE_1_0.txt or copy at
#  http://www.boost.org/LICENSE_1_0.txt
#
# ---------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.6)
project(dummy)

find_package(BoostCompute REQUIRED)
include_directories(\${BoostCompute_INCLUDE_DIRS})

find_package(OpenCL REQUIRED)
include_directories(\${OpenCL_INCLUDE_DIRS})

set(EXAMPLES
  amd_cpp_kernel
  black_scholes
  copy_data
  fizz_buzz
  hello_world
  host_sort
  inline_ptx
  longest_vector
  list_devices
  mapped_view
  memory_limits
  monte_carlo
  point_centroid
  price_cross
  print_vector
  sort_vector
  simple_kernel
  time_copy
  transform_sqrt
  vector_addition
  simple_moving_average
  matrix_transpose
)

# boost library link dependencies
find_package(Boost 1.48 REQUIRED COMPONENTS program_options)
include_directories(SYSTEM \${Boost_INCLUDE_DIRS})

foreach(EXAMPLE \${EXAMPLES})
  add_executable(\${EXAMPLE} \${EXAMPLE}.cpp)
  target_link_libraries(\${EXAMPLE} \${OpenCL_LIBRARIES} \${Boost_LIBRARIES})
endforeach()

EOF

# Configure and build.
mkdir build && cd build
cmake ./..
echo "configure: OK"
make
echo "build: OK"
