-
-
Notifications
You must be signed in to change notification settings - Fork 490
/
debug-macos.sh
executable file
·151 lines (136 loc) · 3.95 KB
/
debug-macos.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
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
#!/bin/bash
FRESH=false
ASAN=false
PRO=false
DEBUG=false
MACPORTS=false
HOMEBREW=false
STATIC=false
WARNINGS=false
BUILD_TYPE="MinSizeRel"
COMPILER_FLAGS=""
DEBUG_FLAGS=""
PRO_VERSION_FLAG=""
STATIC_FLAG=""
WARNING_FLAGS="-Wall -Wextra"
while (( "$#" )); do
case "$1" in
-f|--fresh)
FRESH=true
shift
;;
-a|--asan)
ASAN=true
shift
;;
-p|--pro)
PRO=true
shift
;;
-d|--debug)
DEBUG=true
shift
;;
-m|--macports)
MACPORTS=true
shift
;;
-h|--homebrew)
HOMEBREW=true
shift
;;
-s|--static)
STATIC=true
shift
;;
-w|--warnings)
WARNINGS=true
shift
;;
--)
shift
break
;;
-*)
echo "Unknown option: $1" >&2
exit 1
;;
*)
echo "Invalid argument: $1" >&2
exit 1
;;
esac
done
if [ "$MACPORTS" = true ] && [ "$HOMEBREW" = true ]; then
echo "Error: -m/--macports and -h/--homebrew options are mutually exclusive."
exit 1
fi
# remove MacPorts from PATH if we're not using it or we're using Homebrew
if [ "$MACPORTS" = false ] || [ "$HOMEBREW" = true ]; then
PATH=${PATH/\/opt\/local\/bin:/}
fi
if [ "$FRESH" = true ]; then
rm -rf .cache CMakeCache.txt CMakeFiles/ cmake_install.cmake
rm -rf build && git restore 'build/*'
fi
if [ "$ASAN" = true ]; then
DEBUG=true
DEBUG_FLAGS="-DBUILD_NO_OPTIMIZATION=On -DBUILD_ASAN_DEBUG=On"
fi
if [ "$PRO" = true ]; then
PRO_VERSION_FLAG="-DBUILD_PRO=On"
fi
if [ "$DEBUG" = true ]; then
BUILD_TYPE="Debug"
fi
if [ "$MACPORTS" = true ]; then
CLANG=$(which clang)
CLANGPP=$(which clang++)
if [ -z "$CLANG" ] || [ -z "$CLANGPP" ]; then
echo "clang or clang++ not found. Please ensure they are installed and in your PATH."
exit 1
fi
COMPILER_FLAGS="-DCMAKE_C_COMPILER=$CLANG -DCMAKE_CXX_COMPILER=$CLANGPP"
export CPPFLAGS='-isystem/opt/local/include'
export LDFLAGS='-L/opt/local/lib'
echo
echo "Using clang at $CLANG and clang++ at $CLANGPP from MacPorts"
fi
if [ "$HOMEBREW" = true ]; then
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm/lib/c++ -L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
echo
echo "Using clang at $(which clang) and clang++ at $(which clang++) from Homebrew"
fi
if [ "$STATIC" = true ]; then
STATIC_FLAG="-DBUILD_STATIC=On"
fi
if [ "$WARNINGS" = true ]; then
COMPILER_FLAGS="$COMPILER_FLAGS -DCMAKE_C_FLAGS=$WARNING_FLAGS -DCMAKE_CXX_FLAGS=$WARNING_FLAGS"
fi
echo
echo "+--------------------------------+-------+"
echo "| Build Options | Value |"
echo "+--------------------------------+-------+"
echo "| Fresh build (-f, --fresh) | $(printf "%-5s" $([ "$FRESH" = true ] && echo "Yes" || echo "No")) |"
echo "| Address Sanitizer (-a, --asan) | $(printf "%-5s" $([ "$ASAN" = true ] && echo "Yes" || echo "No")) |"
echo "| Pro version (-p, --pro) | $(printf "%-5s" $([ "$PRO" = true ] && echo "Yes" || echo "No")) |"
echo "| Debug build (-d, --debug) | $(printf "%-5s" $([ "$DEBUG" = true ] && echo "Yes" || echo "No")) |"
echo "| MacPorts (-m, --macports) | $(printf "%-5s" $([ "$MACPORTS" = true ] && echo "Yes" || echo "No")) |"
echo "| Homebrew (-h, --homebrew) | $(printf "%-5s" $([ "$HOMEBREW" = true ] && echo "Yes" || echo "No")) |"
echo "| Static build (-s, --static) | $(printf "%-5s" $([ "$STATIC" = true ] && echo "Yes" || echo "No")) |"
echo "| Warnings (-w, --warnings) | $(printf "%-5s" $([ "$WARNINGS" = true ] && echo "Yes" || echo "No")) |"
echo "+--------------------------------+-------+"
echo
cd ./build || exit
cmake -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
$PRO_VERSION_FLAG \
-DBUILD_SDLGPU=On \
$DEBUG_FLAGS \
$COMPILER_FLAGS \
$STATIC_FLAG \
-DBUILD_WITH_ALL=On \
-DCMAKE_EXPORT_COMPILE_COMMANDS=On \
.. && \
cmake --build . --config "$BUILD_TYPE" --parallel