-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·144 lines (132 loc) · 4.25 KB
/
build.sh
File metadata and controls
executable file
·144 lines (132 loc) · 4.25 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
#!/bin/bash
# --- Default values ---
OS="linux"
ARCH="x64"
BUILD_TYPE="debug"
CUSTOM_C_FLAGS=""
CUSTOM_CXX_FLAGS=""
REBUILD_CMAKE=false
REBUILD_APP=false
# --- Function to show usage ---
usage() {
echo "Usage: $0 [options...]"
echo "Options can be provided in any order:"
echo " linux|macos|windows Operating system target (default: linux)"
echo " x64|armv7|arm64 Architecture target (default: x64)"
echo " debug|release Build type (default: debug)"
echo " --cflags \"<flags>\" C compiler flags"
echo " --cxxflags \"<flags>\" C++ compiler flags"
echo " --rebuild-cmake Force clean and re-run CMake"
echo " --rebuild Force a clean build of the application"
echo " -h, --help Show this help message"
exit 1
}
# --- Process arguments ---
while (( "$#" )); do
case "$1" in
linux|macos|windows)
OS="$1"
shift
;;
x64|armv7|arm64)
ARCH="$1"
shift
;;
debug|release)
BUILD_TYPE="$1"
shift
;;
--cflags)
if [ -n "$2" ] && [[ "$2" != --* ]]; then
CUSTOM_C_FLAGS="$2"
shift 2
else
echo "Error: --cflags requires an argument." >&2
usage
fi
;;
--cxxflags)
if [ -n "$2" ] && [[ "$2" != --* ]]; then
CUSTOM_CXX_FLAGS="$2"
shift 2
else
echo "Error: --cxxflags requires an argument." >&2
usage
fi
;;
--rebuild-cmake)
REBUILD_CMAKE=true
shift
;;
--rebuild)
REBUILD_APP=true
shift
;;
-h|--help)
usage
;;
*)
echo "Error: Unknown option '$1'" >&2
usage
;;
esac
done
# --- Set up build directory and paths ---
BUILD_DIR="build/${OS}_${ARCH}_${BUILD_TYPE}"
# --- Handle CMake rebuild ---
if [ "$REBUILD_CMAKE" = true ]; then
echo "--- Rebuilding CMake configuration ---"
rm -rf "$BUILD_DIR"
fi
# --- Configure CMake if build directory doesn't exist ---
if [ ! -d "$BUILD_DIR" ] || [ ! -f "$BUILD_DIR/build.ninja" ]; then
echo "--- Build directory not ready for Ninja. Configuring CMake for $BUILD_TYPE, $OS on $ARCH... ---"
mkdir -p "$BUILD_DIR"
# --- Find vcpkg ---
if [ -n "$VCPKG_ROOT" ]; then
echo "Using VCPKG_ROOT from environment: $VCPKG_ROOT"
elif [ -d "../../external/vcpkg" ]; then
VCPKG_ROOT="$(readlink -f ../../external/vcpkg)"
echo "Found local vcpkg at: $VCPKG_ROOT"
elif [ -d "/opt/vcpkg" ]; then
VCPKG_ROOT="/opt/vcpkg"
echo "Found system vcpkg at: $VCPKG_ROOT"
else
echo "Error: Could not find vcpkg. Please install it in ../../external/vcpkg or set VCPKG_ROOT."
exit 1
fi
# --- Adjust toolchain and overlay paths ---
# Assuming script is run from project root, so CMAKE_CURRENT_SOURCE_DIR . is correct.
# We substitute /app with the current directory path.
PROJECT_ROOT=$(pwd)
# --- Check for Ninja ---
if command -v ninja &> /dev/null; then
GENERATOR="Ninja"
BUILD_CMD="ninja"
else
echo "Ninja not found. Falling back to Unix Makefiles."
GENERATOR="Unix Makefiles"
BUILD_CMD="make -j$(nproc)"
fi
CMAKE_ARGS=(
"-G" "$GENERATOR"
"-S" "."
"-B" "$BUILD_DIR"
"-DCMAKE_BUILD_TYPE=${BUILD_TYPE^}"
"-DCMAKE_C_FLAGS=${CUSTOM_C_FLAGS}"
"-DCMAKE_CXX_FLAGS=${CUSTOM_CXX_FLAGS}"
"-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
"-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${PROJECT_ROOT}/cmake/toolchains/${OS}-${ARCH}.cmake"
"-DVCPKG_OVERLAY_PORTS=${PROJECT_ROOT}/vcpkg/custom_ports"
)
cmake "${CMAKE_ARGS[@]}"
fi
# --- Build the application ---
if [ "$REBUILD_APP" = true ]; then
echo "--- Rebuilding application (clean build) with $GENERATOR ---"
cmake --build "$BUILD_DIR" --target clean
eval "$BUILD_CMD -C \"$BUILD_DIR\""
else
echo "--- Building application with $GENERATOR ---"
eval "$BUILD_CMD -C \"$BUILD_DIR\""
fi