Skip to content

Commit b6949c5

Browse files
committed
cmake: CMP0022 NEW
1 parent 870d950 commit b6949c5

File tree

12 files changed

+33
-72
lines changed

12 files changed

+33
-72
lines changed

CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ if(WINRT)
7777
endif()
7878
endif()
7979

80-
if(POLICY CMP0022)
81-
cmake_policy(SET CMP0022 OLD)
82-
endif()
83-
84-
if(POLICY CMP0023)
85-
cmake_policy(SET CMP0023 NEW)
86-
endif()
87-
8880
if(POLICY CMP0026)
8981
# silence cmake 3.0+ warnings about reading LOCATION attribute
9082
cmake_policy(SET CMP0026 OLD)

cmake/FindCUDA.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ macro(CUDA_ADD_LIBRARY cuda_target)
15561556
# variable will have been defined.
15571557
CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}")
15581558

1559-
target_link_libraries(${cuda_target}
1559+
target_link_libraries(${cuda_target} LINK_PRIVATE
15601560
${CUDA_LIBRARIES}
15611561
)
15621562

@@ -1600,7 +1600,7 @@ macro(CUDA_ADD_EXECUTABLE cuda_target)
16001600
# variable will have been defined.
16011601
CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}")
16021602

1603-
target_link_libraries(${cuda_target}
1603+
target_link_libraries(${cuda_target} LINK_PRIVATE
16041604
${CUDA_LIBRARIES}
16051605
)
16061606

@@ -1675,9 +1675,9 @@ endmacro()
16751675
###############################################################################
16761676
macro(CUDA_ADD_CUFFT_TO_TARGET target)
16771677
if (CUDA_BUILD_EMULATION)
1678-
target_link_libraries(${target} ${CUDA_cufftemu_LIBRARY})
1678+
target_link_libraries(${target} LINK_PRIVATE ${CUDA_cufftemu_LIBRARY})
16791679
else()
1680-
target_link_libraries(${target} ${CUDA_cufft_LIBRARY})
1680+
target_link_libraries(${target} LINK_PRIVATE ${CUDA_cufft_LIBRARY})
16811681
endif()
16821682
endmacro()
16831683

@@ -1688,9 +1688,9 @@ endmacro()
16881688
###############################################################################
16891689
macro(CUDA_ADD_CUBLAS_TO_TARGET target)
16901690
if (CUDA_BUILD_EMULATION)
1691-
target_link_libraries(${target} ${CUDA_cublasemu_LIBRARY})
1691+
target_link_libraries(${target} LINK_PRIVATE ${CUDA_cublasemu_LIBRARY})
16921692
else()
1693-
target_link_libraries(${target} ${CUDA_cublas_LIBRARY})
1693+
target_link_libraries(${target} LINK_PRIVATE ${CUDA_cublas_LIBRARY})
16941694
endif()
16951695
endmacro()
16961696

cmake/OpenCVDetectAndroidSDK.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ macro(add_android_project target path)
290290
add_library(${JNI_LIB_NAME} SHARED ${android_proj_jni_files})
291291
ocv_target_include_modules_recurse(${JNI_LIB_NAME} ${android_proj_NATIVE_DEPS})
292292
ocv_target_include_directories(${JNI_LIB_NAME} "${path}/jni")
293-
ocv_target_link_libraries(${JNI_LIB_NAME} ${OPENCV_LINKER_LIBS} ${android_proj_NATIVE_DEPS})
293+
ocv_target_link_libraries(${JNI_LIB_NAME} LINK_PRIVATE ${OPENCV_LINKER_LIBS} ${android_proj_NATIVE_DEPS})
294294

295295
set_target_properties(${JNI_LIB_NAME} PROPERTIES
296296
OUTPUT_NAME "${JNI_LIB_NAME}"

cmake/OpenCVModule.cmake

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -787,15 +787,12 @@ macro(_ocv_create_module)
787787
endif()
788788

789789
set(sub_objs "")
790-
set(sub_links "")
791790
set(cuda_objs "")
792791
if (OPENCV_MODULE_${the_module}_CHILDREN)
793792
message(STATUS "Complex module ${the_module}")
794793
foreach (m ${OPENCV_MODULE_${the_module}_CHILDREN})
795794
if (BUILD_${m} AND TARGET ${m}_object)
796-
get_target_property(_sub_links ${m} LINK_LIBRARIES)
797795
list(APPEND sub_objs $<TARGET_OBJECTS:${m}_object>)
798-
list(APPEND sub_links ${_sub_links})
799796
message(STATUS " + ${m}")
800797
else()
801798
message(STATUS " - ${m}")
@@ -837,38 +834,21 @@ macro(_ocv_create_module)
837834
)
838835

839836
if (cuda_objs)
840-
target_link_libraries(${the_module} ${cuda_objs})
841-
endif()
842-
843-
# TODO: is it needed?
844-
if (sub_links)
845-
ocv_list_filterout(sub_links "^opencv_")
846-
ocv_list_unique(sub_links)
847-
target_link_libraries(${the_module} ${sub_links})
837+
target_link_libraries(${the_module} LINK_PRIVATE ${cuda_objs})
848838
endif()
849839

850840
unset(sub_objs)
851-
unset(sub_links)
852841
unset(cuda_objs)
853842

854843
set_target_properties(${the_module} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Module")
855844
set_source_files_properties(${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES} ${${the_module}_pch}
856845
PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Module")
857846

858-
if(NOT BUILD_SHARED_LIBS OR NOT INSTALL_CREATE_DISTRIB)
859-
ocv_target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK})
860-
ocv_target_link_libraries(${the_module} LINK_INTERFACE_LIBRARIES ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK})
861-
ocv_target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
862-
if (HAVE_CUDA)
863-
ocv_target_link_libraries(${the_module} ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
864-
endif()
865-
else()
866-
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK})
867-
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK})
868-
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
869-
if (HAVE_CUDA)
870-
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
871-
endif()
847+
ocv_target_link_libraries(${the_module} LINK_PUBLIC ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK})
848+
ocv_target_link_libraries(${the_module} LINK_PUBLIC ${OPENCV_MODULE_${the_module}_DEPS_EXT})
849+
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_LINKER_LIBS} ${OPENCV_HAL_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
850+
if (HAVE_CUDA)
851+
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
872852
endif()
873853

874854
add_dependencies(opencv_modules ${the_module})
@@ -1074,7 +1054,7 @@ function(ocv_add_perf_tests)
10741054
source_group("Src" FILES "${${the_target}_pch}")
10751055
ocv_add_executable(${the_target} ${OPENCV_PERF_${the_module}_SOURCES} ${${the_target}_pch})
10761056
ocv_target_include_modules(${the_target} ${perf_deps} "${perf_path}")
1077-
ocv_target_link_libraries(${the_target} ${perf_deps} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS})
1057+
ocv_target_link_libraries(${the_target} LINK_PRIVATE ${perf_deps} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS})
10781058
add_dependencies(opencv_perf_tests ${the_target})
10791059

