-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·84 lines (69 loc) · 1.65 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·84 lines (69 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Default build directory
BUILD_DIR="build"
# Function to print usage
print_usage() {
echo "Usage: $0 [command]"
echo ""
echo "Commands:"
echo " debug Build the project in Debug mode (default)"
echo " release Build the project in Release mode"
echo " test Run the test suite (builds in Debug mode first)"
echo " clean Remove the build directory"
echo " help Show this help message"
}
# Function to build the project
build_project() {
local build_type=$1
echo "Building in $build_type mode..."
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
# Configure with CMake
cmake -DCMAKE_BUILD_TYPE="$build_type" ..
# Build with all available cores
make -j"$(nproc)"
cd ..
echo "Build completed successfully."
}
# Function to run tests
run_tests() {
echo "Running tests..."
# Ensure we have a debug build before testing
build_project "Debug"
cd "$BUILD_DIR"
ctest --output-on-failure
cd ..
echo "All tests passed."
}
# Function to clean the build directory
clean_project() {
echo "Cleaning build directory..."
rm -rf "$BUILD_DIR"
echo "Clean completed."
}
# Main logic
COMMAND=${1:-debug}
case "$COMMAND" in
debug)
build_project "Debug"
;;
release)
build_project "Release"
;;
test)
run_tests
;;
clean)
clean_project
;;
help|--help|-h)
print_usage
;;
*)
echo "Error: Unknown command '$COMMAND'"
print_usage
exit 1
;;
esac