From: Zhuo Zhang Date: Sun, 14 Feb 2021 18:38:53 +0000 (+0800) Subject: Merge pull request #19522 from zchrissirhcz:3.4-fix-android-find-zlib-shared-since... X-Git-Tag: submit/tizen/20220120.021815~1^2~1^2~163 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a5a421a9f16763731255d9cd0d41b6d33db17f6d;p=platform%2Fupstream%2Fopencv.git Merge pull request #19522 from zchrissirhcz:3.4-fix-android-find-zlib-shared-since-ndk19 * fix find zlib.so instead of zlib.a when NDK >= 19 On Android platform, `libopencv_imgcodecs.a` is built, expected to depend on `libz.so`. However, since Android NDK r19, NDK's `libz.a` is found instead of `libz.so`, leading to link error (not found libz.a) on machines without same NDK version & direcotry. Since Android NDK-r19, toolchain pieces are installed to `$NDK/toolchains/llvm/prebuilt//...`, including `libz.so`. Also installed to old paths (`/platforms` and `/sysroot`) in NDK r19, r20, r21, but since NDK 22, old paths are removed. - https://github.com/android/ndk/wiki/Changelog-r19 - https://github.com/android/ndk/wiki/Changelog-r22 With this commit, `libz.so` can be correctly found in NDK<19 and NDK>=19. `ZLIB_LIBRARIES` is also simplified as `z`, by appending match (regex) patterns for new toolchain installation directory's libz.so's paths. * simplify libz.so match pattern for abbreviation --- diff --git a/cmake/OpenCVFindLibsGrfmt.cmake b/cmake/OpenCVFindLibsGrfmt.cmake index f99bb33c80..2d28dff875 100644 --- a/cmake/OpenCVFindLibsGrfmt.cmake +++ b/cmake/OpenCVFindLibsGrfmt.cmake @@ -7,9 +7,17 @@ if(BUILD_ZLIB) ocv_clear_vars(ZLIB_FOUND) else() ocv_clear_internal_cache_vars(ZLIB_LIBRARY ZLIB_INCLUDE_DIR) + if(ANDROID) + set(_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + set(CMAKE_FIND_LIBRARY_SUFFIXES .so) + endif() find_package(ZLIB "${MIN_VER_ZLIB}") + if(ANDROID) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) + unset(_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) + endif() if(ZLIB_FOUND AND ANDROID) - if(ZLIB_LIBRARIES MATCHES "/usr/(lib|lib32|lib64)/libz.so$") + if(ZLIB_LIBRARIES MATCHES "/usr/lib.*/libz.so$") set(ZLIB_LIBRARIES z) endif() endif()