10801060
set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};PerfTest")
@@ -1151,7 +1131,7 @@ function(ocv_add_accuracy_tests)
11511131
source_group("Src" FILES "${${the_target}_pch}")
11521132
ocv_add_executable(${the_target} ${OPENCV_TEST_${the_module}_SOURCES} ${${the_target}_pch})
11531133
ocv_target_include_modules(${the_target} ${test_deps} "${test_path}")
1154-
ocv_target_link_libraries(${the_target} ${test_deps} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS})
1134+
ocv_target_link_libraries(${the_target} LINK_PRIVATE ${test_deps} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS})
11551135
add_dependencies(opencv_tests ${the_target})
11561136

11571137
set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};AccuracyTest")
@@ -1208,7 +1188,7 @@ function(ocv_add_samples)
12081188

12091189
ocv_add_executable(${the_target} "${source}")
12101190
ocv_target_include_modules(${the_target} ${samples_deps})
1211-
ocv_target_link_libraries(${the_target} ${samples_deps})
1191+
ocv_target_link_libraries(${the_target} LINK_PRIVATE ${samples_deps})
12121192
set_target_properties(${the_target} PROPERTIES PROJECT_LABEL "(sample) ${name}")
12131193

12141194
set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Sample")

modules/core/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ ocv_add_dispatched_file(mathfuncs_core SSE2 AVX AVX2)
44
ocv_add_dispatched_file(stat SSE4_2 AVX2)
55

66
ocv_add_module(core
7-
"${OPENCV_HAL_LINKER_LIBS}"
87
OPTIONAL opencv_cudev
98
WRAP java python)
109

@@ -57,10 +56,11 @@ endif()
5756

5857
ocv_create_module(${extra_libs})
5958

