-
Notifications
You must be signed in to change notification settings - Fork 15
/
configure.sh
executable file
·112 lines (101 loc) · 3.49 KB
/
configure.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
#!/bin/sh
# Set the following env vars to control this script.
#
# General:
# * USE_DEBUG=[true|false] to enable debug symbols or optimizations.
# Default: false
# * TESTS=[true|false] to build tests.
# Default: true
# * BENCHMARKS=[true|false] to build benchmarks.
# Default: true
# * USE_BREW=[true|false] to use clang/libc++ from homebrew on MacOS.
#
# Requires LLVM:
# * SUBDOC=[true|false] to build subdoc. This requires an LLVM installation.
# Default: false
# * LLVM_ROOT=/path/to/llvm/install where there should exist `lib/cmake/llvm`
# and `lib/cmake/clang`. Needed if SUBDOC=true or if USE_LLVM_CLANG=true.
# * USE_LLVM_CLANG=[true|false] to use clang found in the LLVM_ROOT. Otherwise
# it uses the standard CMake compiler detection.
# Default: false
#
# Requires compiling with Clang:
# * USE_LLD=[true|false] to link with lld linker instead of the system linker.
# Clang must have been built with `lld` in the cmake config variable
# `LLVM_ENABLE_PROJECTS`.
# Default: false
# * USE_ASAN=[true|false] to build against Address Sanitizer. Clang must have
# been built with `compiler-rt` in the cmake config variable
# `LLVM_ENABLE_PROJECTS`.
# Defaults.
if [[ $USE_DEBUG == "" ]]; then USE_DEBUG=false; fi
if [[ $TESTS == "" ]]; then TESTS=true; fi
if [[ $BENCHMARKS == "" ]]; then BENCHMARKS=true; fi
if [[ $SUBDOC == "" ]]; then SUBDOC=false; fi
if [[ $LLVM_ROOT == "" ]]; then LLVM_ROOT=$HOME/s/llvm/install; fi
if [[ $USE_ASAN == "" ]]; then USE_ASAN=false; fi
if [[ $USE_LLD == "" ]]; then USE_LLD=false; fi
if [[ $USE_LLVM_CLANG == "" ]]; then USE_LLVM_CLANG=false; fi
if [[ $USE_BREW == "" ]]; then USE_BREW=false; fi
# System detection.
if [[ $OSTYPE == darwin* ]]; then IS_MAC=true; else IS_MAC=false; fi
# Figure out our command line parameters.
if [[ $USE_DEBUG == true ]]; then
BUILD_TYPE=Debug
else
BUILD_TYPE=Release
fi
if [[ $USE_ASAN == true ]]; then
CXXFLAGS="$CXXFLAGS -fsanitize=address";
fi
if [[ $USE_LLD == true ]]; then
LDFLAGS="$LDFLAGS -fuse-ld=lld"
fi
if [[ $SUBDOC == true ]]; then
SUBSPACE_BUILD_SUBDOC=ON
else
SUBSPACE_BUILD_SUBDOC=OFF
fi
if [[ $TESTS == true ]]; then
SUBSPACE_BUILD_TESTS=ON
else
SUBSPACE_BUILD_TESTS=OFF
fi
if [[ $BENCHMARKS == true ]]; then
SUBSPACE_BUILD_BENCHMARKS=ON
else
SUBSPACE_BUILD_BENCHMARKS=OFF
fi
function set_env() {
echo Set env: "$@"
export "$@"
}
function run() {
echo Running: "$@"
"$@" || exit 1
}
if [[ $USE_LLVM_CLANG == true ]]; then
set_env CC="$LLVM_ROOT/bin/clang"
set_env CXX="$LLVM_ROOT/bin/clang++"
fi
if [[ $IS_MAC == true && $USE_ASAN == true ]]; then
if [[ $CXX == "" ]]; then CLANG=clang++; else CLANG=$CXX; fi
RESOURCE_DIR=$($CLANG --print-resource-dir)
run codesign -f -s - "$RESOURCE_DIR/lib/darwin/libclang_rt.asan_osx_dynamic.dylib"
fi
if [[ $USE_BREW == true ]]; then
set_env CC="/opt/homebrew/opt/llvm/bin/clang"
set_env CXX="/opt/homebrew/opt/llvm/bin/clang++"
set_env LDFLAGS="-L/opt/homebrew/opt/llvm/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm/lib/c++ $LDFLAGS"
fi
set_env LLVM_DIR="$LLVM_ROOT/lib/cmake/llvm"
set_env Clang_DIR="$LLVM_ROOT/lib/cmake/clang"
run cmake -B out \
-DSUBSPACE_BUILD_TESTS=$SUBSPACE_BUILD_TESTS \
-DSUBSPACE_BUILD_SUBDOC=$SUBSPACE_BUILD_SUBDOC \
-DSUBSPACE_BUILD_BENCHMARKS=$SUBSPACE_BUILD_BENCHMARKS \
-G Ninja \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
-DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" \
-DCMAKE_SHARED_LINKER_FLAGS="$LDFLAGS"