forked from KognitionAI/pilecv4j-opencv-packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfromscratch.sh
More file actions
executable file
·678 lines (604 loc) · 24.6 KB
/
fromscratch.sh
File metadata and controls
executable file
·678 lines (604 loc) · 24.6 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
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
#!/bin/bash
if [ "$VERBOSE" != "" ]; then
set -x
fi
MIN_MAJOR_VER=3
MIN_MINOR_VER=4
TO_PATCH_VER=3.4.0
# =============================================================================
# Preamble
# =============================================================================
set -e
MAIN_DIR="$(dirname "$BASH_SOURCE")"
cd "$MAIN_DIR"
PROJDIR="$(pwd -P)"
OS=`uname`
# Platform specifics
WINDOWS=
set +e
if [ "$(echo "$OS" | grep MINGW)" != "" ]; then
PLAT=MINGW
WINDOWS=true
elif [ "$(echo "$OS" | grep MSYS)" != "" ]; then
PLAT=MINGW
WINDOWS=true
elif [ "$(echo "$OS" | grep CYGWIN)" != "" ]; then
PLAT=CYGWIN
WINDOWS=true
elif [ "$(echo "$OS" | grep Linux)" != "" ]; then
PLAT=Linux
else
echo "Sorry, I don't know how to handle building for \"$OS.\" Currently this works on:"
echo " 1) Windows using MSYS2"
echo " 2) Windows using Cygwin"
echo " 3) Linux"
exit 1
fi
set -e
if [ "$WINDOWS" = "true" ]; then
cpath() {
cygpath "$1"
}
if [ "$PLAT" = "CYGWIN" ]; then
cwpath() {
cygpath -w "$1"
}
else
cwpath() {
echo "$1"
}
fi
else
INSTALL_TARGET=install
cpath() {
echo "$1"
}
cwpath() {
echo "$1"
}
fi
sgrep() {
set +e
grep "$@"
set -e
}
segrep() {
set +e
egrep "$@"
set -e
}
# Determine arch automatically for Windows so you don't need to specify it in the generator
OS_SPECIFIC_CMAKE_OPTIONS=
CMAKE_ARCH=
if [ "$WINDOWS" = "true" ]; then
if [ "$(arch | sgrep 64)" != "" ]; then
CMAKE_ARCH="-Ax64"
fi
OS_SPECIFIC_CMAKE_OPTIONS="-DBUILD_WITH_STATIC_CRT=ON"
fi
# =============================================================================
DEFAULT_WORKING_DIRECTORY=/tmp/opencv-working
usage() {
echo "[GIT=/path/to/git/binary/git] [JAVA_HOME=/path/to/java/jdk/root] [MVN=/path/to/mvn/mvn] [CMAKE=/path/to/cmake/cmake] $BASH_SOURCE --opencv-version opencv-version --version version [options]"
echo ""
echo " --opencv-version opencv-version: This needs to be specified. e.g. \"--opencv-version 4.5.2\""
echo " --version version: This needs to be specified. e.g. \"--version 1.0\""
echo " --install-prefix|-i /path/to/install/opencv : Install opencv to the given path."
echo ""
echo " This checkout and build opencv then it will package it up so that it can be used from a self contained"
echo " java jar without any additional dependencies installed. The maven artifact created will be:"
echo " \"ai.kognition.pilecv4j:opencv-(platform):(version)-opencv(opencv-version)[-cuda(cuda-version)]:jar\""
echo " a few examples:"
echo " \"ai.kognition.pilecv4j:opencv-windows-x86_64:1.0-opencv4.5.2:jar\""
echo " \"ai.kognition.pilecv4j:opencv-linux-x86_64:1.0-opencv4.5.2-cuda11.2:jar\""
echo " Options:"
echo " -w /path/to/workingDirectory: this is $DEFAULT_WORKING_DIRECTORY by default. The directory is created"
echo " and deleted as necessary."
echo " -jN: specify the number of threads to use when running make. If the cmake-generator is"
echo " Visual Studio then this translates to /m option to \"msbuild\""
echo " -G cmake-generator: specifially specify the cmake generator to use. The default is chosen otherwise."
echo " --zip /path/to/zip: Create a zip file of the final installed directory with the headers and libraries."
echo ""
echo " --help|-help: print this message"
echo " --skip-checkout: This will \"skip the checkout\" of the opencv code. If you're playing with different"
echo " options then once the code is checked out, using --skip-checkout will allow subsequent runs to progress"
echo " faster. This doesn't work unless the working directory remains the same between runs."
echo " --skip-packaging: Skip the packaging step. That is, only build opencv and opencv_contrib libraries but"
echo " don't package them in a jar file for use with net.dempsy.util.library.NativeLivbraryLoader"
echo " --deploy: perform a \"mvn deploy\" rather than just a \"mvn install\""
echo " --deploy-zip: by default the zipped up opencv distribution created using --zip will not be deployed even"
echo " when the --deploy flag is used. If you want to explicitly deploy it you'll need to include --deploy-zip"
echo " also. Obviously if you specify --deploy-zip you must also request the opencv distribution be zipped"
echo " using --zip"
echo " --offline: Pass -o to maven."
echo ""
echo " Build Options"
echo " --static(default)|--no-static: force the build to statically link (dynamically link for \"--no-static\")"
echo " the JNI libraries. By default, the JNI library is statically linked on all platform builds."
echo " --build-python: Build python3 wrappers. By default, the script blocks building the Python wrappers. If"
echo " you want to build them anyway you can specify \"--build-python\" or \"--build-python-3\"."
echo " --build-python-2: Build python2 wrappers. By default, the script blocks building the Python wrappers."
echo " This is mutually exclusive with \"--build-python\"."
echo " --build-samples: Build the OpenCV samples also."
echo " --build-cuda-support: Build the OpenCV using NVidia's CUDA (Note: CUDA must already be installed, this"
echo " option is untested on Windows). The cuda version will be determined by what's installed."
echo " --build-qt-support: Build the OpenCV using QT as the GUI implementation (Note: QT5 Must already be"
echo " installed, this option is untested on Windows)."
echo " --build-gst-support: Build the OpenCV with gstreamer support. Normally, if you have gstreamer installed"
echo " the default OpenCV build will detect it and build against it. This script disabled that by default."
echo " If you want the OpenCV build's default behavior, use this option"
echo " --no-dnn: disable opencv's DNN support. As a note, OpenCV's DNN seems to conflict with Caffee. Disabling"
echo " OpenCV's DNN also means that DNN Object detection and the contrib module \"text\" is also disabled,"
echo " as is potentially other modules that depend on opencv's DNN support."
echo " --build-cuda-dnn: This option will enable OpenCV's internal build of CUDA DNN. This will also require CUDA."
echo " --build-protobuf: This option will enable OpenCV's internal build of protobuf. While the raw OpenCV build"
echo " defaults to building this, this script defaults to blocking it since it tends to conflict with"
echo " other systems that also rely on protobufs. NOT selecting this option implies protobuf will need to be"
echo " installed on your build machine. You should set the environment variable CMAKE_PREFIX_PATH to point"
echo " to point to the directory where the version of protobufs you're using is installed."
echo ""
echo " If you don't want to use protobufs at all then you need to prevent then Nvidia DNN from building."
echo " see --no-dnn."
echo " --with-tbb: This option will build OpenCV using libtbb. It's assumed that libtbb-dev is installed."
echo " --no-contrib: Don't build the contrib modules which are build by default. The pilecv4j module lib-tracking"
echo " depends on contrib. So that module wont build if you use this option."
echo ""
echo " if GIT isn't set then the script assumes \"git\" is on the command line PATH"
echo " if MVN isn't set then the script assumes \"mvn\" is on the command line PATH"
echo " if CMAKE isn't set then the script assumes \"cmake\" is on the command line PATH"
echo " if JAVA_HOME isn't set then the script will locate the \"java\" executable on the PATH"
echo " and will attempt infer the JAVA_HOME environment variable from there."
echo ""
echo " If you set the environment variable \"VERBOSE=1\" then you will get script debugging output as well as"
echo " verbose 'make' output."
echo " To build against an externally built, non-system installed, version of Protobuf's (only needed for DNN)"
echo " you set/append to the environment variable \"CMAKE_PREFIX_PATH\" to point to the root of the Protobuf"
echo " install."
if [ $# -gt 0 ]; then
exit $1
else
exit 1
fi
}
WORKING_DIR="$DEFAULT_WORKING_DIRECTORY"
OPENCV_VERSION=
PCV4J_VERSION=
PARALLEL_BUILD=
CMAKE_GENERATOR_OPT=
SKIPC=
SKIPP=
BUILD_SHARED="-DBUILD_SHARED_LIBS=OFF -DBUILD_FAT_JAVA_LIB=ON"
BUILD_PYTHON="-DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DBUILD_opencv_python_bindings_generator=OFF"
DEPLOY_ME=
DEPLOY_ZIP=
BUILD_SAMPLES=
BUILD_CUDA=
BUILD_CUDA_DNN=
BUILD_QT=
ZIPUP=
OFFLINE=
CONTRIB_OPTION=-DOPENCV_EXTRA_MODULES_PATH=../sources/opencv_contrib/modules
CONTRIB="true"
BUILD_GST="-DWITH_GSTREAMER=OFF"
# The default is to build the DNN. This variable is set when we disable building the DNN
BUILD_DNN=-DBUILD_OPENCV_DNN=ON
# default for use is to NOT build the internal protobuf
BUILD_PROTOBUF="-DBUILD_PROTOBUF=OFF -DPROTOBUF_UPDATE_FILES=ON"
INSTALL_PREFIX=
WITH_TBB=
while [ $# -gt 0 ]; do
case "$1" in
"-w")
WORKING_DIR=$2
shift
shift
;;
"-i"|"--install-prefix")
INSTALL_PREFIX=$2
shift
shift
;;
"--opencv-version")
OPENCV_VERSION=$2
shift
shift
;;
"--version")
PCV4J_VERSION=$2
shift
shift
;;
"--zip")
ZIPUP=$2
shift
shift
;;
-j*)
PARALLEL_BUILD="$1"
shift
;;
"-G")
CMAKE_GENERATOR_OPT="-G \"$2\""
shift
shift
;;
"-sc"|"--skip-checkout")
SKIPC=true
shift
;;
"-sp"|"--skip-packaging")
SKIPP=true
shift
;;
"-static"|"--static")
shift
;;
"-no-static"|"--no-static")
# BUILD_SHARED should already be set
shift
;;
"-bp"|"--build-python"|"-bp3"|"--build-python-3")
BUILD_PYTHON="-DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=ON -DBUILD_opencv_python_bindings_generator=ON"
shift
;;
"-bp2"|"--build-python-2")
BUILD_PYTHON="-DBUILD_opencv_python2=ON -DBUILD_opencv_python3=OFF -DBUILD_opencv_python_bindings_generator=OFF"
shift
;;
"--deploy")
DEPLOY_ME="--deploy"
shift
;;
"--deploy-zip")
DEPLOY_ZIP="--deploy-zip"
shift
;;
"--offline")
OFFLINE=--offline
shift
;;
"--build-samples")
BUILD_SAMPLES="-DBUILD_EXAMPLES=ON"
shift
;;
"--build-cuda-dnn")
BUILD_CUDA_DNN=="-D OPENCV_DNN_CUDA=ON"
shift
;;
"--build-cuda-support")
# Explicity enable support for CUDA runtime, CUDA FFT support, CUDA linear algebra, and CUDA video decode.
# CUDA_NVCC_FLAG explanation: The current OpenCV compilation mode is equal to default settings of system
# compiler. It usually C++98 (gnu++98) for Ubuntu/Fedora/etc. The NVCC flag is required when building
# using C++11 (rather than OpenCV's expected C++98) but should not cause problems when building on C++98.
# This change is relevant only for CUDA 9.0 or higher but should not effect 8.X builds.
#
# Since cuda 10 opencv doesn't compile without disabling cudacodec since it's deprecated.
BUILD_CUDA="-DWITH_CUDA=ON -DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr -DWITH_CUFFT=ON -DWITH_CUBLAS=ON -DWITH_NVCUVID=ON -DBUILD_opencv_cudacodec=OFF"
shift
;;
"--build-qt-support")
BUILD_QT="-DWITH_QT=ON"
shift
;;
"--build-qt-support")
BUILD_GST=
shift
;;
"--no-dnn")
# These clash with an independent build of caffe. dnn_objdetect and text are dependent on dnn
BUILD_DNN="-DBUILD_OPENCV_DNN=OFF"
shift
;;
"--build-protobuf")
BUILD_PROTOBUF="-DBUILD_PROTOBUF=ON"
shift
;;
"--with-tbb")
WITH_TBB="-DWITH_TBB=ON"
shift
;;
"--no-contrib")
CONTRIB=
CONTRIB_OPTION=
shift
;;
"-help"|"--help"|"-h"|"-?")
usage 0
;;
*)
echo "ERROR: Unknown option \"$1\""
usage
;;
esac
done
# consistency checks
if [ "$PCV4J_VERSION" = "" ]; then
echo "ERROR: you didn't specify a version"
usage
fi
if [ "$OPENCV_VERSION" = "" ]; then
echo "ERROR: you didn't specify and opencv version"
usage
fi
if [ "$DEPLOY_ZIP" != "" -a "$ZIPUP" = "" ]; then
echo "ERROR: You specified --deploy-zip but didn't specify --zip."
usage
fi
MAJOR_VER="$(echo "$OPENCV_VERSION" | sed -e "s/\..*$//1")"
MINOR_VER="$(echo "$OPENCV_VERSION" | sed -e "s/^$MAJOR_VER\.//1" | sed -e "s/\..*$//1")"
PATCH_VER="$(echo "$OPENCV_VERSION" | sed -e "s/^$MAJOR_VER\.$MINOR_VER\.//1")"
# determine if this version is too old to build our native JNI code against.
TOO_OLD=
if [ $MIN_MAJOR_VER -gt $MAJOR_VER ]; then
TOO_OLD="true"
elif [ $MIN_MAJOR_VER -eq $MAJOR_VER -a $MIN_MINOR_VER -gt $MINOR_VER ]; then
TOO_OLD="true"
fi
if [ "$TOO_OLD" = "true" ]; then
echo "WARNING: The version you're building ($OPENCV_VERSION) is lower than the minimum version allowed ($MIN_MAJOR_VER.$MIN_MINOR_VER.x) to build the ai.kognition.pilecv4j extentions."
if [ "$SKIPP" != "true" ]; then
echo " if you want to continue bulding this version you must supply the \"-sp\" option in order to skip building the extenstion."
exit 1
fi
fi
PATCHME=
if [ "$TO_PATCH_VER" = "$OPENCV_VERSION" ]; then
PATCHME=true
fi
mkdir -p "$WORKING_DIR"
if [ ! -d "$WORKING_DIR" ]; then
echo "ERROR: \"$WORKING_DIR\" is not a valid directory."
usage
fi
if [ "$INSTALL_PREFIX" = "" ]; then
echo "ERROR: You must specify the --install-prefix option."
usage
fi
if [ -L "$INSTALL_PREFIX" ]; then
echo "ERROR: \"$INSTALL_PREFIX\" is a symbolic link. It can't be."
exit 1
fi
# ========================================
# Make the WORKING_DIR an absolute path
cd "$WORKING_DIR"
# change working directory to absolute path
WORKING_DIR="$(pwd -P)"
# ========================================
# ========================================
# set and test git command
if [ "$GIT" = "" ]; then
GIT=git
fi
set +e
"$GIT" --version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: Cannot find \"$GIT\" command"
usage
fi
set -e
# ========================================
# ========================================
# set and test git command
if [ "$CMAKE" = "" ]; then
CMAKE=cmake
fi
set +e
"$CMAKE" --version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: Cannot find \"$CMAKE\" command"
usage
fi
set -e
# ========================================
# ========================================
# set and test mvn command
if [ "$MVN" = "" ]; then
MVN=mvn
fi
set +e
"$MVN" --version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: Cannot find \"$MVN\" command"
usage
fi
set -e
# ========================================
# ========================================
# Attempt to caclulate JAVA_HOME if necessary
if [ "$JAVA_HOME" = "" ]; then
TYPE_JAVA="$(type java 2> /dev/null)"
if [ "$TYPE_JAVA" = "" ]; then
echo "ERROR: There's no java command available and JAVA_HOME isn't set."
usage
fi
# make sure 'readlink' works
if [ "$(type readlink 2>/dev/null)" = "" ]; then
echo "Can't use \"readlink\" from this shell. Either install it or explicitly set JAVA_HOME"
usage
fi
JAVA_LOCATION="/$(echo "$TYPE_JAVA" | sed -e "s/^.* \///1")"
while [ -L "$JAVA_LOCATION" ]; do
JAVA_LOCATION="$(readlink "$JAVA_LOCATION")"
done
# java should be in a "bin" directory
if [ "$(basename "$(dirname "$JAVA_LOCATION")")" = "bin" ]; then
JAVA_HOME="$(dirname "$(dirname "$JAVA_LOCATION")")"
echo "JAVA_HOME not set. It seems to be at $JAVA_HOME so I'm going with that."
echo "JAVA_HOME :$JAVA_HOME"
else
echo "Can't automatically locate the correct JAVA_HOME. Please set it explicitly."
usage
fi
fi
export JAVA_HOME
# ========================================
# figure out the deploy version
# calculate the version
# find the cuda version
CUDA_VERSION=
if [ "$BUILD_CUDA" != "" ]; then
if [ -f /usr/local/cuda/version.txt ]; then
CUDA_VERSION="$(cat /usr/local/cuda/version.txt | sgrep -i cuda | sgrep -i version | tail -1 | sed -e "s/^.*[Vv]ersion //1" | segrep -o -e "^[0-9][0-9]*[0-9]*\.[0-9][0-9]*[0-9]*[0-9]*")"
else
NVCC_EXE=
if [ "$(type nvcc 2>&1 | sgrep "not found")" != "" -a -x /usr/local/cuda/bin/nvcc ]; then
NVCC_EXE=/usr/local/cuda/bin/nvcc
else
NVCC_EXE=nvcc
fi
if [ "$NVCC_EXE" != "" ]; then
CUDA_VERSION="$($NVCC_EXE --version | segrep -e ", V[0-9][0-9]*[0-9]*[0-9]*\." | sed -e "s/^.*, V//1" | sed -E "s/\.[0-9][0-9]*[0-9]*[0-9]*[0-9]*[0-9]*[0-9]*$//1")"
else
echo "WARNING: Can't calculate the cuda version."
fi
fi
CUDA_VERSION="-cuda$CUDA_VERSION"
fi
DEPLOY_VERSION="$PCV4J_VERSION-opencv$OPENCV_VERSION$CUDA_VERSION"
#=========================================
# Comment out the actual build by including the next line
#if [ "Yo" = "" ]; then
#=========================================
# ========================================
# Checkout everything and switch to the correct tag
# remove these even if we're skipping the checkout
if [ -d "$WORKING_DIR/build" ]; then
rm -rf "$WORKING_DIR/build"/* 2>/dev/null
fi
if [ -f "$WORKING_DIR/cmake.out" ]; then
rm -rf "$WORKING_DIR/cmake.out"
fi
if [ -d "$WORKING_DIR/installed" ]; then
rm -rf "$WORKING_DIR/installed"/* 2>/dev/null
fi
if [ "$SKIPC" != "true" ]; then
# remove ONLY the expected generated files if they exist
if [ -d "$WORKING_DIR/sources" ]; then
rm -rf "$WORKING_DIR/sources"/* 2>/dev/null
fi
mkdir -p sources
mkdir -p build
cd sources
"$GIT" clone https://github.com/opencv/opencv.git
cd opencv
"$GIT" checkout "$OPENCV_VERSION"
if [ "$PATCHME" = "true" ]; then
echo "Applying patch for building a FAT jar."
# if it's not too old then apply the patch to build a fat jar
git cherry-pick f3dde79ed6f5e17f16f4e2ad9669841e0dd6887c
fi
cd ..
if [ "$CONTRIB" = "true" ]; then
"$GIT" clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
"$GIT" checkout "$OPENCV_VERSION"
cd ..
fi
else
# we're still going to clean up the build directory
mkdir -p "$WORKING_DIR"/build
fi
# ========================================
cd "$WORKING_DIR"/build
# Make sure cmake.out is removed because we need to grep it assuming it was empty/non-existent at the beginning of the run
if [ -f "$WORKING_DIR/cmake.out" ]; then
set +e
rm "$WORKING_DIR/cmake.out" 2>/dev/null
if [ $? -ne 0 ]; then
echo "Couldn't remove \"$WORKING_DIR/cmake.out\" from a previous run. Can't continue."
exit 1
fi
if [ -f "$WORKING_DIR/cmake.out" ]; then
echo "Couldn't remove \"$WORKING_DIR/cmake.out\" from a previous run. Can't continue."
exit 1
fi
set -e
fi
echo "JAVA_HOME: \"$JAVA_HOME\"" | tee "$WORKING_DIR/cmake.out"
if [ "$CMAKE_PREFIX_PATH" != "" ]; then
echo "CMAKE_PREFIX_PATH is set to \"$CMAKE_PREFIX_PATH\"" | tee -a "$WORKING_DIR/cmake.out"
fi
BUILD_CMD=$(echo "\"$CMAKE\" $CMAKE_GENERATOR_OPT -DCMAKE_BUILD_TYPE=Release $BUILD_GST -DOPENCV_ENABLE_NONFREE:BOOL=ON -DCMAKE_INSTALL_PREFIX=\"$(cwpath "$INSTALL_PREFIX")\" $CONTRIB_OPTION $BUILD_SHARED $BUILD_PYTHON $BUILD_SAMPLES $BUILD_CUDA $BUILD_CUDA_DNN $BUILD_QT $BUILD_DNN $BUILD_PROTOBUF $WITH_TBB -DENABLE_PRECOMPILED_HEADERS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DOPENCV_SKIP_VISIBILITY_HIDDEN=ON $OS_SPECIFIC_CMAKE_OPTIONS $CMAKE_ARCH ../sources/opencv")
echo "$BUILD_CMD" | tee -a "$WORKING_DIR/cmake.out"
eval "$BUILD_CMD" | tee -a "$WORKING_DIR/cmake.out"
# check cmake.out for the java wrappers
if [ "$(sgrep -A4 -- '-- Java:' "$WORKING_DIR/cmake.out" | sgrep -- '-- Java wrappers:' | sgrep YES)" = "" ]; then
echo "ERROR: It appears that the JNI wrappers wont build in this configuration."
echo " Some common reasons include:"
echo " 1) Ant isn't installed or on the path"
echo " 2) The cmake build cannot find python."
echo " Note: on Windows when using the Windows CMake (as opposed to the mingw cmake) \"ant\" needs to be on the Windows PATH"
exit 1
fi
# Get the make command from the cmake output
MAKE="$(cpath "$(sgrep -- '-- CMake build tool:' "$WORKING_DIR/cmake.out" | sed -e "s/^.*CMake build tool: *//g")")"
if [ "$(echo "$MAKE" | sgrep -i msbuild)" != "" ]; then
# We're on windows using Visual Studio
INSTALL_TARGET=INSTALL.vcxproj
RELEASE="-p:Configuration=Release"
if [ "$PARALLEL_BUILD" != "" ]; then
PARALLEL_BUILD="-m"
fi
else
# otherwise we're running MAKE
INSTALL_TARGET=install
RELEASE=
fi
echo "Building using:" | tee -a "$WORKING_DIR/cmake.out"
echo "\"$MAKE\" $PARALLEL_BUILD $INSTALL_TARGET $RELEASE" | tee -a "$WORKING_DIR/cmake.out"
"$MAKE" $PARALLEL_BUILD $INSTALL_TARGET $RELEASE
# HACK to repair incorrectly generate protobuf dependency
OCV_CMAKE_CONFIG=`find "$INSTALL_PREFIX" -name "OpenCVModules.cmake"`
DO_REPLACE_PROTOBUF_LINK=true
if [ "$OCV_CMAKE_CONFIG" = "" ]; then
echo "WARNING: Cannot find the OpenCVModules.cmake so I cannot correct potential downstream Protobuf link dependency."
DO_REPLACE_PROTOBUF_LINK=
fi
if [ $(echo "$OCV_CMAKE_CONFIG" | wc -l) -ne 1 ]; then
echo "WARNING: There seeme to be more than one OpenCVModules.cmake in the install directory \"$INSTALL_PREFIX\""
DO_REPLACE_PROTOBUF_LINK=
fi
if [ "$DO_REPLACE_PROTOBUF_LINK" = "true" ]; then
cp "$OCV_CMAKE_CONFIG" /tmp
cat /tmp/"$(basename "$OCV_CMAKE_CONFIG")" | sed -e "s/<LINK_ONLY:libprotobuf>/<LINK_ONLY:protobuf>/g" > "$OCV_CMAKE_CONFIG"
rm /tmp/"$(basename "$OCV_CMAKE_CONFIG")"
fi
# if we're on linux, and execstack is installed, then we want to fixup the opencv_${shortversion} library
if [ "Linux" = "$PLAT" ]; then
set +e
type execstack
if [ $? -eq 0 ]; then
JAVA_SHARED_LIB=`find "$INSTALL_PREFIX" -name "libopencv_java*.so" | head -1`
if [ -f "$JAVA_SHARED_LIB" ]; then
echo "Applying buffer overrun protection to \"$JAVA_SHARED_LIB\""
execstack -s "$JAVA_SHARED_LIB"
else
echo "WARN: I should have been able to apply buffer overrun protection to the shared lib \"$JAVA_SHARED_LIB\" but I couldn't find it."
fi
else
echo "NOT applying overrun protection. You should install 'execstack' using 'sudo apt-get install execstack'. Continuing..."
fi
set -e
fi
# copy the cmake details into the install dir for potential later reference.
cp "$WORKING_DIR/cmake.out" "$INSTALL_PREFIX"
#=========================================
# Comment out the actual build by including the next line
#fi
#=========================================
cd "$PROJDIR"
if [ "$SKIPP" != "true" ]; then
echo "PACKAGING COMMAND:"
if [ "$ZIPUP" != "" ]; then
if [ "$DEPLOY_ZIP" != "" ]; then
echo "OPENCV_INSTALL=\"$INSTALL_PREFIX\" ./package.sh $OFFLINE --version \"$DEPLOY_VERSION\" $DEPLOY_ME --zip \"$ZIPUP\" \"$DEPLOY_ZIP\""
OPENCV_INSTALL="$INSTALL_PREFIX" ./package.sh $OFFLINE --version "$DEPLOY_VERSION" $DEPLOY_ME --zip "$ZIPUP" "$DEPLOY_ZIP"
else
echo "OPENCV_INSTALL=\"$INSTALL_PREFIX\" ./package.sh $OFFLINE --version \"$DEPLOY_VERSION\" $DEPLOY_ME --zip \"$ZIPUP\""
OPENCV_INSTALL="$INSTALL_PREFIX" ./package.sh $OFFLINE --version "$DEPLOY_VERSION" $DEPLOY_ME --zip "$ZIPUP"
fi
else
echo "OPENCV_INSTALL=\"$INSTALL_PREFIX\" ./package.sh $OFFLINE --version \"$DEPLOY_VERSION\" $DEPLOY_ME"
OPENCV_INSTALL="$INSTALL_PREFIX" ./package.sh $OFFLINE --version "$DEPLOY_VERSION" $DEPLOY_ME
fi
fi