Skip to content

Commit a5a421a

Browse files
authored
Merge pull request opencv#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/<host-tag>/...`, including `libz.so`. Also installed to old paths (`<NDK>/platforms` and `<NDK>/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
1 parent 743099f commit a5a421a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cmake/OpenCVFindLibsGrfmt.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ if(BUILD_ZLIB)
77
ocv_clear_vars(ZLIB_FOUND)
88
else()
99
ocv_clear_internal_cache_vars(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
10+
if(ANDROID)
11+
set(_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
12+
set(CMAKE_FIND_LIBRARY_SUFFIXES .so)
13+
endif()
1014
find_package(ZLIB "${MIN_VER_ZLIB}")
15+
if(ANDROID)
16+
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
17+
unset(_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
18+
endif()
1119
if(ZLIB_FOUND AND ANDROID)
12-
if(ZLIB_LIBRARIES MATCHES "/usr/(lib|lib32|lib64)/libz.so$")
20+
if(ZLIB_LIBRARIES MATCHES "/usr/lib.*/libz.so$")
1321
set(ZLIB_LIBRARIES z)
1422
endif()
1523
endif()

0 commit comments

Comments
 (0)