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

set -e

# Copy the upstream CMake lists and testsuite.
cp -a ./data/ ./test/* $AUTOPKGTEST_TMP
cd $AUTOPKGTEST_TMP

# Create a standalone project.
rm CMakeLists.txt
cat << EOF > CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(glm-tests)

enable_testing()

add_definitions(-DSOURCE_DIR="\${CMAKE_CURRENT_SOURCE_DIR}")

find_package(gli REQUIRED)
include_directories(SYSTEM \${gli_INCLUDE_DIRS})

find_package(glm REQUIRED)
include_directories(SYSTEM \${glm_INCLUDE_DIRS})

function(glmCreateTestGTC NAME)
  set(SAMPLE_NAME test-\${NAME})
  add_executable(\${SAMPLE_NAME} \${NAME}.cpp)
  add_test(NAME \${SAMPLE_NAME}
           COMMAND \$<TARGET_FILE:\${SAMPLE_NAME}>)
endfunction()

add_subdirectory(bug)
add_subdirectory(core)

EOF

# Configure, build and run.
mkdir build && cd build
cmake .. && make && make test
