forked from L-Acoustics/avdecc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_cmake.sh
More file actions
executable file
·310 lines (289 loc) · 8.21 KB
/
gen_cmake.sh
File metadata and controls
executable file
·310 lines (289 loc) · 8.21 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/bin/bash
# Useful script to generate project files using cmake
# Get absolute folder for this script
selfFolderPath="`cd "${BASH_SOURCE[0]%/*}"; pwd -P`/" # Command to get the absolute path
# Include util functions
. "${selfFolderPath}scripts/utils.sh"
# Override default cmake options
cmake_opt="-DBUILD_AVDECC_EXAMPLES=TRUE -DBUILD_AVDECC_TESTS=TRUE -DBUILD_AVDECC_LIB_SHARED_CXX=TRUE -DBUILD_AVDECC_LIB_STATIC_RT_SHARED=TRUE -DBUILD_AVDECC_DOC=TRUE -DBUILD_AVDECC_CONTROLLER=TRUE -DINSTALL_AVDECC_EXAMPLES=TRUE -DINSTALL_AVDECC_TESTS=TRUE -DINSTALL_AVDECC_LIB_SHARED_CXX=TRUE -DINSTALL_AVDECC_LIB_STATIC=TRUE -DINSTALL_AVDECC_HEADERS=TRUE -DINSTALL_AVDECC_DOC=TRUE -DENABLE_AVDECC_SIGNING=FALSE"
if isMac; then
cmake_opt="$cmake_opt -DBUILD_AVDECC_INTERFACE_MAC=TRUE -DBUILD_AVDECC_INTERFACE_PCAP_DYNAMIC_LINKING=FALSE -DBUILD_AVDECC_INTERFACE_VIRTUAL=TRUE"
elif isWindows; then
cmake_opt="$cmake_opt -DBUILD_AVDECC_INTERFACE_PCAP=TRUE -DBUILD_AVDECC_INTERFACE_PCAP_DYNAMIC_LINKING=TRUE -DBUILD_AVDECC_INTERFACE_VIRTUAL=TRUE"
else
cmake_opt="$cmake_opt -DBUILD_AVDECC_INTERFACE_PCAP=TRUE -DBUILD_AVDECC_INTERFACE_PCAP_DYNAMIC_LINKING=FALSE -DBUILD_AVDECC_INTERFACE_VIRTUAL=TRUE"
fi
############################ DO NOT MODIFY AFTER THAT LINE #############
# Default values
default_VisualGenerator="Visual Studio 16 2019"
default_VisualGeneratorArch="Win32"
default_VisualToolset="v142"
default_VisualToolchain="x64"
default_VisualArch="x86"
default_VisualSdk="8.1"
#
cmake_generator=""
generator_arch=""
arch=""
toolset=""
cmake_config=""
outputFolderBasePath="_build"
if isMac; then
cmake_path="/Applications/CMake.app/Contents/bin/cmake"
# CMake.app not found, use cmake from the path
if [ ! -f "${cmake_path}" ]; then
cmake_path="cmake"
fi
generator="Xcode"
getCcArch arch
defaultOutputFolder="${outputFolderBasePath}_<arch>"
else
# Use cmake from the path
cmake_path="cmake"
if isWindows; then
generator="$default_VisualGenerator"
generator_arch="$default_VisualGeneratorArch"
toolset="$default_VisualToolset"
toolchain="$default_VisualToolchain"
platformSdk="$default_VisualSdk"
arch="$default_VisualArch"
defaultOutputFolder="${outputFolderBasePath}_<arch>_<toolset>"
else
generator="Unix Makefiles"
getCcArch arch
defaultOutputFolder="${outputFolderBasePath}_<arch>_<config>"
fi
fi
which "${cmake_path}" &> /dev/null
if [ $? -ne 0 ]; then
echo "CMake not found. Please add CMake binary folder in your PATH environment variable."
exit 1
fi
outputFolder=""
outputFolderForced=0
add_cmake_opt=()
useVSclang=0
useVS2017=0
hasTeamId=0
doSign=0
while [ $# -gt 0 ]
do
case "$1" in
-h)
echo "Usage: gen_cmake.sh [options]"
echo " -h -> Display this help"
echo " -o <folder> -> Output folder (Default: ${defaultOutputFolder})"
echo " -f <flags> -> Force all cmake flags (Default: $cmake_opt)"
echo " -a <flags> -> Add cmake flags to default ones (or to forced ones with -f option)"
echo " -b <cmake path> -> Force cmake binary path (Default: $cmake_path)"
echo " -c <cmake generator> -> Force cmake generator (Default: $generator)"
if isWindows; then
echo " -t <visual toolset> -> Force visual toolset (Default: $toolset)"
echo " -tc <visual toolchain> -> Force visual toolchain (Default: $toolchain)"
echo " -64 -> Generate the 64 bits version of the project (Default: 32)"
echo " -vs2017 -> Compile using VS 2017 compiler instead of the default one"
echo " -clang -> Compile using clang for VisualStudio"
fi
if isMac; then
echo " -id <TeamIdentifier> -> iTunes team identifier for binary signing."
fi
if isLinux; then
echo " -debug -> Force debug configuration (Linux only)"
echo " -release -> Force release configuration (Linux only)"
fi
echo " -sign -> Sign binaries (Default: No signing)"
exit 3
;;
-o)
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -o option, see help (-h)"
exit 4
fi
outputFolder="$1"
outputFolderForced=1
;;
-f)
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -f option, see help (-h)"
exit 4
fi
cmake_opt="$1"
;;
-a)
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -a option, see help (-h)"
exit 4
fi
IFS=' ' read -r -a tokens <<< "$1"
for token in ${tokens[@]}
do
add_cmake_opt+=("$token")
done
;;
-b)
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -b option, see help (-h)"
exit 4
fi
if [ ! -x "$1" ]; then
echo "ERROR: Specified cmake binary is not valid (not found or not executable): $1"
exit 4
fi
cmake_path="$1"
;;
-c)
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -c option, see help (-h)"
exit 4
fi
cmake_generator="$1"
;;
-t)
if isWindows; then
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -t option, see help (-h)"
exit 4
fi
toolset="$1"
else
echo "ERROR: -t option is only supported on Windows platform"
exit 4
fi
;;
-tc)
if isWindows; then
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -tc option, see help (-h)"
exit 4
fi
toolchain="$1"
else
echo "ERROR: -tc option is only supported on Windows platform"
exit 4
fi
;;
-64)
if isWindows; then
generator="Visual Studio 15 2017 Win64"
arch="x64"
else
echo "ERROR: -64 option is only supported on Windows platform"
exit 4
fi
;;
-vs2017)
if isWindows; then
useVS2017=1
else
echo "ERROR: -vs2017 option is only supported on Windows platform"
exit 4
fi
;;
-clang)
if isWindows; then
useVSclang=1
else
echo "ERROR: -clang option is only supported on Windows platform"
exit 4
fi
;;
-id)
if isMac; then
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -id option, see help (-h)"
exit 4
fi
add_cmake_opt+=("-DLA_TEAM_IDENTIFIER=$1")
hasTeamId=1
else
echo "ERROR: -id option is only supported on macOS platform"
exit 4
fi
;;
-debug)
if isLinux; then
cmake_config="Debug"
add_cmake_opt+=("-DCMAKE_BUILD_TYPE=${cmake_config}")
else
echo "ERROR: -debug option is only supported on Linux platform"
exit 4
fi
;;
-release)
if isLinux; then
cmake_config="Release"
add_cmake_opt+=("-DCMAKE_BUILD_TYPE=${cmake_config}")
else
echo "ERROR: -release option is only supported on Linux platform"
exit 4
fi
;;
-sign)
add_cmake_opt+=("-DENABLE_AVDECC_SIGNING=TRUE")
doSign=1
;;
*)
echo "ERROR: Unknown option '$1' (use -h for help)"
exit 4
;;
esac
shift
done
if [ ! -z "$cmake_generator" ]; then
echo "Overriding default cmake generator ($generator) with: $cmake_generator"
generator="$cmake_generator"
fi
# Check TeamIdentifier specified is signing enabled on macOS
if isMac; then
if [[ $hasTeamId -eq 0 && $doSign -eq 1 ]]; then
echo "ERROR: macOS requires either iTunes TeamIdentifier to be specified using -id option, or -no-signing to disable binary signing"
exit 4
fi
fi
# Check if at least a -debug or -release option has been passed on linux
if isLinux; then
if [ -z $cmake_config ]; then
echo "ERROR: Linux requires either -debug or -release option to be specified"
exit 4
fi
fi
# Using -vs2017 option
if [ $useVS2017 -eq 1 ]; then
generator="Visual Studio 15 2017"
toolset="v141"
fi
# Using -clang option (shortcut to auto-define the toolset)
if [ $useVSclang -eq 1 ]; then
toolset="ClangCL"
fi
if [ $outputFolderForced -eq 0 ]; then
getOutputFolder outputFolder "${outputFolderBasePath}" "${arch}" "${toolset}" "${cmake_config}"
fi
generator_arch_option=""
if [ ! -z "${generator_arch}" ]; then
generator_arch_option="-A${generator_arch} "
fi
toolset_option=""
if [ ! -z "${toolset}" ]; then
if [ ! -z "${toolchain}" ]; then
toolset_option="-T${toolset},host=${toolchain} "
else
toolset_option="-T${toolset} "
fi
fi
sdk_option=""
if [ ! -z "${platformSdk}" ]; then
sdk_option="-DCMAKE_SYSTEM_VERSION=$platformSdk"
fi
echo "Generating cmake project..."
"$cmake_path" -H. -B"${outputFolder}" "-G${generator}" $generator_arch_option $toolset_option $sdk_option $cmake_opt "${add_cmake_opt[@]}"
echo ""
echo "All done, generated project lies in ${outputFolder}"