| 1 |
#!/bin/bash |
| 2 |
# Test that abPOA can be used via add_subdirectory() without polluting |
| 3 |
# the parent project's compile flags or install rules. |
| 4 |
set -e |
| 5 |
|
| 6 |
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 7 |
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 8 |
cd "$PROJECT_DIR" |
| 9 |
|
| 10 |
BUILD_DIR="/tmp/abpoa_subdir_build_$$" |
| 11 |
trap "rm -rf $BUILD_DIR" EXIT |
| 12 |
|
| 13 |
ERRORS=0 |
| 14 |
|
| 15 |
# Configure the parent project that add_subdirectory()'s abPOA |
| 16 |
if ! cmake -B "$BUILD_DIR" -S tests/test_cmake_subdir \ |
| 17 |
-DABPOA_SOURCE_DIR="$PROJECT_DIR" \ |
| 18 |
-DCMAKE_BUILD_TYPE=Release 2>/tmp/cmake_subdir_cfg.log; then |
| 19 |
echo "FAIL: cmake configure failed for add_subdirectory test" |
| 20 |
cat /tmp/cmake_subdir_cfg.log |
| 21 |
ERRORS=$((ERRORS + 1)) |
| 22 |
fi |
| 23 |
|
| 24 |
# Build |
| 25 |
if [ $ERRORS -eq 0 ]; then |
| 26 |
if ! cmake --build "$BUILD_DIR" -j$(nproc) 2>/tmp/cmake_subdir_build.log; then |
| 27 |
echo "FAIL: cmake build failed for add_subdirectory test" |
| 28 |
cat /tmp/cmake_subdir_build.log |
| 29 |
ERRORS=$((ERRORS + 1)) |
| 30 |
fi |
| 31 |
fi |
| 32 |
|
| 33 |
# Run the consumer binary |
| 34 |
if [ $ERRORS -eq 0 ]; then |
| 35 |
if ! "$BUILD_DIR/test_parent" >/dev/null 2>&1; then |
| 36 |
echo "FAIL: test_parent binary failed" |
| 37 |
ERRORS=$((ERRORS + 1)) |
| 38 |
fi |
| 39 |
fi |
| 40 |
|
| 41 |
rm -f /tmp/cmake_subdir_cfg.log /tmp/cmake_subdir_build.log |
| 42 |
|
| 43 |
if [ $ERRORS -gt 0 ]; then |
| 44 |
echo "$ERRORS add_subdirectory errors" |
| 45 |
exit 1 |
| 46 |
fi |
| 47 |
|
| 48 |
echo "add_subdirectory integration works correctly" |
| 49 |
exit 0 |