60-
ocv_target_link_libraries(${the_module}
59+
ocv_target_link_libraries(${the_module} LINK_PRIVATE
6160
"${ZLIB_LIBRARIES}" "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}"
6261
"${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}" "${HALIDE_LIBRARIES}"
6362
"${ITT_LIBRARIES}"
63+
"${OPENCV_HAL_LINKER_LIBS}"
6464
)
6565

6666
ocv_add_accuracy_tests()

modules/cudev/test/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ if(OCV_DEPENDENCIES_FOUND)
1616
ocv_cuda_filter_options()
1717

1818
CUDA_ADD_EXECUTABLE(${the_target} ${OPENCV_TEST_${the_module}_SOURCES})
19-
ocv_target_link_libraries(${the_target} ${test_deps} ${OPENCV_LINKER_LIBS} ${CUDA_LIBRARIES})
19+
ocv_target_link_libraries(${the_target} LINK_PRIVATE
20+
${test_deps} ${OPENCV_LINKER_LIBS} ${CUDA_LIBRARIES}
21+
)
2022
add_dependencies(opencv_tests ${the_target})
2123

2224
set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL}")

modules/highgui/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ if(MSVC)
147147
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
148148
endif()
149149

150-
if(NOT BUILD_opencv_world)
151-
#stop automatic dependencies propagation for this module
152-
set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "")
153-
endif()
154-
155150
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
156151
endmacro()
157152

modules/imgcodecs/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ if(MSVC)
123123
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
124124
endif()
125125

126-
#stop automatic dependencies propagation for this module
127-
set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "")
128-
129126
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
130127
endmacro()
131128

modules/java/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,14 @@ if(BUILD_FAT_JAVA_LIB)
435435
endif()
436436
if(APPLE)
437437
foreach(_dep ${__deps})
438-
ocv_target_link_libraries(${the_module} -Wl,-force_load "${_dep}")
438+
ocv_target_link_libraries(${the_module} LINK_PRIVATE -Wl,-force_load "${_dep}")
439439
endforeach()
440440
else()
441-
ocv_target_link_libraries(${the_module} -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive)
441+
ocv_target_link_libraries(${the_module} LINK_PRIVATE -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive)
442442
endif()
443-
ocv_target_link_libraries(${the_module} ${__extradeps} ${OPENCV_LINKER_LIBS})
443+
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${__extradeps} ${OPENCV_LINKER_LIBS})
444444
else()
445-
ocv_target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS})
445+
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS})
446446
endif()
447447
448448
# Additional target properties
@@ -451,12 +451,12 @@ set_target_properties(${the_module} PROPERTIES
451451
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
452452
LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
453453
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
454-
LINK_INTERFACE_LIBRARIES ""
455454
)
456455
457456
if(ANDROID)
458-
ocv_target_link_libraries(${the_module} jnigraphics) # for Mat <=> Bitmap converters
459-
ocv_target_link_libraries(${the_module} LINK_INTERFACE_LIBRARIES ${OPENCV_LINKER_LIBS} jnigraphics)
457+
ocv_target_link_libraries(${the_module} LINK_PUBLIC jnigraphics) # for Mat <=> Bitmap converters
458+
ocv_target_link_libraries(${the_module} LINK_PUBLIC log dl z)
459+
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_LINKER_LIBS})
460460
461461
# force strip library after the build command
462462
# because samples and tests will make a copy of the library before install

modules/python/common.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ if(APPLE)
7272
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
7373
elseif(WIN32 OR OPENCV_FORCE_PYTHON_LIBS)
7474
if(${PYTHON}_DEBUG_LIBRARIES AND NOT ${PYTHON}_LIBRARIES MATCHES "optimized.*debug")
75-
ocv_target_link_libraries(${the_module} debug ${${PYTHON}_DEBUG_LIBRARIES} optimized ${${PYTHON}_LIBRARIES})
75+
ocv_target_link_libraries(${the_module} LINK_PRIVATE debug ${${PYTHON}_DEBUG_LIBRARIES} optimized ${${PYTHON}_LIBRARIES})
7676
else()
77-
ocv_target_link_libraries(${the_module} ${${PYTHON}_LIBRARIES})
77+
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${${PYTHON}_LIBRARIES})
7878
endif()
7979
endif()
80-
ocv_target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS})
80+
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_MODULE_${the_module}_DEPS})
8181

8282
if(DEFINED ${PYTHON}_CVPY_SUFFIX)
8383
set(CVPY_SUFFIX "${${PYTHON}_CVPY_SUFFIX}")

0 commit comments

Comments
 (0)