This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
configure
executable file
·475 lines (376 loc) · 15.5 KB
/
configure
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#!/bin/bash
# Exit immediately on failure of a subcommand
set -e
##=============================================================================
## Main configuration processing
RELEASE_DIR=release
DEBUG_DIR=debug
TURI_HOME=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
DEPS_PREFIX=$PWD/deps/local
IOS_DEFAULT_MIN_VERSION=12
MACOS_DEFAULT_MIN_VERSION=10.12
function print_help {
echo "Configures the build with the specified toolchain. "
echo
echo "If configure has already been run before, running configure "
echo "will simply reconfigure the build with no changes. "
echo
echo "Usage: ./configure <options>"
echo
echo " --cleanup Clean up everything."
echo
echo " --install-python-toolchain Install python in local virtualenv."
echo
echo " --no-pre-commit don't install any git pre-commit hooks"
echo
echo " --with-ccache (default) Use ccache, if available."
echo " --no-ccache "
echo
echo " --with-clang-tidy Run clang-tidy, if available."
echo " --with-clang-metrics Run clang with timing metrics. Requires Clang 9.0."
echo
echo " --with-capi (default) Build C API."
echo " --with-capi-framework Build C API as macOS framework (macOS + XCode builder only)"
echo " --no-capi Skip building the C API."
echo
echo " --with-python (default) Build python components."
echo " --no-python"
echo
echo " --virtualenv=VIRTUALENV_EXE Path to virtualenv executable (otherwise looks in \$PATH)."
echo
echo " --with-visualization (default) Build Turi Create visualization client."
echo " --no-visualization"
echo
echo " --release-opt-for-size Optimize for size."
echo " --debug-opt-for-size Debug optimize for size."
echo
echo " --arch=<architecture> The target architecture. "
echo " May be added multiple times. First entry is used to determine compile-time features."
echo
echo " --with-remotefs (default) Include capabilities for remote file access."
echo " --no-remotefs Disable remote file access."
echo
echo " --builder=<builder> Generates build files for the given build system. "
echo " Possible values are make (default), xcode, or ninja."
echo
echo " --with-release (default) Configure release-mode build directory release/."
echo " --no-release Disable release-mode build directory release/."
echo
echo " --release-dir=<dir> Directory to use for release mode build tree."
echo
echo " --with-debug (default) Configure debug-mode build directory release/."
echo " --no-debug Disable release-mode build directory release/."
echo
echo " --debug-dir=<dir> Directory to use for debug mode build tree."
echo
echo " --yes Defaults to yes on a prompt"
echo
echo " --min-ios-version Override the minimum iOS version (default ${IOS_DEFAULT_MIN_VERSION})"
echo " --min-macos-version Override the minimum MacOS version (default ${MACOS_DEFAULT_MIN_VERSION})"
echo
echo " --codesign Enable code signing for OSX projects. If enabled, the "
echo " proper CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_**** parameters "
echo " denoting the signing variables should be passed in."
echo
echo " --list-source-files If given, a list of all the source files compiled using "
echo " the given options is printed as part of the configuration, "
echo " using the [SOURCE:<source_file>] format. "
echo
echo " -D var=value Specify FLAGS definitions to be passed on to cmake."
echo
echo "Relevant environment variables: "
echo
echo " CMAKE Path to CMake executable."
echo " CC Path to C compiler."
echo " CXX Path to C++ compiler."
echo
echo "Example: ./configure"
echo
echo "Cleanup all build directories"
echo "Example: ./configure --cleanup"
echo
echo
exit 1
} # end of print help
function unknown_option {
echo "Unrecognized option: $1"
echo "To get help, run ./configure --help"
exit 1
} # end of unknown option
function run_cleanup {
echo "cleaning up";
rm -rf release debug deps/local/ deps/build/ deps/env
}
function run_cleanup_prompt {
#!/bin/bash
echo "This script completely erases all build folders including dependencies!"
if [[ $default_yes == 1 ]]; then
yesorno="yes"
else
echo "Are you sure you want to continue? (yes or no)"
read yesorno;
fi
if [ "$yesorno" == "yes" ]; then
run_cleanup
else
echo "Doing nothing!";
fi
}
function install_python_toolchain {
echo "Installing python toolchain."
# TODO - validate that $VIRTUALENV is set, and/or set it if not
echo "Using virtualenv at $VIRTUALENV."
pushd ${TURI_HOME}
VIRTUALENV=${VIRTUALENV} ./scripts/install_python_toolchain.sh
popd
}
# command flag options
cleanup_option=0
python_only=0
default_yes=0
with_python=1
with_pre_commit=1
with_ccache=1
with_clangtidy=0
with_clangmetrics=0
with_capi=1
with_capi_framework=0
with_ios=0
with_ccache=1
with_visualization=1
with_remotefs=1
with_release=1
with_debug=1
release_opt_for_size=0
debug_opt_for_size=0
arch_list=""
target=""
builder="make"
min_ios_version=${IOS_DEFAULT_MIN_VERSION}
min_macos_version=${MACOS_DEFAULT_MIN_VERSION}
enable_codesign=0
list_source_files=0
DEBUG_DIR="${TURI_HOME}/debug"
RELEASE_DIR="$TURI_HOME/release"
###############################################################################
#
# Parse command line configure flags ------------------------------------------
#
while [ $# -gt 0 ]
do case $1 in
--cleanup) cleanup_option=1;;
--install-python-toolchain) python_only=1;;
--release-opt-for-size) release_opt_for_size=1;;
--debug-opt-for-size) debug_opt_for_size=1;;
--target=*) target=${1##--target=};;
--target) target=${2}; shift;;
--arch=*) arch_list="${arch_list};${1##--arch=}";;
--arch) arch_list="${arch_list};$2"; shift ;;
--no-pre-commit) with_pre_commit=0;;
--with-ccache) with_ccache=1;;
--no-ccache) with_ccache=0;;
--with-clang-tidy) with_clangtidy=1;;
--with-clang-metrics) with_clangmetrics=1;;
--with-capi) with_capi=1;;
--with-capi-framework) with_capi=1; with_capi_framework=1;;
--no-capi) with_capi=0;;
--with-python) with_python=1;;
--no-python) with_python=0;;
--with-visualization) with_visualization=1;;
--no-visualization) with_visualization=0;;
--with-remotefs) with_remotefs=1;;
--no-remotefs) with_remotefs=0;;
--with-release) with_release=1;;
--no-release) with_release=0;;
--with-debug) with_debug=1;;
--no-debug) with_debug=0;;
--release-dir=*) RELEASE_DIR=${1##--release-dir=} ;;
--release-dir) RELEASE_DIR=${2} ; shift ;;
--debug-dir=*) DEBUG_DIR=${1##--debug-dir=} ;;
--debug-dir) DEBUG_DIR=${2} ; shift ;;
--yes) default_yes=1;;
--builder=*) builder=${1##--builder=} ;;
--builder) builder=${2} ; shift ;;
--codesign) enable_codesign=1;;
--help) print_help ;;
-D) CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -D $2"; shift ;;
--virtualenv=*) VIRTUALENV="${1##--virtualenv=}" ;;
--virtualenv) VIRTUALENV="$2"; shift ;;
--min-ios-version=*) min_ios_version=${1##--min-ios-version=};;
--min-ios-version) min_ios_version=${2}; shift;;
--min-macos-version=*) min_macos_version=${1##--min-macos-version=};;
--min-macos-version) min_macos_version=${2}; shift ;;
--list-source-files) list_source_files=1 ;;
*) unknown_option $1 ;;
esac
shift
done
if [[ $cleanup_option == 1 ]]; then
run_cleanup_prompt
exit 0
fi
if [[ $python_only == 1 ]]; then
with_pre_commit=$with_pre_commit install_python_toolchain
exit $?
fi
# If we need to build python, we also need to install the python toolchain
if [[ $with_python == 1 ]]; then
if [[ $with_visualization == 0 ]]; then
echo "Visualization client libraries (--with-visualization) required for python build."
exit 1
fi
install_python_toolchain
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_PYTHON=1"
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DPYTHON_EXECUTABLE:FILEPATH=${PWD}/deps/env/bin/python"
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DPYTHON_INCLUDE_DIR=${PWD}/deps/env/include/python*/"
# Activate the virtual environment
export PYTHON_EXECUTABLE=${PWD}/deps/env/bin/python
export PATH=${PWD}/deps/env/bin:$PATH
else
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_PYTHON=0"
fi
# Release Opt for size
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DRELEASE_OPT_FOR_SIZE=${release_opt_for_size}"
# Debug Opt for size
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DDEBUG_OPT_FOR_SIZE=${debug_opt_for_size}"
# Tell CMake whether we need to build the remote FS stuff.
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_LIST_SOURCE_FILES=${list_source_files}"
# Check what is needed with the remote_fs stuff
if [[ $with_capi == 1 ]]; then
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_CAPI=1"
if [[ $with_capi_framework == 1 ]]; then
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_CAPI_FRAMEWORK=1"
fi
else
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_CAPI=0"
fi
# Do we need to build the visualization toolkit?
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_VISUALIZATION_CLIENT=${with_visualization}"
# Tell CMake whether we need to build the remote FS stuff.
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_REMOTEFS=${with_remotefs}"
##################################################################3
# setup compilers and includes
#
# mac compiler detection
export LD_LIBRARY_PATH=${PWD}/deps/local/lib:${PWD}/deps/local/lib64:$LD_LIBRARY_PATH
export INCLUDE_PATH=${PWD}/deps/local/include:$LD_LIBRARY_PATH
echo "======================= BUILD CONFIGURATION ========================"
echo "System Information: "
uname -v
build_platform="$(uname -s)"
case "${build_platform}" in
Darwin*) build_platform=macosx;;
Linux*) build_platform=linux;;
*) ;;
esac
echo "Build platform identified as ${build_platform}."
if [[ ! -z ${arch_list} ]] ; then
arch_list="${arch_list##;}"
echo "Using architectures: ${arch_list}"
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DTC_BUILD_ARCH='${arch_list}'"
fi
if [[ -z ${target} ]] ; then
target=${build_platform}
fi
echo "Build targeting ${target}."
echo "======================= FINDING COMPILERS ========================"
# Set up the compilers
mkdir -p ${PWD}/deps/local/bin
CCCMD=`./scripts/find_compiler.sh cc --ccache=$with_ccache --script-dir=${PWD}/deps/local/bin/`
CXXCMD=`./scripts/find_compiler.sh cxx --ccache=$with_ccache --script-dir=${PWD}/deps/local/bin/`
echo "Setting C compiler to $CCCMD."
echo "Setting C++ compiler to $CXXCMD."
if [[ $with_clangtidy == 1 ]]; then
clangtidy_path=$(which clang-tidy || true)
if [[ ! -x "$clangtidy_path" ]]; then
echo "Unable to find clang-tidy in path."
exit 1
fi
echo "Setting clang-tidy to $clangtidy_path"
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_CXX_CLANG_TIDY=${clangtidy_path}"
fi
if [[ $with_clangmetrics == 1 ]]; then
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DTC_BUILD_METRICS=ON"
fi
echo "======================= FINDING CMAKE ========================"
# Set up the path to CMake
CMAKE=`./scripts/find_cmake.sh`
########################################################
# Prepare to build
set -e
set -o pipefail
case $builder in
xcode)
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -GXcode"
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=1"
if [[ ! -z ${arch_list} ]] ; then
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_OSX_ARCHITECTURES='${arch_list}'"
fi
;;
make) ;;
ninja) CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -Gninja"
;;
*) echo "Unrecognized builder $builder; valid options are make, ninja, and xcode." ; exit 1 ;;
esac
if [[ ${enable_codesign} == 1 ]] ; then
if [[ ! $builder == xcode ]] ; then
echo "Code signing currently only supported with xcode builder."
exit 1
fi
elif [[ ${builder} == xcode ]] ; then
# Deal with the code signing issues.
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY= -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=0 -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM= "
# This also requires us to skip the code signing when trying to compile targets to check definitions.
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY"
echo "Skipping code signing."
fi
#######################################################
# Handle the case where the builder is not xcode but we still need to set the sdk root.
if [[ ${build_platform} == macosx ]] && [[ ${target} != macosx* ]] ; then
if [[ ${builder} != xcode ]] ; then
# Cross-platform builds on macosx must use the xcode builder.
echo "ERROR: cross-compilation on OSX requires the xcode build train using --builder=xcode."
exit 1
fi
# Turn on cross compilation
# Setting CMAKE_SYSTEM_NAME turns on cross-compilation (setting CMAKE_CROSSCOMPILING=1)
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DCMAKE_SYSTEM_NAME=Darwin"
# Target build architecture to be the first architecture given by the arch list.
config_arch="${arch_list%%;*}"
CMAKE_CONFIG_FLAGS="$CMAKE_CONFIG_FLAGS -DCMAKE_SYSTEM_PROCESSOR=${config_arch}"
echo "Targeting build configuration to run on ${config_arch}."
fi
if [[ ${build_platform} == macosx ]] ; then
SDKROOT=`xcrun --sdk ${target} --show-sdk-path || echo ""`
if [[ -z ${SDKROOT} ]] ; then
echo "Cannot find valid SDK for target ${target}. (command xcrun --sdk ${target} --show-sdk-path)."
fi
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DTC_BASE_SDK=${target} -DCMAKE_OSX_SYSROOT=${SDKROOT}"
# Set up minimum versions
if [[ ${target} == iphoneos* ]] ; then
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_OSX_DEPLOYMENT_TARGET=${min_ios_version} -DTC_BUILD_IOS=1"
elif [[ ${target} == macosx* ]] ; then
target_tag=x86_64-apple-macos${min_macos_version}
CMAKE_CONFIG_FLAGS="${CMAKE_CONFIG_FLAGS} -DCMAKE_OSX_DEPLOYMENT_TARGET=${min_macos_version} -DCMAKE_CXX_COMPILER_TARGET=${target_tag} -DCMAKE_C_COMPILER_TARGET=${target_tag} -DTC_BUILD_IOS=0"
else
echo "ERROR: Compiling for unsupported target ${target}."
exit 1
fi
fi
build_cmd="$CMAKE \
$GENERATOR \
-D CMAKE_C_COMPILER=$CCCMD \
-D CMAKE_CXX_COMPILER=$CXXCMD \
${CMAKE_CONFIG_FLAGS}"
if [[ $with_debug == 1 ]] ; then
set -x
mkdir -p ${DEBUG_DIR}
cd ${DEBUG_DIR} && $build_cmd -DCMAKE_BUILD_TYPE=Debug -D CMAKE_CONFIGURATION_TYPES='Debug;Release' ${TURI_HOME}
set +x
fi
if [[ $with_release == 1 ]] ; then
set -x
mkdir -p ${RELEASE_DIR}
cd ${RELEASE_DIR} && $build_cmd -DCMAKE_BUILD_TYPE=Release -D CMAKE_CONFIGURATION_TYPES='Release;Debug' ${TURI_HOME}
set +x
fi