-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathbuild-preset.sh
executable file
·161 lines (143 loc) · 3.47 KB
/
build-preset.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
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PROJECT=rellic
BUILDLOG=${PROJECT}-build.log
CONFIGLOG=${PROJECT}-configure.log
rm -f ${BUILDLOG} ${CONFIGLOG}
BUILD_TYPE=dbg
VCPKG_SUFFIX="-rel"
set -o pipefail
function sanity_check {
if [ -z "${CMAKE_TOOLCHAIN_FILE}" ]; then
echo "Please set the CMAKE_TOOLCHAIN_FILE environment variable to the CMake toolchain file to build against"
exit 1
else
echo "Building against CMake toolchain file: [${CMAKE_TOOLCHAIN_FILE}]"
fi
if [ -z "${INSTALL_DIR}" ]; then
echo "Please set the INSTALL_DIR environment variable to the desired installation directory"
exit 1
else
echo "Installing to: [${INSTALL_DIR}]"
fi
}
function show_usage {
printf "${0}: Build ${PROJECT} <debug|release> [-- extra arguments to CMake]"
printf "\n"
printf "\t--help: this screen\n"
printf "\t--debug-vcpkg: build against a debug vcpkg (default OFF)\n"
printf "\t<debug|release|asan>: the type of build to do (debug or release or asan+debug)\n"
printf "\tArguments after '--' are passed to CMake during configuration (e.g. -DCMAKE_C_COMPILER=foo)\n"
printf "\n"
printf "INSTALL_DIR set to [${INSTALL_DIR}]\n"
printf "CMAKE_TOOLCHAIN_FILE set to [${CMAKE_TOOLCHAIN_FILE}]\n"
return 0
}
function set_arch {
local arch=$(uname -m)
case ${arch} in
aarch64 | arm64)
echo "arm64"
;;
x86_64)
echo "x64"
;;
*)
echo "Unknown architecture: ${arch}"
exit 1
esac
}
function set_os {
local os=$(uname -s)
case ${os} in
Darwin)
echo "osx"
;;
Linux)
echo "linux"
;;
*)
echo "Unknown OS: ${os}"
exit 1
esac
}
# Make the user specify which build type
if [[ $# -eq 0 ]]; then
show_usage ${0}
exit 0
fi
# check if proper env vars are set
sanity_check
# Look for help or set the build type
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--help | -h | "-?")
show_usage ${0}
exit 0
;;
--debug-vcpkg)
VCPKG_SUFFIX=""
shift
;;
debug)
BUILD_TYPE="dbg"
shift
;;
release)
BUILD_TYPE="rel"
shift
;;
asan)
BUILD_TYPE="asan"
VCPKG_SUFFIX="-asan"
shift
;;
"--")
shift
break
;;
*) # unknown option
echo "UNKNOWN OPTION: ${1}"
echo "Usage:"
show_usage ${0}
exit 1
;;
esac
done
ARCH=$(set_arch)
OS=$(set_os)
export VCPKG_TARGET_TRIPLET=${ARCH}-${OS}${VCPKG_SUFFIX}
echo "Configuring [${BUILD_TYPE}] [${ARCH}] against vcpkg [${VCPKG_TARGET_TRIPLET}]..."
if [[ "${@}" != "" ]]
then
echo "Passing extra arguments to CMake: ${@}"
fi
cmake --preset vcpkg-${ARCH}-${BUILD_TYPE} ${@} &>${CONFIGLOG}
if [ "$?" != "0" ]; then
echo "Configuration failed. See ${CONFIGLOG}"
cat "${CONFIGLOG}"
exit 1
else
echo "Configure success!"
fi
echo "Building [${BUILD_TYPE}] [${ARCH}]..."
cmake --build --preset ${ARCH}-${BUILD_TYPE} --parallel &>${BUILDLOG}
if [ "$?" != "0" ]; then
echo "Build failed. See ${BUILDLOG}"
cat "${BUILDLOG}"
exit 1
else
echo "Build success!"
fi
echo "Installing [${BUILD_TYPE}] [${ARCH}]..."
# re-use build log since its mostly a part of build process
cmake --build --preset ${ARCH}-${BUILD_TYPE} --target install --parallel >>${BUILDLOG} 2>&1
if [ "$?" != "0" ]; then
echo "Install failed. See ${BUILDLOG}"
cat "${BUILDLOG}"
exit 1
else
echo "Install success!"
fi