diff --git a/3rdparty/libtiff/CMakeLists.txt b/3rdparty/libtiff/CMakeLists.txt index ae9914b3e8..73717e20c0 100644 --- a/3rdparty/libtiff/CMakeLists.txt +++ b/3rdparty/libtiff/CMakeLists.txt @@ -244,10 +244,14 @@ mark_as_advanced(HAVE_IEEEFP) # Large file support if(UNIX OR MINGW) - # This might not catch every possibility catered for by - # AC_SYS_LARGEFILE. - add_definitions(-D_FILE_OFFSET_BITS=64) - set(FILE_OFFSET_BITS 64) + if(ANDROID AND (ANDROID_NATIVE_API_LEVEL LESS 21) AND (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES Clang)) + # Android NDK build problem: 'mmap' issue with GCC and API<21 + else() + # This might not catch every possibility catered for by + # AC_SYS_LARGEFILE. + add_definitions(-D_FILE_OFFSET_BITS=64) + set(FILE_OFFSET_BITS 64) + endif() endif() # Documentation install directory (default to cmake project docdir) diff --git a/3rdparty/libtiff/tif_config.h.cmake.in b/3rdparty/libtiff/tif_config.h.cmake.in index de0f3a3c2c..492636ec92 100644 --- a/3rdparty/libtiff/tif_config.h.cmake.in +++ b/3rdparty/libtiff/tif_config.h.cmake.in @@ -245,9 +245,6 @@ # endif #endif -/* Number of bits in a file offset, on hosts where this is settable. */ -#define _FILE_OFFSET_BITS @FILE_OFFSET_BITS@ - /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ #ifndef __cplusplus diff --git a/3rdparty/protobuf/src/google/protobuf/util/field_mask_util.cc b/3rdparty/protobuf/src/google/protobuf/util/field_mask_util.cc index 9dfcbd726b..62b29a87fe 100644 --- a/3rdparty/protobuf/src/google/protobuf/util/field_mask_util.cc +++ b/3rdparty/protobuf/src/google/protobuf/util/field_mask_util.cc @@ -216,14 +216,14 @@ class FieldMaskTree { ~Node() { ClearChildren(); } void ClearChildren() { - for (map::iterator it = children.begin(); + for (std::map::iterator it = children.begin(); it != children.end(); ++it) { delete it->second; } children.clear(); } - map children; + std::map children; private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Node); @@ -274,7 +274,7 @@ void FieldMaskTree::MergeToFieldMask(const string& prefix, const Node* node, out->add_paths(prefix); return; } - for (map::const_iterator it = node->children.begin(); + for (std::map::const_iterator it = node->children.begin(); it != node->children.end(); ++it) { string current_path = prefix.empty() ? it->first : prefix + "." + it->first; MergeToFieldMask(current_path, it->second, out); @@ -339,7 +339,7 @@ void FieldMaskTree::MergeLeafNodesToTree(const string& prefix, const Node* node, if (node->children.empty()) { out->AddPath(prefix); } - for (map::const_iterator it = node->children.begin(); + for (std::map::const_iterator it = node->children.begin(); it != node->children.end(); ++it) { string current_path = prefix.empty() ? it->first : prefix + "." + it->first; MergeLeafNodesToTree(current_path, it->second, out); @@ -353,7 +353,7 @@ void FieldMaskTree::MergeMessage(const Node* node, const Message& source, const Reflection* source_reflection = source.GetReflection(); const Reflection* destination_reflection = destination->GetReflection(); const Descriptor* descriptor = source.GetDescriptor(); - for (map::const_iterator it = node->children.begin(); + for (std::map::const_iterator it = node->children.begin(); it != node->children.end(); ++it) { const string& field_name = it->first; const Node* child = it->second; @@ -456,7 +456,7 @@ void FieldMaskTree::TrimMessage(const Node* node, Message* message) { const int32 field_count = descriptor->field_count(); for (int index = 0; index < field_count; ++index) { const FieldDescriptor* field = descriptor->field(index); - map::const_iterator it = node->children.find(field->name()); + std::map::const_iterator it = node->children.find(field->name()); if (it == node->children.end()) { reflection->ClearField(message, field); } else { diff --git a/3rdparty/protobuf/src/google/protobuf/util/internal/type_info.cc b/3rdparty/protobuf/src/google/protobuf/util/internal/type_info.cc index 00a8ee7a2a..8201ea629a 100644 --- a/3rdparty/protobuf/src/google/protobuf/util/internal/type_info.cc +++ b/3rdparty/protobuf/src/google/protobuf/util/internal/type_info.cc @@ -60,7 +60,7 @@ class TypeInfoForTypeResolver : public TypeInfo { virtual util::StatusOr ResolveTypeUrl( StringPiece type_url) const { - map::iterator it = cached_types_.find(type_url); + std::map::iterator it = cached_types_.find(type_url); if (it != cached_types_.end()) { return it->second; } @@ -85,7 +85,7 @@ class TypeInfoForTypeResolver : public TypeInfo { virtual const google::protobuf::Enum* GetEnumByTypeUrl( StringPiece type_url) const { - map::iterator it = cached_enums_.find(type_url); + std::map::iterator it = cached_enums_.find(type_url); if (it != cached_enums_.end()) { return it->second.ok() ? it->second.ValueOrDie() : NULL; } @@ -123,8 +123,8 @@ class TypeInfoForTypeResolver : public TypeInfo { typedef util::StatusOr StatusOrEnum; template - static void DeleteCachedTypes(map* cached_types) { - for (typename map::iterator it = cached_types->begin(); + static void DeleteCachedTypes(std::map* cached_types) { + for (typename std::map::iterator it = cached_types->begin(); it != cached_types->end(); ++it) { if (it->second.ok()) { delete it->second.ValueOrDie(); @@ -153,11 +153,11 @@ class TypeInfoForTypeResolver : public TypeInfo { // cached_types_, cached_enums_ and camel_case_name_table_. mutable set string_storage_; - mutable map cached_types_; - mutable map cached_enums_; + mutable std::map cached_types_; + mutable std::map cached_enums_; mutable set indexed_types_; - mutable map camel_case_name_table_; + mutable std::map camel_case_name_table_; }; } // namespace diff --git a/3rdparty/protobuf/src/google/protobuf/util/message_differencer.cc b/3rdparty/protobuf/src/google/protobuf/util/message_differencer.cc index 03a334b6e8..62423be145 100644 --- a/3rdparty/protobuf/src/google/protobuf/util/message_differencer.cc +++ b/3rdparty/protobuf/src/google/protobuf/util/message_differencer.cc @@ -1284,7 +1284,7 @@ class MaximumMatcher { int count1_; int count2_; google::protobuf::scoped_ptr match_callback_; - map, bool> cached_match_results_; + std::map, bool> cached_match_results_; vector* match_list1_; vector* match_list2_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MaximumMatcher); @@ -1322,7 +1322,7 @@ int MaximumMatcher::FindMaximumMatch(bool early_return) { bool MaximumMatcher::Match(int left, int right) { pair p(left, right); - map, bool>::iterator it = cached_match_results_.find(p); + std::map, bool>::iterator it = cached_match_results_.find(p); if (it != cached_match_results_.end()) { return it->second; } diff --git a/cmake/OpenCVDetectCXXCompiler.cmake b/cmake/OpenCVDetectCXXCompiler.cmake index 7ca813e0c9..9f3f4c0dbe 100644 --- a/cmake/OpenCVDetectCXXCompiler.cmake +++ b/cmake/OpenCVDetectCXXCompiler.cmake @@ -13,7 +13,7 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Clang") set(CMAKE_COMPILER_IS_GNUCC 1) set(CMAKE_COMPILER_IS_CLANGCC 1) endif() -if("${CMAKE_CXX_COMPILER};${CMAKE_C_COMPILER}" MATCHES "ccache") +if("${CMAKE_CXX_COMPILER};${CMAKE_C_COMPILER};${CMAKE_CXX_COMPILER_LAUNCHER}" MATCHES "ccache") set(CMAKE_COMPILER_IS_CCACHE 1) endif() diff --git a/cmake/OpenCVFindLibsGrfmt.cmake b/cmake/OpenCVFindLibsGrfmt.cmake index 0ae58c89f4..ab1dcd92c5 100644 --- a/cmake/OpenCVFindLibsGrfmt.cmake +++ b/cmake/OpenCVFindLibsGrfmt.cmake @@ -8,8 +8,7 @@ if(BUILD_ZLIB) else() find_package(ZLIB "${MIN_VER_ZLIB}") if(ZLIB_FOUND AND ANDROID) - if(ZLIB_LIBRARIES STREQUAL "${ANDROID_SYSROOT}/usr/lib/libz.so" OR - ZLIB_LIBRARIES STREQUAL "${ANDROID_SYSROOT}/usr/lib64/libz.so") + if(ZLIB_LIBRARIES MATCHES "/usr/(lib|lib32|lib64)/libz.so$") set(ZLIB_LIBRARIES z) endif() endif() diff --git a/cmake/OpenCVFindLibsPerf.cmake b/cmake/OpenCVFindLibsPerf.cmake index 76d1d83bb5..5fba24c30b 100644 --- a/cmake/OpenCVFindLibsPerf.cmake +++ b/cmake/OpenCVFindLibsPerf.cmake @@ -18,6 +18,13 @@ if(WITH_IPP) endif() ocv_include_directories(${IPP_INCLUDE_DIRS}) list(APPEND OPENCV_LINKER_LIBS ${IPP_LIBRARIES}) + + # Details: #10229 + if(ANDROID AND NOT OPENCV_SKIP_ANDROID_IPP_FIX_1) + set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a ${CMAKE_SHARED_LINKER_FLAGS}") + elseif(ANDROID AND NOT OPENCV_SKIP_ANDROID_IPP_FIX_2) + set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bsymbolic ${CMAKE_SHARED_LINKER_FLAGS}") + endif() endif() endif() diff --git a/cmake/templates/OpenCV.mk.in b/cmake/templates/OpenCV.mk.in index addde3a268..207cd0fd62 100644 --- a/cmake/templates/OpenCV.mk.in +++ b/cmake/templates/OpenCV.mk.in @@ -88,6 +88,16 @@ LOCAL_STATIC_LIBRARIES:=$(USER_LOCAL_STATIC_LIBRARIES) LOCAL_SHARED_LIBRARIES:=$(USER_LOCAL_SHARED_LIBRARIES) LOCAL_LDLIBS:=$(USER_LOCAL_LDLIBS) +# Details: #10229 +ifeq ($(OPENCV_SKIP_ANDROID_IPP_FIX_1),) + LOCAL_LDFLAGS += -Wl,--exclude-libs,libippicv.a + LOCAL_LDFLAGS += -Wl,--exclude-libs,libippiw.a +else + ifeq ($(OPENCV_SKIP_ANDROID_IPP_FIX_2),) + LOCAL_LDFLAGS += -Wl,-Bsymbolic + endif +endif + LOCAL_C_INCLUDES += $(OPENCV_LOCAL_C_INCLUDES) LOCAL_CFLAGS += $(OPENCV_LOCAL_CFLAGS) diff --git a/platforms/android/android.toolchain.cmake b/platforms/android/android.toolchain.cmake index 6d64f92148..e566301d81 100644 --- a/platforms/android/android.toolchain.cmake +++ b/platforms/android/android.toolchain.cmake @@ -312,9 +312,16 @@ macro( __DETECT_NATIVE_API_LEVEL _var _path ) set( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*.*$" ) file( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" ) if( NOT __apiFileContent ) - message( SEND_ERROR "Could not get Android native API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." ) + set( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+__ANDROID_API_FUTURE__[\t ]*$" ) + file( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" ) + if( __apiFileContent ) + set(${_var} 10000) + else() + message( SEND_ERROR "Could not get Android native API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." ) + endif() + else() + string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" ) endif() - string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" ) unset( __apiFileContent ) unset( __ndkApiLevelRegex ) endmacro() @@ -810,10 +817,15 @@ unset(__real_api_level) # validate list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx ) if( __levelIdx EQUAL -1 ) - message( SEND_ERROR "Specified Android native API level 'android-${ANDROID_NATIVE_API_LEVEL}' is not supported by your NDK/toolchain." ) + message( SEND_ERROR "Specified Android native API level 'android-${ANDROID_NATIVE_API_LEVEL}' is not supported by your NDK/toolchain.\nSupported values of ANDROID_NATIVE_API_LEVEL: ${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" ) else() if( BUILD_WITH_ANDROID_NDK ) - __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) + if(EXISTS "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h") + __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) + else() + __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/sysroot/usr/include/android/api-level.h") + endif() + if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL AND NOT __realApiLevel GREATER 9000 ) message( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." ) endif() @@ -914,6 +926,7 @@ if( BUILD_WITH_STANDALONE_TOOLCHAIN ) set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) + set( ANDROID_SYSROOT_INCLUDE "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include" ) if( NOT ANDROID_STL STREQUAL "none" ) set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/include/c++/${ANDROID_COMPILER_VERSION}" ) @@ -991,6 +1004,11 @@ endif() if( BUILD_WITH_ANDROID_NDK ) set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" ) + if( EXISTS "${ANDROID_SYSROOT}/usr/include" ) + set( ANDROID_SYSROOT_INCLUDE "${ANDROID_SYSROOT}/usr/include" ) + else() + set( ANDROID_SYSROOT_INCLUDE "${ANDROID_NDK}/sysroot/usr/include" "${ANDROID_NDK}/sysroot/usr/include/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) + endif() if( ANDROID_STL STREQUAL "none" ) # do nothing @@ -1480,7 +1498,7 @@ if( DEFINED ANDROID_RTTI AND ANDROID_STL_FORCE_FEATURES ) endif() endif() -# configure exceptios +# configure exceptions if( DEFINED ANDROID_EXCEPTIONS AND ANDROID_STL_FORCE_FEATURES ) if( ANDROID_EXCEPTIONS ) set( CMAKE_CXX_FLAGS "-fexceptions ${CMAKE_CXX_FLAGS}" ) @@ -1492,9 +1510,11 @@ if( DEFINED ANDROID_EXCEPTIONS AND ANDROID_STL_FORCE_FEATURES ) endif() # global includes and link directories -include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_STL_INCLUDE_DIRS} ) +include_directories( SYSTEM "${ANDROID_SYSROOT_INCLUDE}" ${ANDROID_STL_INCLUDE_DIRS} ) get_filename_component(__android_install_path "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ABSOLUTE) # avoid CMP0015 policy warning link_directories( "${__android_install_path}" ) +set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DANDROID -D__ANDROID_API__=${ANDROID_NATIVE_API_LEVEL}" ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DANDROID -D__ANDROID_API__=${ANDROID_NATIVE_API_LEVEL}" ) # detect if need link crtbegin_so.o explicitly if( NOT DEFINED ANDROID_EXPLICIT_CRT_LINK ) @@ -1567,19 +1587,58 @@ set( ANDROID True ) set( BUILD_ANDROID True ) # where is the target environment -set( CMAKE_FIND_ROOT_PATH "${ANDROID_TOOLCHAIN_ROOT}/bin" "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" "${ANDROID_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" ) +set( CMAKE_FIND_ROOT_PATH + "${ANDROID_TOOLCHAIN_ROOT}/bin" + "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" + "${ANDROID_SYSROOT}" + "${ANDROID_NDK}/sysroot" # NDK16+ + "${CMAKE_INSTALL_PREFIX}" + "${CMAKE_INSTALL_PREFIX}/share" ) # only search for libraries and includes in the ndk toolchain -set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) -set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) -set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) +if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) +endif() +if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) +endif() + +if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) + set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY ) +endif() + +if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) +endif() + +macro(__cmake_find_root_save_and_reset) + foreach(v + CMAKE_FIND_ROOT_PATH_MODE_LIBRARY + CMAKE_FIND_ROOT_PATH_MODE_INCLUDE + CMAKE_FIND_ROOT_PATH_MODE_PACKAGE + CMAKE_FIND_ROOT_PATH_MODE_PROGRAM + ) + set(__save_${v} ${${v}}) + set(${v} NEVER) + endforeach() +endmacro() + +macro(__cmake_find_root_restore) + foreach(v + CMAKE_FIND_ROOT_PATH_MODE_LIBRARY + CMAKE_FIND_ROOT_PATH_MODE_INCLUDE + CMAKE_FIND_ROOT_PATH_MODE_PACKAGE + CMAKE_FIND_ROOT_PATH_MODE_PROGRAM + ) + set(${v} ${__save_${v}}) + unset(__save_${v}) + endforeach() +endmacro() # macro to find packages on the host OS macro( find_host_package ) - set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) - set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) - set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) + __cmake_find_root_save_and_reset() if( CMAKE_HOST_WIN32 ) SET( WIN32 1 ) SET( UNIX ) @@ -1591,17 +1650,13 @@ macro( find_host_package ) SET( WIN32 ) SET( APPLE ) SET( UNIX 1 ) - set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) - set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) - set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + __cmake_find_root_restore() endmacro() # macro to find programs on the host OS macro( find_host_program ) - set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) - set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) - set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) + __cmake_find_root_save_and_reset() if( CMAKE_HOST_WIN32 ) SET( WIN32 1 ) SET( UNIX ) @@ -1613,9 +1668,7 @@ macro( find_host_program ) SET( WIN32 ) SET( APPLE ) SET( UNIX 1 ) - set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) - set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) - set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + __cmake_find_root_restore() endmacro() @@ -1713,6 +1766,7 @@ endif() # ANDROID_NDK_RELEASE_NUM : numeric ANDROID_NDK_RELEASE version (1000*major+minor) # ANDROID_ARCH_NAME : "arm", "x86", "mips", "arm64", "x86_64", "mips64" depending on ANDROID_ABI # ANDROID_SYSROOT : path to the compiler sysroot +# ANDROID_SYSROOT_INCLUDE : paths to system include paths # TOOL_OS_SUFFIX : "" or ".exe" depending on host platform # ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used #