diff --git a/3rdparty/cpufeatures/CMakeLists.txt b/3rdparty/cpufeatures/CMakeLists.txt index 327f2348b678bdaef4ccf0251eb76f53868a8f5d..cdb7c34f7f00df6e7c1e9795e3bbd030d24e8fc5 100644 --- a/3rdparty/cpufeatures/CMakeLists.txt +++ b/3rdparty/cpufeatures/CMakeLists.txt @@ -1,15 +1,18 @@ +if(NOT ANDROID) + message("cpufeatures is ANDROID project") +endif() -ocv_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -file(GLOB cpuf_s *.c) -file(GLOB cpuf_h *.h) +set(CPUFEATURES_ROOT "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "Android cpufeatures project sources (for example, /sources/android/cpufeatures)") -set(lib_srcs ${cpuf_s}) -set(lib_hdrs ${cpuf_h}) +set(CPUFEATURES_INCLUDE_DIRS ${CPUFEATURES_ROOT} CACHE INTERNAL "") +set(CPUFEATURES_LIBRARIES cpufeatures CACHE INTERNAL "") -set(CPUFEATURES_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "") -set(CPUFEATURES_LIBRARIES cpufeatures CACHE INTERNAL "") +if(NOT DEFINED CPUFEATURES_SOURCES) + set(CPUFEATURES_SOURCES ${CPUFEATURES_ROOT}/cpu-features.c ${CPUFEATURES_ROOT}/cpu-features.h) +endif() -add_library(cpufeatures STATIC ${lib_srcs} ${lib_hdrs}) +include_directories(${CPUFEATURES_INCLUDE_DIRS}) +add_library(cpufeatures STATIC ${CPUFEATURES_SOURCES}) set_target_properties(cpufeatures PROPERTIES OUTPUT_NAME cpufeatures @@ -17,8 +20,8 @@ set_target_properties(cpufeatures COMPILE_PDB_NAME cpufeatures COMPILE_PDB_NAME_DEBUG "cpufeatures${OPENCV_DEBUG_POSTFIX}" ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH} - ) - +) + if(ENABLE_SOLUTION_FOLDERS) set_target_properties(cpufeatures PROPERTIES FOLDER "3rdparty") endif() @@ -26,4 +29,3 @@ endif() if(NOT BUILD_SHARED_LIBS) ocv_install_target(cpufeatures EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() - diff --git a/3rdparty/cpufeatures/LICENSE b/3rdparty/cpufeatures/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..d6c092292c614ce80204df312cfb89cdbb946035 --- /dev/null +++ b/3rdparty/cpufeatures/LICENSE @@ -0,0 +1,13 @@ +Copyright (C) 2016 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/3rdparty/cpufeatures/README.md b/3rdparty/cpufeatures/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d643c1c4a04b07af4d02edb47be6dfeeb2010eb8 --- /dev/null +++ b/3rdparty/cpufeatures/README.md @@ -0,0 +1,4 @@ +The Android NDK provides a small library named cpufeatures that your app can use at runtime to detect the target device's CPU family and the optional features it supports. +It is designed to work as-is on all official Android platform versions. + +https://developer.android.com/ndk/guides/cpu-features.html diff --git a/3rdparty/libwebp/CMakeLists.txt b/3rdparty/libwebp/CMakeLists.txt index e72932f3e0a884623cfe09a1727823f9e05e7058..a02e338d2f742d4dca2a21cdb057962ef3bfa88c 100644 --- a/3rdparty/libwebp/CMakeLists.txt +++ b/3rdparty/libwebp/CMakeLists.txt @@ -5,7 +5,7 @@ project(${WEBP_LIBRARY}) ocv_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -ocv_include_directories("${CPUFEATURES_INCLUDE_DIR}") +ocv_include_directories(${CPUFEATURES_INCLUDE_DIRS}) file(GLOB lib_srcs dec/*.c demux/*.c dsp/*.c enc/*.c mux/*.c utils/*.c webp/*.c) file(GLOB lib_hdrs dec/*.h demux/*.h dsp/*.h enc/*.h mux/*.h utils/*.h webp/*.h) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d1c925caeefd27d9d1eb0bf0ea4cdde9cdd3654..d53366b8761b8f3c7eecb7c158e3ff22e56b44e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,10 @@ if(POLICY CMP0042) cmake_policy(SET CMP0042 NEW) endif() +if(POLICY CMP0046) + cmake_policy(SET CMP0046 OLD) +endif() + if(POLICY CMP0051) cmake_policy(SET CMP0051 NEW) endif() diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index ca4a753dbd8104d5aeae8cff89d427a25959376a..1ca1daf827b50d9c286bf19530ec5e9887ecb1a2 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -32,10 +32,10 @@ source_group("Src" FILES "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version_string ocv_glob_module_sources(SOURCES "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version_string.inc" HEADERS ${lib_cuda_hdrs} ${lib_cuda_hdrs_detail}) -ocv_module_include_directories(${the_module} ${ZLIB_INCLUDE_DIRS} ${OPENCL_INCLUDE_DIRS} ${CPUFEATURES_INCLUDE_DIR}) +ocv_module_include_directories(${the_module} ${ZLIB_INCLUDE_DIRS} ${OPENCL_INCLUDE_DIRS} ${CPUFEATURES_INCLUDE_DIRS}) ocv_create_module(${extra_libs}) -ocv_target_link_libraries(${the_module} ${ZLIB_LIBRARIES} "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" "${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}") +ocv_target_link_libraries(${the_module} ${ZLIB_LIBRARIES} "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" "${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}") ocv_add_accuracy_tests() ocv_add_perf_tests() diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 6fa20a93cbd1ed1db91a986a63d7ba8f400c8687..2438663098fc29146ac19fa6d936cd8713fd9e7f 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -447,10 +447,16 @@ struct HWFeatures CV_UNUSED(cpuid_data_ex); #endif // OPENCV_HAVE_X86_CPUID - #if defined ANDROID || defined __linux__ + #if defined __ANDROID__ || defined __linux__ #ifdef __aarch64__ have[CV_CPU_NEON] = true; have[CV_CPU_FP16] = true; + #elif defined __arm__ && defined __ANDROID__ + __android_log_print(ANDROID_LOG_INFO, "OpenCV", "calling android_getCpuFeatures() ..."); + uint64_t features = android_getCpuFeatures(); + __android_log_print(ANDROID_LOG_INFO, "OpenCV", "calling android_getCpuFeatures() ... Done (%llx)", features); + have[CV_CPU_NEON] = (features & ANDROID_CPU_ARM_FEATURE_NEON) != 0; + have[CV_CPU_FP16] = (features & ANDROID_CPU_ARM_FEATURE_VFP_FP16) != 0; #elif defined __arm__ int cpufile = open("/proc/self/auxv", O_RDONLY); @@ -471,11 +477,6 @@ struct HWFeatures close(cpufile); } - #ifdef ANDROID - uint64_t features = android_getCpuFeatures(); - have[CV_CPU_NEON] = (features & ANDROID_CPU_ARM_FEATURE_NEON) != 0; - have[CV_CPU_FP16] = (features & ANDROID_CPU_ARM_FEATURE_VFP_FP16) != 0; - #endif #endif #elif (defined __clang__ || defined __APPLE__) #if (defined __ARM_NEON__ || (defined __ARM_NEON && defined __aarch64__))