From 870d9502bb767a61e054aece4c001364d45a9c40 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 16 Aug 2017 21:22:35 +0000 Subject: [PATCH 1/5] cmake: CMP0020 NEW --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8683f34ffa..5f2a4de439 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,10 +77,6 @@ if(WINRT) endif() endif() -if(POLICY CMP0020) - cmake_policy(SET CMP0020 OLD) -endif() - if(POLICY CMP0022) cmake_policy(SET CMP0022 OLD) endif() From b6949c5088b358b6f31649fb757c37affa1b6d07 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 16 Aug 2017 21:23:06 +0000 Subject: [PATCH 2/5] cmake: CMP0022 NEW --- CMakeLists.txt | 8 ------- cmake/FindCUDA.cmake | 12 +++++----- cmake/OpenCVDetectAndroidSDK.cmake | 2 +- cmake/OpenCVModule.cmake | 38 +++++++----------------------- modules/core/CMakeLists.txt | 4 ++-- modules/cudev/test/CMakeLists.txt | 4 +++- modules/highgui/CMakeLists.txt | 5 ---- modules/imgcodecs/CMakeLists.txt | 3 --- modules/java/CMakeLists.txt | 14 +++++------ modules/python/common.cmake | 6 ++--- modules/videoio/CMakeLists.txt | 5 ---- modules/viz/CMakeLists.txt | 4 ++-- 12 files changed, 33 insertions(+), 72 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f2a4de439..f8fff8c250 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,14 +77,6 @@ if(WINRT) endif() endif() -if(POLICY CMP0022) - cmake_policy(SET CMP0022 OLD) -endif() - -if(POLICY CMP0023) - cmake_policy(SET CMP0023 NEW) -endif() - if(POLICY CMP0026) # silence cmake 3.0+ warnings about reading LOCATION attribute cmake_policy(SET CMP0026 OLD) diff --git a/cmake/FindCUDA.cmake b/cmake/FindCUDA.cmake index 678b450aba..207be6e578 100644 --- a/cmake/FindCUDA.cmake +++ b/cmake/FindCUDA.cmake @@ -1556,7 +1556,7 @@ macro(CUDA_ADD_LIBRARY cuda_target) # variable will have been defined. CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") - target_link_libraries(${cuda_target} + target_link_libraries(${cuda_target} LINK_PRIVATE ${CUDA_LIBRARIES} ) @@ -1600,7 +1600,7 @@ macro(CUDA_ADD_EXECUTABLE cuda_target) # variable will have been defined. CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") - target_link_libraries(${cuda_target} + target_link_libraries(${cuda_target} LINK_PRIVATE ${CUDA_LIBRARIES} ) @@ -1675,9 +1675,9 @@ endmacro() ############################################################################### macro(CUDA_ADD_CUFFT_TO_TARGET target) if (CUDA_BUILD_EMULATION) - target_link_libraries(${target} ${CUDA_cufftemu_LIBRARY}) + target_link_libraries(${target} LINK_PRIVATE ${CUDA_cufftemu_LIBRARY}) else() - target_link_libraries(${target} ${CUDA_cufft_LIBRARY}) + target_link_libraries(${target} LINK_PRIVATE ${CUDA_cufft_LIBRARY}) endif() endmacro() @@ -1688,9 +1688,9 @@ endmacro() ############################################################################### macro(CUDA_ADD_CUBLAS_TO_TARGET target) if (CUDA_BUILD_EMULATION) - target_link_libraries(${target} ${CUDA_cublasemu_LIBRARY}) + target_link_libraries(${target} LINK_PRIVATE ${CUDA_cublasemu_LIBRARY}) else() - target_link_libraries(${target} ${CUDA_cublas_LIBRARY}) + target_link_libraries(${target} LINK_PRIVATE ${CUDA_cublas_LIBRARY}) endif() endmacro() diff --git a/cmake/OpenCVDetectAndroidSDK.cmake b/cmake/OpenCVDetectAndroidSDK.cmake index c8f7cba419..52278ee85b 100644 --- a/cmake/OpenCVDetectAndroidSDK.cmake +++ b/cmake/OpenCVDetectAndroidSDK.cmake @@ -290,7 +290,7 @@ macro(add_android_project target path) add_library(${JNI_LIB_NAME} SHARED ${android_proj_jni_files}) ocv_target_include_modules_recurse(${JNI_LIB_NAME} ${android_proj_NATIVE_DEPS}) ocv_target_include_directories(${JNI_LIB_NAME} "${path}/jni") - ocv_target_link_libraries(${JNI_LIB_NAME} ${OPENCV_LINKER_LIBS} ${android_proj_NATIVE_DEPS}) + ocv_target_link_libraries(${JNI_LIB_NAME} LINK_PRIVATE ${OPENCV_LINKER_LIBS} ${android_proj_NATIVE_DEPS}) set_target_properties(${JNI_LIB_NAME} PROPERTIES OUTPUT_NAME "${JNI_LIB_NAME}" diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index ea85e21d35..f560accfbd 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -787,15 +787,12 @@ macro(_ocv_create_module) endif() set(sub_objs "") - set(sub_links "") set(cuda_objs "") if (OPENCV_MODULE_${the_module}_CHILDREN) message(STATUS "Complex module ${the_module}") foreach (m ${OPENCV_MODULE_${the_module}_CHILDREN}) if (BUILD_${m} AND TARGET ${m}_object) - get_target_property(_sub_links ${m} LINK_LIBRARIES) list(APPEND sub_objs $) - list(APPEND sub_links ${_sub_links}) message(STATUS " + ${m}") else() message(STATUS " - ${m}") @@ -837,38 +834,21 @@ macro(_ocv_create_module) ) if (cuda_objs) - target_link_libraries(${the_module} ${cuda_objs}) - endif() - - # TODO: is it needed? - if (sub_links) - ocv_list_filterout(sub_links "^opencv_") - ocv_list_unique(sub_links) - target_link_libraries(${the_module} ${sub_links}) + target_link_libraries(${the_module} LINK_PRIVATE ${cuda_objs}) endif() unset(sub_objs) - unset(sub_links) unset(cuda_objs) set_target_properties(${the_module} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Module") set_source_files_properties(${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES} ${${the_module}_pch} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Module") - if(NOT BUILD_SHARED_LIBS OR NOT INSTALL_CREATE_DISTRIB) - ocv_target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK}) - ocv_target_link_libraries(${the_module} LINK_INTERFACE_LIBRARIES ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK}) - ocv_target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN}) - if (HAVE_CUDA) - ocv_target_link_libraries(${the_module} ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) - endif() - else() - ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK}) - ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK}) - ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN}) - if (HAVE_CUDA) - ocv_target_link_libraries(${the_module} LINK_PRIVATE ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) - endif() + ocv_target_link_libraries(${the_module} LINK_PUBLIC ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK}) + ocv_target_link_libraries(${the_module} LINK_PUBLIC ${OPENCV_MODULE_${the_module}_DEPS_EXT}) + ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_LINKER_LIBS} ${OPENCV_HAL_LINKER_LIBS} ${IPP_LIBS} ${ARGN}) + if (HAVE_CUDA) + ocv_target_link_libraries(${the_module} LINK_PRIVATE ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY}) endif() add_dependencies(opencv_modules ${the_module}) @@ -1074,7 +1054,7 @@ function(ocv_add_perf_tests) source_group("Src" FILES "${${the_target}_pch}") ocv_add_executable(${the_target} ${OPENCV_PERF_${the_module}_SOURCES} ${${the_target}_pch}) ocv_target_include_modules(${the_target} ${perf_deps} "${perf_path}") - ocv_target_link_libraries(${the_target} ${perf_deps} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS}) + ocv_target_link_libraries(${the_target} LINK_PRIVATE ${perf_deps} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS}) add_dependencies(opencv_perf_tests ${the_target}) set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};PerfTest") @@ -1151,7 +1131,7 @@ function(ocv_add_accuracy_tests) source_group("Src" FILES "${${the_target}_pch}") ocv_add_executable(${the_target} ${OPENCV_TEST_${the_module}_SOURCES} ${${the_target}_pch}) ocv_target_include_modules(${the_target} ${test_deps} "${test_path}") - ocv_target_link_libraries(${the_target} ${test_deps} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS}) + ocv_target_link_libraries(${the_target} LINK_PRIVATE ${test_deps} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS}) add_dependencies(opencv_tests ${the_target}) set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};AccuracyTest") @@ -1208,7 +1188,7 @@ function(ocv_add_samples) ocv_add_executable(${the_target} "${source}") ocv_target_include_modules(${the_target} ${samples_deps}) - ocv_target_link_libraries(${the_target} ${samples_deps}) + ocv_target_link_libraries(${the_target} LINK_PRIVATE ${samples_deps}) set_target_properties(${the_target} PROPERTIES PROJECT_LABEL "(sample) ${name}") set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Sample") diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 9a098514a7..4d6b7bbd82 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -4,7 +4,6 @@ ocv_add_dispatched_file(mathfuncs_core SSE2 AVX AVX2) ocv_add_dispatched_file(stat SSE4_2 AVX2) ocv_add_module(core - "${OPENCV_HAL_LINKER_LIBS}" OPTIONAL opencv_cudev WRAP java python) @@ -57,10 +56,11 @@ endif() ocv_create_module(${extra_libs}) -ocv_target_link_libraries(${the_module} +ocv_target_link_libraries(${the_module} LINK_PRIVATE "${ZLIB_LIBRARIES}" "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" "${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}" "${HALIDE_LIBRARIES}" "${ITT_LIBRARIES}" + "${OPENCV_HAL_LINKER_LIBS}" ) ocv_add_accuracy_tests() diff --git a/modules/cudev/test/CMakeLists.txt b/modules/cudev/test/CMakeLists.txt index d348fdcb56..ab9fd42529 100644 --- a/modules/cudev/test/CMakeLists.txt +++ b/modules/cudev/test/CMakeLists.txt @@ -16,7 +16,9 @@ if(OCV_DEPENDENCIES_FOUND) ocv_cuda_filter_options() CUDA_ADD_EXECUTABLE(${the_target} ${OPENCV_TEST_${the_module}_SOURCES}) - ocv_target_link_libraries(${the_target} ${test_deps} ${OPENCV_LINKER_LIBS} ${CUDA_LIBRARIES}) + ocv_target_link_libraries(${the_target} LINK_PRIVATE + ${test_deps} ${OPENCV_LINKER_LIBS} ${CUDA_LIBRARIES} + ) add_dependencies(opencv_tests ${the_target}) set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL}") diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 1b73dbcbcc..4fba298589 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -147,11 +147,6 @@ if(MSVC) set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG") endif() -if(NOT BUILD_opencv_world) - #stop automatic dependencies propagation for this module - set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "") -endif() - ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations) endmacro() diff --git a/modules/imgcodecs/CMakeLists.txt b/modules/imgcodecs/CMakeLists.txt index 7f53e48595..281b507328 100644 --- a/modules/imgcodecs/CMakeLists.txt +++ b/modules/imgcodecs/CMakeLists.txt @@ -123,9 +123,6 @@ if(MSVC) set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG") endif() -#stop automatic dependencies propagation for this module -set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "") - ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations) endmacro() diff --git a/modules/java/CMakeLists.txt b/modules/java/CMakeLists.txt index 74bc0ef041..ae28e4cbc9 100644 --- a/modules/java/CMakeLists.txt +++ b/modules/java/CMakeLists.txt @@ -435,14 +435,14 @@ if(BUILD_FAT_JAVA_LIB) endif() if(APPLE) foreach(_dep ${__deps}) - ocv_target_link_libraries(${the_module} -Wl,-force_load "${_dep}") + ocv_target_link_libraries(${the_module} LINK_PRIVATE -Wl,-force_load "${_dep}") endforeach() else() - ocv_target_link_libraries(${the_module} -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive) + ocv_target_link_libraries(${the_module} LINK_PRIVATE -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive) endif() - ocv_target_link_libraries(${the_module} ${__extradeps} ${OPENCV_LINKER_LIBS}) + ocv_target_link_libraries(${the_module} LINK_PRIVATE ${__extradeps} ${OPENCV_LINKER_LIBS}) else() - ocv_target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS}) + ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS}) endif() # Additional target properties @@ -451,12 +451,12 @@ set_target_properties(${the_module} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} - LINK_INTERFACE_LIBRARIES "" ) if(ANDROID) - ocv_target_link_libraries(${the_module} jnigraphics) # for Mat <=> Bitmap converters - ocv_target_link_libraries(${the_module} LINK_INTERFACE_LIBRARIES ${OPENCV_LINKER_LIBS} jnigraphics) + ocv_target_link_libraries(${the_module} LINK_PUBLIC jnigraphics) # for Mat <=> Bitmap converters + ocv_target_link_libraries(${the_module} LINK_PUBLIC log dl z) + ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_LINKER_LIBS}) # force strip library after the build command # because samples and tests will make a copy of the library before install diff --git a/modules/python/common.cmake b/modules/python/common.cmake index 454c0d4271..28a3d9cd15 100644 --- a/modules/python/common.cmake +++ b/modules/python/common.cmake @@ -72,12 +72,12 @@ if(APPLE) set_target_properties(${the_module} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") elseif(WIN32 OR OPENCV_FORCE_PYTHON_LIBS) if(${PYTHON}_DEBUG_LIBRARIES AND NOT ${PYTHON}_LIBRARIES MATCHES "optimized.*debug") - ocv_target_link_libraries(${the_module} debug ${${PYTHON}_DEBUG_LIBRARIES} optimized ${${PYTHON}_LIBRARIES}) + ocv_target_link_libraries(${the_module} LINK_PRIVATE debug ${${PYTHON}_DEBUG_LIBRARIES} optimized ${${PYTHON}_LIBRARIES}) else() - ocv_target_link_libraries(${the_module} ${${PYTHON}_LIBRARIES}) + ocv_target_link_libraries(${the_module} LINK_PRIVATE ${${PYTHON}_LIBRARIES}) endif() endif() -ocv_target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS}) +ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_MODULE_${the_module}_DEPS}) if(DEFINED ${PYTHON}_CVPY_SUFFIX) set(CVPY_SUFFIX "${${PYTHON}_CVPY_SUFFIX}") diff --git a/modules/videoio/CMakeLists.txt b/modules/videoio/CMakeLists.txt index 086e2235e5..0c0b3791b2 100644 --- a/modules/videoio/CMakeLists.txt +++ b/modules/videoio/CMakeLists.txt @@ -261,11 +261,6 @@ if(MSVC) endif() endif() -#stop automatic dependencies propagation for this module -if(NOT BUILD_opencv_world) - set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "") -endif() - ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations) if(WIN32 AND HAVE_FFMPEG) diff --git a/modules/viz/CMakeLists.txt b/modules/viz/CMakeLists.txt index 68bd8d3ec7..ddeccf15f6 100644 --- a/modules/viz/CMakeLists.txt +++ b/modules/viz/CMakeLists.txt @@ -25,10 +25,10 @@ if(NOT BUILD_SHARED_LIBS) endif() ocv_define_module(viz opencv_core WRAP python) -ocv_target_link_libraries(${the_module} ${VTK_LIBRARIES}) +ocv_target_link_libraries(${the_module} LINK_PRIVATE ${VTK_LIBRARIES}) if(APPLE AND BUILD_opencv_viz) - ocv_target_link_libraries(${the_module} "-framework Cocoa") + ocv_target_link_libraries(${the_module} LINK_PRIVATE "-framework Cocoa") endif() if(TARGET opencv_test_viz) From e63d3dd25ffbb30dd05bbbfb43b19d833a9c7d52 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 16 Aug 2017 22:33:27 +0000 Subject: [PATCH 3/5] cmake: CMP0046 NEW --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8fff8c250..5eecb036ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,7 +87,7 @@ if(POLICY CMP0042) endif() if(POLICY CMP0046) - cmake_policy(SET CMP0046 OLD) + cmake_policy(SET CMP0046 NEW) endif() if(POLICY CMP0051) From 87a98e4562e0dddeb1708af0a363913f7352b1f0 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 16 Aug 2017 22:49:17 +0000 Subject: [PATCH 4/5] cmake: CMP0026 NEW --- CMakeLists.txt | 5 +- cmake/OpenCVDetectAndroidSDK.cmake | 3 +- cmake/OpenCVGenABI.cmake | 12 +-- cmake/OpenCVGenAndroidMK.cmake | 25 ++++++- cmake/OpenCVGenPkgconfig.cmake | 95 +++++++++++++++++++----- cmake/OpenCVUtils.cmake | 74 ++++++++++++------ cmake/templates/opencv_abi.xml.in | 2 - modules/java/CMakeLists.txt | 3 +- modules/java/android_test/CMakeLists.txt | 5 +- 9 files changed, 158 insertions(+), 66 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5eecb036ec..3e23a3955d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,8 +78,7 @@ if(WINRT) endif() if(POLICY CMP0026) - # silence cmake 3.0+ warnings about reading LOCATION attribute - cmake_policy(SET CMP0026 OLD) + cmake_policy(SET CMP0026 NEW) endif() if(POLICY CMP0042) @@ -1368,7 +1367,7 @@ if(HAVE_OPENCL) set(__libs "") foreach(l ${OPENCL_LIBRARIES}) if(TARGET ${l}) - get_target_property(p ${l} LOCATION) + get_target_property(p ${l} IMPORTED_LOCATION) if(p MATCHES NOTFOUND) list(APPEND __libs "${l}") else() diff --git a/cmake/OpenCVDetectAndroidSDK.cmake b/cmake/OpenCVDetectAndroidSDK.cmake index 52278ee85b..85c103e002 100644 --- a/cmake/OpenCVDetectAndroidSDK.cmake +++ b/cmake/OpenCVDetectAndroidSDK.cmake @@ -297,9 +297,8 @@ macro(add_android_project target path) LIBRARY_OUTPUT_DIRECTORY "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}" ) - get_target_property(android_proj_jni_location "${JNI_LIB_NAME}" LOCATION) if (NOT (CMAKE_BUILD_TYPE MATCHES "debug")) - add_custom_command(TARGET ${JNI_LIB_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${android_proj_jni_location}") + add_custom_command(TARGET ${JNI_LIB_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "$") endif() endif() endif() diff --git a/cmake/OpenCVGenABI.cmake b/cmake/OpenCVGenABI.cmake index e9d6a33481..4aaa16a6a1 100644 --- a/cmake/OpenCVGenABI.cmake +++ b/cmake/OpenCVGenABI.cmake @@ -26,7 +26,9 @@ set(OPENCV_ABI_SKIP_HEADERS "") set(OPENCV_ABI_SKIP_LIBRARIES "") foreach(mod ${OPENCV_MODULES_BUILD}) string(REGEX REPLACE "^opencv_" "" mod "${mod}") - if(NOT "${OPENCV_MODULE_opencv_${mod}_LOCATION}" STREQUAL "${OpenCV_SOURCE_DIR}/modules/${mod}") + if(NOT OPENCV_MODULE_opencv_${mod}_CLASS STREQUAL "PUBLIC" + OR NOT "${OPENCV_MODULE_opencv_${mod}_LOCATION}" STREQUAL "${OpenCV_SOURCE_DIR}/modules/${mod}" # opencv_contrib + ) # headers foreach(h ${OPENCV_MODULE_opencv_${mod}_HEADERS}) file(RELATIVE_PATH h "${OPENCV_MODULE_opencv_${mod}_LOCATION}/include" "${h}") @@ -34,10 +36,7 @@ foreach(mod ${OPENCV_MODULES_BUILD}) endforeach() # libraries if(TARGET opencv_${mod}) # opencv_world - set(lib_name "") - get_target_property(lib_name opencv_${mod} LOCATION) - get_filename_component(lib_name "${lib_name}" NAME) - list(APPEND OPENCV_ABI_SKIP_LIBRARIES "${lib_name}") + list(APPEND OPENCV_ABI_SKIP_LIBRARIES "\$") endif() endif() endforeach() @@ -48,4 +47,5 @@ string(REPLACE ";" "\n " OPENCV_ABI_SKIP_LIBRARIES "${OPENCV_ABI_SKIP_LIBRARI set(OPENCV_ABI_GCC_OPTIONS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} -DOPENCV_ABI_CHECK=1") string(REGEX REPLACE "([^ ]) +([^ ])" "\\1\\n \\2" OPENCV_ABI_GCC_OPTIONS "${OPENCV_ABI_GCC_OPTIONS}") -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_abi.xml.in" "${path1}") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_abi.xml.in" "${path1}.base") +file(GENERATE OUTPUT "${path1}" INPUT "${path1}.base") diff --git a/cmake/OpenCVGenAndroidMK.cmake b/cmake/OpenCVGenAndroidMK.cmake index 9cc52147af..69aa43bfd8 100644 --- a/cmake/OpenCVGenAndroidMK.cmake +++ b/cmake/OpenCVGenAndroidMK.cmake @@ -20,12 +20,29 @@ if(ANDROID) endif() # build the list of opencv libs and dependencies for all modules - ocv_get_all_libs(OPENCV_MODULES_CONFIGMAKE OPENCV_EXTRA_COMPONENTS_CONFIGMAKE OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE) + ocv_get_all_libs(OPENCV_MODULES OPENCV_EXTRA_COMPONENTS OPENCV_3RDPARTY_COMPONENTS) # list -> string - string(REPLACE ";" " " OPENCV_MODULES_CONFIGMAKE "${OPENCV_MODULES_CONFIGMAKE}") - string(REPLACE ";" " " OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "${OPENCV_EXTRA_COMPONENTS_CONFIGMAKE}") - string(REPLACE ";" " " OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE "${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE}") + foreach(_var OPENCV_MODULES OPENCV_EXTRA_COMPONENTS OPENCV_3RDPARTY_COMPONENTS) + set(var "${_var}_CONFIGMAKE") + set(${var} "") + foreach(lib ${${_var}}) + set(lib_name "${lib}") + if(TARGET ${lib}) + get_target_property(_output ${lib} IMPORTED_LOCATION) + if(NOT _output) + get_target_property(output_name ${lib} OUTPUT_NAME) + if(output_name) + set(lib_name "${output_name}") + endif() + else() + ocv_get_libname(lib_name "${_output}") + endif() + endif() + set(${var} "${${var}} ${lib_name}") + endforeach() + string(STRIP "${${var}}" ${var}) + endforeach() # replace 'opencv_' -> ''' string(REPLACE "opencv_" "" OPENCV_MODULES_CONFIGMAKE "${OPENCV_MODULES_CONFIGMAKE}") diff --git a/cmake/OpenCVGenPkgconfig.cmake b/cmake/OpenCVGenPkgconfig.cmake index b8cb8777c0..cd7566f844 100644 --- a/cmake/OpenCVGenPkgconfig.cmake +++ b/cmake/OpenCVGenPkgconfig.cmake @@ -1,3 +1,7 @@ +if(MSVC OR IOS) + return() +endif() + # -------------------------------------------------------------------------------------------- # according to man pkg-config # The package name specified on the pkg-config command line is defined to @@ -12,11 +16,11 @@ macro(fix_prefix lst isown) set(_lst) foreach(item ${${lst}}) - if(TARGET ${item}) - get_target_property(item "${item}" LOCATION_${CMAKE_BUILD_TYPE}) - if("${isown}") - get_filename_component(item "${item}" NAME_WE) - string(REGEX REPLACE "^lib(.*)" "\\1" item "${item}") + if(DEFINED TARGET_LOCATION_${item}) + set(item "${TARGET_LOCATION_${item}}") + if(${isown}) + get_filename_component(item "${item}" NAME) + ocv_get_libname(item "${item}") endif() endif() if(item MATCHES "^-l") @@ -25,8 +29,8 @@ macro(fix_prefix lst isown) list(APPEND _lst "${item}") elseif(item MATCHES "[\\/]") get_filename_component(libdir "${item}" PATH) - get_filename_component(libname "${item}" NAME_WE) - string(REGEX REPLACE "^lib(.*)" "\\1" libname "${libname}") + get_filename_component(_libname "${item}" NAME) + ocv_get_libname(libname "${_libname}") list(APPEND _lst "-L${libdir}" "-l${libname}") else() list(APPEND _lst "-l${item}") @@ -36,6 +40,14 @@ macro(fix_prefix lst isown) unset(_lst) endmacro() +if(NOT DEFINED CMAKE_HELPER_SCRIPT) + +if(INSTALL_TO_MANGLED_PATHS) + set(OPENCV_PC_FILE_NAME "opencv-${OPENCV_VERSION}.pc") +else() + set(OPENCV_PC_FILE_NAME opencv.pc) +endif() + # build the list of opencv libs and dependencies for all modules ocv_get_all_libs(_modules _extra _3rdparty) @@ -56,9 +68,61 @@ if(_modules MATCHES "opencv_contrib_world") list(INSERT _modules 0 "opencv_contrib_world") endif() -fix_prefix(_modules TRUE) -fix_prefix(_extra FALSE) -fix_prefix(_3rdparty TRUE) +set(HELPER_SCRIPT "") +ocv_cmake_script_append_var(HELPER_SCRIPT + BUILD_SHARED_LIBS + CMAKE_BINARY_DIR + CMAKE_INSTALL_PREFIX + OpenCV_SOURCE_DIR + OPENCV_PC_FILE_NAME + OPENCV_VERSION_PLAIN + OPENCV_LIB_INSTALL_PATH + OPENCV_INCLUDE_INSTALL_PATH + OPENCV_3P_LIB_INSTALL_PATH + + _modules + _extra + _3rdparty +) + +foreach(item ${_modules} ${_extra} ${_3rdparty}) + if(TARGET ${item}) + set(HELPER_SCRIPT "${HELPER_SCRIPT} +set(TARGET_LOCATION_${item} \"$\") +") + endif() +endforeach() + +set(CMAKE_HELPER_SCRIPT "${CMAKE_BINARY_DIR}/OpenCVGenPkgConfig.info.cmake") +file(GENERATE OUTPUT "${CMAKE_HELPER_SCRIPT}" CONTENT "${HELPER_SCRIPT}") + +add_custom_target(developer_scripts) +add_custom_command( + OUTPUT "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" + COMMAND ${CMAKE_COMMAND} "-DCMAKE_HELPER_SCRIPT=${CMAKE_HELPER_SCRIPT}" -P "${OpenCV_SOURCE_DIR}/cmake/OpenCVGenPkgconfig.cmake" + DEPENDS "${CMAKE_BINARY_DIR}/OpenCVGenPkgConfig.info.cmake" + "${OpenCV_SOURCE_DIR}/cmake/OpenCVGenPkgconfig.cmake" + COMMENT "Generate ${OPENCV_PC_FILE_NAME}" +) +add_custom_target(gen-pkgconfig ALL SOURCES "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}") +add_dependencies(developer_scripts gen-pkgconfig) + + +if(UNIX AND NOT ANDROID) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig COMPONENT dev) +endif() + +# ============================================================================= +else() # DEFINED CMAKE_HELPER_SCRIPT + +cmake_minimum_required(VERSION 2.8.12.2) +cmake_policy(SET CMP0012 NEW) +include("${CMAKE_HELPER_SCRIPT}") +include("${OpenCV_SOURCE_DIR}/cmake/OpenCVUtils.cmake") + +fix_prefix(_modules 1) +fix_prefix(_extra 0) +fix_prefix(_3rdparty 1) ocv_list_unique(_modules) ocv_list_unique(_extra) @@ -68,7 +132,7 @@ set(OPENCV_PC_LIBS "-L\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}" "${_modules}" ) -if (BUILD_SHARED_LIBS) +if(BUILD_SHARED_LIBS) set(OPENCV_PC_LIBS_PRIVATE "${_extra}") else() set(OPENCV_PC_LIBS_PRIVATE @@ -86,15 +150,8 @@ set(exec_prefix "\${prefix}") set(libdir "\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}") set(includedir "\${prefix}/${OPENCV_INCLUDE_INSTALL_PATH}") -if(INSTALL_TO_MANGLED_PATHS) - set(OPENCV_PC_FILE_NAME "opencv-${OPENCV_VERSION}.pc") -else() - set(OPENCV_PC_FILE_NAME opencv.pc) -endif() configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv-XXX.pc.in" "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" @ONLY) -if(UNIX AND NOT ANDROID) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig COMPONENT dev) -endif() +endif() # DEFINED CMAKE_HELPER_SCRIPT diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 8ef7205009..a75e171fb3 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -517,6 +517,7 @@ macro(CHECK_MODULE module_name define cv_module) endif() endmacro() +if(NOT DEFINED CMAKE_ARGC) # Guard CMake standalone invocations set(OPENCV_BUILD_INFO_FILE "${CMAKE_BINARY_DIR}/version_string.tmp") file(REMOVE "${OPENCV_BUILD_INFO_FILE}") @@ -597,6 +598,7 @@ function(status text) endif() endfunction() +endif() # NOT DEFINED CMAKE_ARGC # remove all matching elements from the list macro(ocv_list_filterout lst regex) @@ -689,8 +691,8 @@ endmacro() function(ocv_convert_to_lib_name var) set(tmp "") foreach(path ${ARGN}) - get_filename_component(tmp_name "${path}" NAME_WE) - string(REGEX REPLACE "^lib" "" tmp_name "${tmp_name}") + get_filename_component(tmp_name "${path}" NAME) + ocv_get_libname(tmp_name "${tmp_name}") list(APPEND tmp "${tmp_name}") endforeach() set(${var} ${tmp} PARENT_SCOPE) @@ -899,32 +901,42 @@ function(ocv_source_group group) endif() endfunction() -function(ocv_target_link_libraries target) - _ocv_fix_target(target) - set(LINK_DEPS ${ARGN}) - # process world - if(BUILD_opencv_world) - foreach(m ${OPENCV_MODULES_BUILD}) - if(OPENCV_MODULE_${m}_IS_PART_OF_WORLD) - if(";${LINK_DEPS};" MATCHES ";${m};") - list(REMOVE_ITEM LINK_DEPS ${m}) - if(NOT (";${LINK_DEPS};" MATCHES ";opencv_world;")) - list(APPEND LINK_DEPS opencv_world) - endif() - endif() - endif() - endforeach() - endif() - if(";${LINK_DEPS};" MATCHES ";${target};") - list(REMOVE_ITEM LINK_DEPS "${target}") # prevent "link to itself" warning (world problem) - endif() +macro(__ocv_push_target_link_libraries) if(NOT TARGET ${target}) if(NOT DEFINED OPENCV_MODULE_${target}_LOCATION) message(FATAL_ERROR "ocv_target_link_libraries: invalid target: '${target}'") endif() - set(OPENCV_MODULE_${target}_LINK_DEPS ${OPENCV_MODULE_${target}_LINK_DEPS} ${LINK_DEPS} CACHE INTERNAL "" FORCE) + set(OPENCV_MODULE_${target}_LINK_DEPS ${OPENCV_MODULE_${target}_LINK_DEPS} ${ARGN} CACHE INTERNAL "" FORCE) else() - target_link_libraries(${target} ${LINK_DEPS}) + target_link_libraries(${target} ${ARGN}) + endif() +endmacro() + +function(ocv_target_link_libraries target) + set(LINK_DEPS ${ARGN}) + _ocv_fix_target(target) + set(LINK_MODE "LINK_PRIVATE") + set(LINK_PENDING "") + foreach(dep ${LINK_DEPS}) + if(" ${dep}" STREQUAL " ${target}") + # prevent "link to itself" warning (world problem) + elseif(" ${dep}" STREQUAL " LINK_PRIVATE" OR " ${dep}" STREQUAL "LINK_PUBLIC") + if(NOT LINK_PENDING STREQUAL "") + __ocv_push_target_link_libraries(${LINK_MODE} ${LINK_PENDING}) + set(LINK_PENDING "") + set(LINK_MODE "${dep}") + endif() + else() + if(BUILD_opencv_world) + if(OPENCV_MODULE_${dep}_IS_PART_OF_WORLD) + set(dep opencv_world) + endif() + endif() + list(APPEND LINK_PENDING "${dep}") + endif() + endforeach() + if(NOT LINK_PENDING STREQUAL "") + __ocv_push_target_link_libraries(${LINK_MODE} ${LINK_PENDING}) endif() endfunction() @@ -1037,6 +1049,12 @@ macro(ocv_get_all_libs _modules _extra _3rdparty) endforeach() foreach (dep ${deps} ${OPENCV_LINKER_LIBS}) if (NOT DEFINED OPENCV_MODULE_${dep}_LOCATION) + if(dep MATCHES "^\\$]+)>$") + set(dep "${CMAKE_MATCH_1}") + endif() + if(dep MATCHES "^\\$<") + message(WARNING "Unexpected CMake generator expression: ${dep}") + endif() if (TARGET ${dep}) get_target_property(_type ${dep} TYPE) if(_type STREQUAL "STATIC_LIBRARY" AND BUILD_SHARED_LIBS) @@ -1055,7 +1073,7 @@ macro(ocv_get_all_libs _modules _extra _3rdparty) string(FIND "${_output}" "${CMAKE_BINARY_DIR}" _POS) if (_POS EQUAL 0) ocv_get_libname(_libname "${_output_name}") - list(INSERT ${_3rdparty} 0 ${_libname}) + list(INSERT ${_3rdparty} 0 ${dep}) else() if(_output) list(INSERT ${_extra} 0 ${_output}) @@ -1175,3 +1193,11 @@ macro(ocv_generate_vs_version_file DESTINATION) configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/vs_version.rc.in" "${DESTINATION}" @ONLY) endmacro() + +macro(ocv_cmake_script_append_var content_var) + foreach(var_name ${ARGN}) + set(${content_var} "${${content_var}} +set(${var_name} \"${${var_name}}\") +") + endforeach() +endmacro() diff --git a/cmake/templates/opencv_abi.xml.in b/cmake/templates/opencv_abi.xml.in index 43a53c3eeb..99128451bf 100644 --- a/cmake/templates/opencv_abi.xml.in +++ b/cmake/templates/opencv_abi.xml.in @@ -29,8 +29,6 @@ opencv2/flann/hdf5.h opencv2/imgcodecs/ios.h opencv2/videoio/cap_ios.h - opencv2/ts.hpp - opencv2/ts/* opencv2/xobjdetect/private.hpp @OPENCV_ABI_SKIP_HEADERS@ diff --git a/modules/java/CMakeLists.txt b/modules/java/CMakeLists.txt index ae28e4cbc9..2f49eb2e90 100644 --- a/modules/java/CMakeLists.txt +++ b/modules/java/CMakeLists.txt @@ -460,10 +460,9 @@ if(ANDROID) # force strip library after the build command # because samples and tests will make a copy of the library before install - get_target_property(__opencv_java_location ${the_module} LOCATION) # Turn off stripping in debug build if ( NOT (CMAKE_BUILD_TYPE MATCHES "Debug")) - add_custom_command(TARGET ${the_module} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${__opencv_java_location}") + add_custom_command(TARGET ${the_module} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "$") endif() endif() diff --git a/modules/java/android_test/CMakeLists.txt b/modules/java/android_test/CMakeLists.txt index 6d69de5a0f..2925d65e37 100644 --- a/modules/java/android_test/CMakeLists.txt +++ b/modules/java/android_test/CMakeLists.txt @@ -43,13 +43,10 @@ add_custom_command( list(APPEND opencv_test_java_file_deps ${android_proj_target_files}) -get_target_property(java_location opencv_java LOCATION) -get_filename_component(java_name "${java_location}" NAME) - # build java part add_custom_command( OUTPUT "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" - COMMAND ${CMAKE_COMMAND} -E copy_if_different "${java_location}" "${opencv_test_java_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${java_name}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "$" "${opencv_test_java_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/$" COMMAND ${ANT_EXECUTABLE} -q -noinput -k debug -Djava.target=1.6 -Djava.source=1.6 COMMAND ${CMAKE_COMMAND} -E touch "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" # needed because ant does not update the timestamp of updated apk WORKING_DIRECTORY "${opencv_test_java_bin_dir}" From 8c84763ed306a3b2bf85f82a3d4487bad77ddc90 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 19 Aug 2017 16:05:32 +0000 Subject: [PATCH 5/5] vtk: eliminate 'override' build warning --- modules/viz/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/viz/CMakeLists.txt b/modules/viz/CMakeLists.txt index ddeccf15f6..a5468c5bba 100644 --- a/modules/viz/CMakeLists.txt +++ b/modules/viz/CMakeLists.txt @@ -24,6 +24,8 @@ if(NOT BUILD_SHARED_LIBS) endif() endif() +ocv_warnings_disable(CMAKE_CXX_FLAGS -Winconsistent-missing-override) + ocv_define_module(viz opencv_core WRAP python) ocv_target_link_libraries(${the_module} LINK_PRIVATE ${VTK_LIBRARIES})