From 65ac0faf01b9b5448b4242eb8bb3af296bbabc0d Mon Sep 17 00:00:00 2001 From: n-kai-cj <33518812+n-kai-cj@users.noreply.github.com> Date: Thu, 24 Dec 2020 11:53:30 +0900 Subject: [PATCH] * Build OpenCV without OpenBLAS when environment variable `NOOPENBLAS=yes` (pull #987) --- CHANGELOG.md | 1 + opencv/cppbuild.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19a75aebd53..7f413f4421d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ + * Build OpenCV without OpenBLAS when environment variable `NOOPENBLAS=yes` ([pull #987](https://github.com/bytedeco/javacpp-presets/pull/987)) * Enable OpenCL acceleration for DNNL ([issue #938](https://github.com/bytedeco/javacpp-presets/issues/938)) * Introduce monkey patching when loading presets for CPython to relocate home more reliably * Add display sample for librealsense2 ([pull #978](https://github.com/bytedeco/javacpp-presets/pull/978)) diff --git a/opencv/cppbuild.sh b/opencv/cppbuild.sh index 657855ab80a..0cf3f99ec66 100755 --- a/opencv/cppbuild.sh +++ b/opencv/cppbuild.sh @@ -125,6 +125,73 @@ if [[ "$EXTENSION" == *gpu ]]; then GPU_FLAGS="-DWITH_CUDA=ON -DWITH_CUDNN=ON -DOPENCV_DNN_CUDA=ON -DCUDA_VERSION=11.0 -DCUDNN_VERSION=8.0 -DCUDA_ARCH_BIN='3.5' -DCUDA_ARCH_PTX='3.5' -DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr -DCUDA_nppicom_LIBRARY=" fi +# exclude openblas dependencies +if [[ "${NOOPENBLAS:-no}" == "yes" ]]; then + # arguments: + function del_keyword_line { + fname=$1 + ex_word=$2 + ln=`grep -n $ex_word $fname | sed -n -e 's/:.*//gp'` + cnt=0 + for l in $ln; do + sedinplace "`expr ${l} - ${cnt}`d" $fname + cnt=`expr ${cnt} + 1` + done + } + + # arguments: + function del_keyword_tags { + fname=$1 + ex_word=$2 + ex_start_tag="<$3>" + ex_end_tag="" + ln=`grep -n $ex_word $fname | sed -n -e 's/:.*//gp'` + cnt=0 + for l in $ln; do + ls=`expr ${l} - ${cnt}` + srl=`head -n ${ls} $fname | tac | grep -n $ex_start_tag | sed -e 's/:.*//gp' | head -n 1` + erl=`sed -n "${ls},\\$p" $fname | grep -n $ex_end_tag | sed -e 's/:.*//gp' | head -n 1` + if [ ! "${srl:+srl}" -o ! "${erl:+erl}" ]; then continue; fi + start_line=`expr ${ls} - $srl + 1` + end_line=`expr ${ls} + $erl - 1` + cnt=`expr $cnt + ${end_line} - ${start_line}` + sedinplace "${start_line},${end_line}d" $fname + done + } + + # arguments: + function add_line_after_keyword { + fname=$1 + key1=$2 + key2=$3 + add_line=$4 + add_tag_line_num=`grep -n "${key1}" $fname | sed -n -e 's/:.*//gp' | head -n 1` + add_line_num=`sed -n "${add_tag_line_num},\\$p" $fname | grep -n "${key2}" | sed -e 's/:.*//gp' | head -n 1` + l=`expr ${add_tag_line_num} + ${add_line_num}` + sedinplace "${l}i ${add_line}" $fname + } + + echo "Exclude OpenBLAS dependencies" + cd ../../../ + ex_word=openblas + ex_tag=dependency + for ex_file in {pom.xml,platform/pom.xml,platform/gpu/pom.xml}; do + del_keyword_tags $ex_file $ex_word $ex_tag + done + ex_file=pom.xml + ex_tag=properties + del_keyword_tags $ex_file $ex_word $ex_tag + del_keyword_line $ex_file $ex_word + add_line_after_keyword $ex_file "package" "" "\${javacpp.platform}\${javacpp.platform.extension}-noopenblas<\/classifier>" + add_line_after_keyword $ex_file "org.moditect" "moditect-maven-plugin" "add-module-infos<\/id>\${project.build.directory}\/\${project.artifactId}-\${javacpp.platform}\${javacpp.platform.extension}-noopenblas.jar<\/file><\/module><\/modules><\/configuration><\/execution><\/executions>" + ex_file=src/main/java/org/bytedeco/opencv/presets/opencv_core.java + sedinplace 's/\"openblas_config.h\", \"cblas.h\",\ //' $ex_file + for run in {1..2}; do del_keyword_line $ex_file $ex_word; done + ex_file=src/main/java9/module-info.java + del_keyword_line $ex_file $ex_word + cd cppbuild/"$PLATFORM$EXTENSION"/opencv-$OPENCV_VERSION +fi + case $PLATFORM in android-arm) $CMAKE -DCMAKE_TOOLCHAIN_FILE=platforms/android/android.toolchain.cmake -DANDROID_ABI=armeabi-v7a -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DANDROID_STL=c++_static -DANDROID_NATIVE_API_LEVEL=21 -DCMAKE_C_FLAGS="$ANDROID_FLAGS" -DCMAKE_CXX_FLAGS="$ANDROID_FLAGS" -DCMAKE_INSTALL_PREFIX="$INSTALL_PATH" -DCMAKE_INSTALL_LIBDIR="lib" -DBUILD_SHARED_LIBS=ON $BUILD_X -DENABLE_PRECOMPILED_HEADERS=OFF $WITH_X $GPU_FLAGS $BUILD_CONTRIB_X .