-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·101 lines (86 loc) · 2.01 KB
/
build.sh
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
set -euo pipefail
OUT_DIR="build"
# Usage function prints help message
usage() {
echo "Usage: $0 [debug|release|profile|asm|all]"
exit 1
}
# Run Doxygen and log output; exit if it fails.
build_doxygen() {
local out_dir="$1"
echo "Running Doxygen..."
if ! doxygen Doxyfile &>"$out_dir/doxygen.log"; then
echo "Doxygen failed. Check $out_dir/doxygen.log for details."
exit 1
fi
}
# Configure and build with CMake and Ninja.
# Arguments: build directory, build type, compiler
build_with_cmake() {
local build_dir="$1"
local build_type="$2"
local compiler="$3"
echo "Configuring and building ${build_type} build in ${build_dir} using ${compiler}..."
mkdir -p "$build_dir"
if [ $build_type == "Release" ]; then
build_doxygen "$build_dir"
fi
if ! CXX="$compiler" cmake -G Ninja -S . -B "$build_dir" -DCMAKE_BUILD_TYPE="$build_type"; then
echo "CMake configuration failed for ${build_dir}."
exit 1
fi
# if ! bear -- ninja -C "$build_dir" &>"$build_dir/build.log"; then
if ! ninja -C "$build_dir" &>"$build_dir/build.log"; then
echo "Ninja build failed for ${build_dir}. See $build_dir/build.log for details."
exit 1
fi
compdb -p build/ list >compile_commands.json
echo "${build_type} build completed successfully in ${build_dir}."
}
build_debug() {
build_with_cmake "$OUT_DIR" "Debug" "clang++"
}
build_release() {
local release_dir="${OUT_DIR}-release"
build_with_cmake "$release_dir" "Release" "g++"
}
build_profile() {
local profile_dir="${OUT_DIR}-profile"
build_with_cmake "$profile_dir" "Profile" "g++"
}
build_asm() {
local profile_dir="${OUT_DIR}-asm"
build_with_cmake "$profile_dir" "Asm" "g++"
}
# Determine build mode from first argument (default is debug)
if [ $# -eq 0 ]; then
MODE="debug"
else
MODE="$1"
fi
case "$MODE" in
debug)
build_debug
;;
release)
build_release
;;
profile)
build_profile
;;
asm)
build_asm
;;
all)
echo "Building all configurations concurrently..."
build_debug &
build_release &
build_profile &
build_asm &
wait
;;
*)
usage
;;
esac