#!/bin/sh
set -e

cp -r test "$AUTOPKGTEST_TMP"

cd "$AUTOPKGTEST_TMP"
sed -i -e '1 s/^cmake_minimum/#&/' -e '/target_link/ s/\${PROJECT_NAME}/MANIF::manif/' test/CMakeLists.txt
cat > CMakeLists.txt << EOF
cmake_minimum_required(VERSION 3.14)
project(manif-autopkgtest)
find_package(manif REQUIRED)

enable_testing()
add_subdirectory(test)
EOF

echo ""
echo "---------------- Testing C++ implementation ----------------"

mkdir _build
cd _build

cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
cmake --build . --verbose -j`nproc || echo 1`
ctest --output-on-failure

