-
Notifications
You must be signed in to change notification settings - Fork 19
/
example_build_script_2
executable file
·381 lines (268 loc) · 10 KB
/
example_build_script_2
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
#!/bin/bash
#
# Another example script for building dependencies and xReg.
# Compared to the other bash build script (example_build_script) which only uses
# static libraries and links from each dependency's cmake build directory, this script
# allows for shared libraries and will also install all dependencies into a specified
# install prefix. This allows users to pull in all dependencies by just setting the
# CMAKE_PREFIX_PATH to this directory when configuring the xReg build.
# stop after the first failed command
set -e
# Disable these to skip downloading and building dependencies
: ${NEED_TO_DOWNLOAD_THIRD_PARTY:=true}
: ${NEED_TO_BUILD_THIRD_PARTY:=true}
# Set this to false to not build xreg and only build the dependencies
: ${NEED_TO_BUILD_XREG:=true}
# This can be set to false when building on servers which do not have appropriate UI
# dependencies. This can avoid linker errors.
: ${XREG_DO_GUI:=true}
# Use these to explicitly set the build config
#BUILD_CONFIG="Debug"
#BUILD_CONFIG="Release"
# This uses a default config of release, but is overriden by the BUILD_CONFIG
# environment variable
: ${BUILD_CONFIG:=Release}
# Use these to explicitly set buiding shared or static libs
#BUILD_SHARED="ON"
#BUILD_SHARED="OFF"
# This defaults to static libs, but is overriden by the BUILD_SHARED environment variable
: ${BUILD_SHARED:=OFF}
# directory of the xReg repo (since this script is located in the repo root)
XREG_DIR="$(cd "$(dirname "$0")"; pwd)"
# use this to build the xreg library and apps within the repo directory:
XREG_BUILD_DIR="$XREG_DIR/build"
# use this to build the xreg library and apps in a tmp directory:
#XREG_BUILD_DIR="$HOME/tmp/xreg_build"
# set as blank to not install xreg, otherwise set to installation prefix
# The value here is the default value and is overriden by a XREG_INSTALL_DIR environment variable
: ${XREG_INSTALL_DIR:="$HOME/xreg"}
# Set DEPS_DIR to a directory outside of the xReg repo in which to download and build dependencies
# use this to build the deps in a subdirectory of the parent directory of the repo:
DEPS_DIR="$XREG_DIR/../xreg_deps_build"
# use this to build the deps in a tmp directory
#DEPS_DIR="$HOME/tmp/xreg_deps_build"
# use this to install the deps in a subdirectory of the parent directory of the repo:
DEPS_INSTALL_DIR="$XREG_DIR/../xreg_deps_install"
# use this to install the deps in a tmp directory
#DEPS_INSTALL_DIR="$HOME/tmp/xreg_deps_install"
# get rid of any repository prefix in the paths:
DEPS_DIR="$(cd "$(dirname "$DEPS_DIR")"; pwd)/$(basename "$DEPS_DIR")"
DEPS_INSTALL_DIR="$(cd "$(dirname "$DEPS_INSTALL_DIR")"; pwd)/$(basename "$DEPS_INSTALL_DIR")"
mkdir -p $DEPS_DIR
mkdir -p $DEPS_INSTALL_DIR
cd $DEPS_DIR
if ! [ -x "$(command -v wget)" ]; then
echo "wget is not available, using a wrapper to curl instead."
function wget()
{
FILENAME_TO_DOWNLOAD=`basename $1`
echo "Downloading $FILENAME_TO_DOWNLOAD ..."
curl -L -O $1
}
fi
# Operating system name
OS_STR=`uname -s`
if [ "$NEED_TO_DOWNLOAD_THIRD_PARTY" = true ]; then
echo "Downloading third party libraries..."
# Choose the TBB package for your operating system:
if [ "$OS_STR" == "Darwin" ]; then
TBB_URL="https://github.com/intel/tbb/releases/download/2018_U1/tbb2018_20170919oss_mac.tgz"
elif [ "$OS_STR" == "Linux" ]; then
TBB_URL="https://github.com/intel/tbb/releases/download/2018_U1/tbb2018_20170919oss_lin.tgz"
else
TBB_URL="https://github.com/intel/tbb/releases/download/2018_U1/tbb2018_20170919oss_win.zip"
fi
TBB_FILE=`basename $TBB_URL`
wget $TBB_URL
tar xf $TBB_FILE
rm $TBB_FILE
BOOST_URL="https://boostorg.jfrog.io/artifactory/main/release/1.74.0/source/boost_1_74_0.zip"
BOOST_FILE=`basename $BOOST_URL`
wget $BOOST_URL
unzip -q $BOOST_FILE
rm $BOOST_FILE
EIGEN_URL="https://gitlab.com/libeigen/eigen/-/archive/3.3.4/eigen-3.3.4.zip"
EIGEN_FILE=`basename $EIGEN_URL`
wget $EIGEN_URL
unzip -q $EIGEN_FILE
rm $EIGEN_FILE
VIENNACL_URL="https://github.com/viennacl/viennacl-dev/archive/release-1.7.1.zip"
VIENNACL_FILE=`basename $VIENNACL_URL`
wget $VIENNACL_URL
unzip -q $VIENNACL_FILE
rm $VIENNACL_FILE
FMT_URL="https://github.com/fmtlib/fmt/archive/5.3.0.zip"
FMT_FILE=`basename $FMT_URL`
wget $FMT_URL
unzip -q $FMT_FILE
rm $FMT_FILE
NLOPT_URL="https://github.com/stevengj/nlopt/archive/v2.5.0.zip"
NLOPT_FILE=`basename $NLOPT_URL`
wget $NLOPT_URL
unzip -q $NLOPT_FILE
rm $NLOPT_FILE
VTK_URL="https://www.vtk.org/files/release/8.2/VTK-8.2.0.zip"
wget $VTK_URL
VTK_FILE=`basename $VTK_URL`
unzip -q $VTK_FILE
rm $VTK_FILE
ITK_URL="https://github.com/InsightSoftwareConsortium/ITK/releases/download/v5.2.1/InsightToolkit-5.2.1.zip"
ITK_FILE=`basename $ITK_URL`
wget $ITK_URL
unzip -q $ITK_FILE
rm $ITK_FILE
OPENCV_URL="https://github.com/opencv/opencv/archive/3.4.12.zip"
OPENCV_FILE=`basename $OPENCV_URL`
wget $OPENCV_URL
unzip -q $OPENCV_FILE
rm $OPENCV_FILE
fi
TBB_EXTRACT_DIR="$DEPS_DIR/tbb2018_20170919oss"
TBB_INSTALL_DIR="$DEPS_INSTALL_DIR/tbb"
TBB_INC_DIR="$TBB_INSTALL_DIR/include"
TBB_CMAKE_DIR="$TBB_INSTALL_DIR/cmake"
BOOST_DIR="$DEPS_DIR/`ls | grep "boost_*"`"
EIGEN_DIR="$DEPS_DIR/`ls | grep "eigen-*"`"
VIENNACL_DIR="$DEPS_DIR/`ls | grep "viennacl-dev-release-*"`"
FMT_DIR="$DEPS_DIR/`ls | grep "fmt-*"`"
NLOPT_DIR="$DEPS_DIR/`ls | grep "nlopt-*"`"
VTK_DIR="$DEPS_DIR/`ls | grep "VTK-*"`"
ITK_DIR="$DEPS_DIR/`ls | grep "InsightToolkit-*"`"
OPENCV_DIR="$DEPS_DIR/`ls | grep "opencv-*"`"
if [ "$NEED_TO_BUILD_THIRD_PARTY" = true ] ; then
echo "Copying TBB to install prefix..."
mv $TBB_EXTRACT_DIR $TBB_INSTALL_DIR
echo "Copying header only libraries..."
mkdir -p $DEPS_INSTALL_DIR/include
mv $BOOST_DIR/boost $DEPS_INSTALL_DIR/include
mv $EIGEN_DIR/Eigen $DEPS_INSTALL_DIR/include
mv $EIGEN_DIR/unsupported $DEPS_INSTALL_DIR/include
mv $EIGEN_DIR/signature_of_eigen3_matrix_library $DEPS_INSTALL_DIR/include
mv $VIENNACL_DIR/viennacl $DEPS_INSTALL_DIR/include
echo "Building third-party libraries..."
cd $FMT_DIR
mkdir build
cd build
cmake -G Ninja .. \
-DCMAKE_INSTALL_PREFIX:PATH=$DEPS_INSTALL_DIR \
-DBUILD_SHARED_LIBS:BOOL=$BUILD_SHARED \
-DCMAKE_CXX_STANDARD:STRING="11" \
-DCMAKE_BUILD_TYPE:STRING=$BUILD_CONFIG \
-DFMT_USE_CPP11:BOOL=ON \
-DFMT_TEST:BOOL=OFF \
-DFMT_INSTALL:BOOL=ON \
-DFMT_DOC:BOOL=OFF
cmake --build .
cmake --install .
cd ../../
cd $NLOPT_DIR
mkdir build
cd build
cmake -G Ninja .. \
-DCMAKE_INSTALL_PREFIX:PATH=$DEPS_INSTALL_DIR \
-DBUILD_SHARED_LIBS:BOOL=$BUILD_SHARED \
-DCMAKE_CXX_STANDARD:STRING="11" \
-DCMAKE_BUILD_TYPE:STRING=$BUILD_CONFIG \
-DNLOPT_CXX:BOOL=OFF \
-DNLOPT_PYTHON:BOOL=OFF \
-DNLOPT_OCTAVE:BOOL=OFF \
-DNLOPT_MATLAB:BOOL=OFF \
-DNLOPT_GUILE:BOOL=OFF \
-DNLOPT_SWIG:BOOL=OFF \
-DNLOPT_LINK_PYTHON:BOOL=OFF
# nlopt tries to override the install prefix originally passsed
cmake -UCMAKE_INSTALL_PREFIX -DCMAKE_INSTALL_PREFIX:PATH=$DEPS_INSTALL_DIR .
cmake --build .
cmake --install .
cd ../../
cd $VTK_DIR
mkdir build
cd build
VTK_NO_RENDER_FLAGS=""
if [ "$XREG_DO_GUI" = false ]; then
VTK_NO_RENDER_FLAGS="-DVTK_RENDERING_BACKEND=None -DVTK_Group_Rendering:BOOL=OFF"
fi
TBB_ROOT="$TBB_INC_DIR/.." cmake -G Ninja .. \
-DCMAKE_INSTALL_PREFIX:PATH=$DEPS_INSTALL_DIR \
-DBUILD_SHARED_LIBS:BOOL=$BUILD_SHARED \
-DCMAKE_CXX_STANDARD:STRING="11" \
-DCMAKE_BUILD_TYPE:STRING=$BUILD_CONFIG \
-DVTK_Group_Imaging:BOOL=ON \
-DVTK_Group_Views:BOOL=ON \
-DBUILD_TESTING:BOOL=OFF \
-DVTK_SMP_IMPLEMENTATION_TYPE:STRING="TBB" $VTK_NO_RENDER_FLAGS
cmake --build .
cmake --install .
cd ../..
cd $ITK_DIR
mkdir build
cd build
cmake -G Ninja .. \
-DCMAKE_INSTALL_PREFIX:PATH=$DEPS_INSTALL_DIR \
-DBUILD_SHARED_LIBS:BOOL=$BUILD_SHARED \
-DCMAKE_CXX_STANDARD:STRING="11" \
-DCMAKE_BUILD_TYPE:STRING=$BUILD_CONFIG \
-DBUILD_TESTING:BOOL=OFF \
-DBUILD_EXAMPLES:BOOL=OFF \
-DITK_USE_GPU:BOOL=OFF \
-DModule_ITKReview:BOOL=ON \
-DModule_LabelErodeDilate:BOOL=ON
cmake --build .
cmake --install .
cd ../..
cd $OPENCV_DIR
mkdir build
cd build
# Need to set this OFF on MARCC (and other systems without the necessary deps)
OPENCV_GUI_FLAGS=""
if [ "$XREG_DO_GUI" = false ]; then
OPENCV_GUI_FLAGS="-DBUILD_opencv_highgui:BOOL=OFF -DWITH_GSTREAMER:BOOL=OFF"
fi
cmake -G Ninja .. \
-DCMAKE_INSTALL_PREFIX:PATH=$DEPS_INSTALL_DIR \
-DBUILD_SHARED_LIBS:BOOL=$BUILD_SHARED \
-DCMAKE_CXX_STANDARD:STRING="11" \
-DCMAKE_BUILD_TYPE:STRING=$BUILD_CONFIG \
-DBUILD_TESTS:BOOL=OFF \
-DBUILD_EXAMPLES:BOOL=OFF \
-DBUILD_DOCS:BOOL=OFF \
-DBUILD_WITH_DEBUG_INFO:BOOL=OFF \
-DWITH_TBB:BOOL=OFF \
-DBUILD_TBB:BOOL=OFF \
-DWITH_IPP:BOOL=OFF \
-DWITH_VTK:BOOL=OFF \
-DWITH_CUBLAS:BOOL=OFF \
-DWITH_CUDA:BOOL=OFF \
-DWITH_CUFFT:BOOL=OFF \
-DWITH_OPENCL:BOOL=OFF \
-DWITH_EIGEN:BOOL=OFF \
-DBUILD_opencv_python2:BOOL=OFF \
-DBUILD_opencv_python3:BOOL=OFF $OPENCV_GUI_FLAGS
cmake --build .
cmake --install .
cd ../..
fi
# START: XREG BUILD:
if [ "$NEED_TO_BUILD_XREG" = true ]; then
mkdir $XREG_BUILD_DIR
cd $XREG_BUILD_DIR
XREG_POS_INDEP_CODE_FLAG=""
if [ "$OS_STR" == "Linux" ] && [ "$BUILD_SHARED" == "ON" ]; then
XREG_POS_INDEP_CODE_FLAG="-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON"
fi
XREG_CMAKE_INSTALL_FLAG=""
if [ "$XREG_INSTALL_DIR" != "" ]; then
XREG_CMAKE_INSTALL_FLAG="-DCMAKE_INSTALL_PREFIX:PATH=$XREG_INSTALL_DIR"
fi
cmake -G Ninja $XREG_DIR \
-DCMAKE_PREFIX_PATH:PATH=$DEPS_INSTALL_DIR \
-DBUILD_SHARED_LIBS:BOOL=$BUILD_SHARED \
-DCMAKE_BUILD_TYPE:STRING=$BUILD_CONFIG \
-DXREG_USE_LEGACY_FIND_TBB:BOOL=OFF \
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON \
-DXREG_INCLUDE_GIT_HASH_IN_VER_STR:BOOL=ON $XREG_POS_INDEP_CODE_FLAG $XREG_CMAKE_INSTALL_FLAG
cmake --build .
if [ "$XREG_INSTALL_DIR" != "" ]; then
cmake --install .
fi
fi