-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·164 lines (140 loc) · 4.27 KB
/
build.sh
File metadata and controls
executable file
·164 lines (140 loc) · 4.27 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env bash
BUILD_DIR="build"
META_DIR="meta"
METAGEN="${META_DIR}/build/metagen"
clean_partial() {
if [ ! -d "${BUILD_DIR}" ]; then
echo "==> Build directory '${BUILD_DIR}' not present. Nothing to clean."
return 0
fi
echo "==> Cleaning host/module build artifacts..."
rm -rf \
"${BUILD_DIR}/CMakeFiles/utilities_host.dir" \
"${BUILD_DIR}/CMakeFiles/utilities_app.dir" \
"${BUILD_DIR}/hot"
rm -f \
"${BUILD_DIR}/utilities_host" \
"${BUILD_DIR}/utilities_host.pdb"
rm -rf "${BUILD_DIR}/utilities_host.dSYM"
echo "==> Host/module artifacts cleaned. Dear ImGui cache preserved."
}
clean_hard() {
echo "==> Performing hard clean..."
rm -rf "${BUILD_DIR}"
echo "==> Build directory cleaned."
}
case "${1}" in
clean)
clean_partial
exit 0
;;
hard-clean)
clean_hard
exit 0
;;
esac
FLAVOR=${1:-release}
REQUESTED_TARGET=${2:-all}
CLEAN_BUILD=${3:-false}
CMAKE_ARGS=()
COMMON_WARN_FLAGS="-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wshadow -Wformat=2 -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-gnu-anonymous-struct -Wno-nested-anon-types -Wno-gnu-zero-variadic-macro-arguments -Wno-initializer-overrides"
C_FLAGS="${COMMON_WARN_FLAGS}"
CXX_FLAGS="${COMMON_WARN_FLAGS}"
LD_FLAGS=""
echo "==> Selected build flavor: ${FLAVOR}"
case "${FLAVOR}" in
release)
CMAKE_ARGS+=("-DCMAKE_BUILD_TYPE=Release")
CMAKE_ARGS+=("-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON")
;;
debug)
CMAKE_ARGS+=("-DCMAKE_BUILD_TYPE=Debug")
CMAKE_ARGS+=("-DADDRESS_SANITIZER=1")
C_FLAGS+=" -fsanitize=address -fno-omit-frame-pointer -DDEBUG=1"
CXX_FLAGS+=" -fsanitize=address -fno-omit-frame-pointer -DDEBUG=1"
LD_FLAGS="-fsanitize=address"
;;
*)
echo "Error: Unknown build flavor '${FLAVOR}'" >&2
echo "Available flavors: release, debug, asan" >&2
exit 1
;;
esac
CMAKE_ARGS+=("-DCMAKE_C_FLAGS=${C_FLAGS}")
CMAKE_ARGS+=("-DCMAKE_CXX_FLAGS=${CXX_FLAGS}")
CMAKE_ARGS+=("-DCMAKE_OBJCXX_FLAGS=${CXX_FLAGS}")
if [[ -n "${LD_FLAGS}" ]]; then
CMAKE_ARGS+=("-DCMAKE_EXE_LINKER_FLAGS=${LD_FLAGS}")
fi
case "${CLEAN_BUILD}" in
clean)
clean_partial
;;
hard-clean)
clean_hard
;;
true)
clean_hard
;;
esac
echo "==> Ensuring build directory exists..."
mkdir -p "${BUILD_DIR}"
run_metagen() {
(cd "${META_DIR}" && bash build_meta.sh)
if [ $? -ne 0 ]; then
echo "Error: Failed to build metagen" >&2
exit 1
fi
NEEDS_REGEN=0
for metadef in $(find . -name "*.metadef" -type f 2>/dev/null); do
generated="${metadef%.metadef}.generated.hpp"
if [ ! -f "$generated" ] || [ "$metadef" -nt "$generated" ]; then
NEEDS_REGEN=1
break
fi
done
if [ ${NEEDS_REGEN} -eq 1 ]; then
echo "==> Running metagen..."
"${METAGEN}" -v .
if [ $? -ne 0 ]; then
echo "Error: metagen failed" >&2
exit 1
fi
fi
}
if find . -name "*.metadef" -type f 2>/dev/null | grep -q .; then
run_metagen
fi
echo "==> Configuring CMake..."
cmake -S . -B "${BUILD_DIR}" "${CMAKE_ARGS[@]}"
if [ ! -d "${BUILD_DIR}" ]; then
echo "Error: expected build directory '${BUILD_DIR}' to exist after configure." >&2
exit 2
fi
case "${REQUESTED_TARGET}" in
all)
BUILD_CMD=(cmake --build "${BUILD_DIR}" -- -j$(sysctl -n hw.ncpu 2>/dev/null || echo 4))
;;
host)
BUILD_CMD=(cmake --build "${BUILD_DIR}" --target utilities_host -- -j$(sysctl -n hw.ncpu 2>/dev/null || echo 4))
;;
module)
BUILD_CMD=(cmake --build "${BUILD_DIR}" --target utilities_app -- -j$(sysctl -n hw.ncpu 2>/dev/null || echo 4))
;;
*)
echo "Error: Unknown build target '${REQUESTED_TARGET}'" >&2
echo "Available targets: all, host, module" >&2
exit 3
;;
esac
echo "==> Building (${REQUESTED_TARGET})..."
BUILD_START=$(date +%s.%N)
"${BUILD_CMD[@]}"
BUILD_STATUS=$?
if [ ${BUILD_STATUS} -ne 0 ]; then
exit ${BUILD_STATUS}
fi
BUILD_END=$(date +%s.%N)
BUILD_TIME=$(awk "BEGIN {printf \"%.2f\", $BUILD_END - $BUILD_START}")
echo "==> Compilation time: ${BUILD_TIME}s"
echo "==> Done. Artifacts in '${BUILD_DIR}/'"