Debian Codegraph @

tests/test_cmake_lib_only.sh

raw
1 #!/bin/bash
2 # Test that CMake can build only the library (no CLI executable)
3 # when ABPOA_BUILD_EXE=OFF.
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_build_libonly_$$"
11 trap "rm -rf $BUILD_DIR" EXIT
12
13 ERRORS=0
14
15 # Test 1: Build with ABPOA_BUILD_EXE=OFF
16 if ! cmake -B "$BUILD_DIR" -S . -DABPOA_BUILD_EXE=OFF \
17 -DCMAKE_BUILD_TYPE=Release >/dev/null 2>&1; then
18 echo "FAIL: cmake configure failed (ABPOA_BUILD_EXE=OFF)"
19 exit 1
20 fi
21 if ! cmake --build "$BUILD_DIR" -j$(sysctl -n hw.logicalcpu 2>/dev/null || nproc 2>/dev/null || echo 4) >/dev/null 2>&1; then
22 echo "FAIL: cmake build failed (ABPOA_BUILD_EXE=OFF)"
23 exit 1
24 fi
25
26 # Library must exist
27 if find "$BUILD_DIR" -name 'libabpoa.a' | grep -q .; then
28 : # ok
29 else
30 echo "FAIL: libabpoa.a not found in lib-only build"
31 ERRORS=$((ERRORS + 1))
32 fi
33
34 # Binary must NOT exist
35 if find "$BUILD_DIR" -name 'abpoa' -type f -exec test -x {} \; -print | grep -q .; then
36 echo "FAIL: abpoa binary found in lib-only build (should be disabled)"
37 ERRORS=$((ERRORS + 1))
38 fi
39
40 # Test 2: Default top-level build should still produce the binary
41 BUILD_DIR2="/tmp/abpoa_build_default_$$"
42 trap "rm -rf $BUILD_DIR $BUILD_DIR2" EXIT
43
44 if ! cmake -B "$BUILD_DIR2" -S . -DCMAKE_BUILD_TYPE=Release >/dev/null 2>&1; then
45 echo "FAIL: cmake configure failed (default build)"
46 exit 1
47 fi
48 if ! cmake --build "$BUILD_DIR2" -j$(sysctl -n hw.logicalcpu 2>/dev/null || nproc 2>/dev/null || echo 4) >/dev/null 2>&1; then
49 echo "FAIL: cmake build failed (default build)"
50 exit 1
51 fi
52
53 if ! find "$BUILD_DIR2" -name 'abpoa' -type f -exec test -x {} \; -print | grep -q .; then
54 echo "FAIL: abpoa binary not found in default build (should be built)"
55 ERRORS=$((ERRORS + 1))
56 fi
57
58 if [ $ERRORS -gt 0 ]; then
59 echo "$ERRORS cmake lib-only errors"
60 exit 1
61 fi
62
63 echo "CMake library-only build works correctly"
64 exit 0