set(CUDA_cufft_LIBRARY_ABS ${CUDA_cufft_LIBRARY})
ocv_convert_to_lib_name(CUDA_cufft_LIBRARY ${CUDA_cufft_LIBRARY})
endif()
+
+ if(CMAKE_GENERATOR MATCHES "Visual Studio"
+ AND NOT OPENCV_SKIP_CUDA_CMAKE_SUPPRESS_REGENERATION
+ )
+ message(WARNING "CUDA with MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake manually if updates are required.")
+ set(CMAKE_SUPPRESS_REGENERATION ON)
+ endif()
endif()
+
+
+# ----------------------------------------------------------------------------
+# Add CUDA libraries (needed for apps/tools, samples)
+# ----------------------------------------------------------------------------
+if(HAVE_CUDA)
+ # details: https://github.com/NVIDIA/nvidia-docker/issues/775
+ if(" ${CUDA_CUDA_LIBRARY}" MATCHES "/stubs/libcuda.so" AND NOT OPENCV_SKIP_CUDA_STUB_WORKAROUND)
+ set(CUDA_STUB_ENABLED_LINK_WORKAROUND 1)
+ if(EXISTS "${CUDA_CUDA_LIBRARY}" AND NOT OPENCV_SKIP_CUDA_STUB_WORKAROUND_RPATH_LINK)
+ set(CUDA_STUB_TARGET_PATH "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${CUDA_CUDA_LIBRARY}" "${CUDA_STUB_TARGET_PATH}/libcuda.so.1"
+ RESULT_VARIABLE CUDA_STUB_SYMLINK_RESULT)
+ if(NOT CUDA_STUB_SYMLINK_RESULT EQUAL 0)
+ execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CUDA_CUDA_LIBRARY}" "${CUDA_STUB_TARGET_PATH}/libcuda.so.1"
+ RESULT_VARIABLE CUDA_STUB_COPY_RESULT)
+ if(NOT CUDA_STUB_COPY_RESULT EQUAL 0)
+ set(CUDA_STUB_ENABLED_LINK_WORKAROUND 0)
+ endif()
+ endif()
+ if(CUDA_STUB_ENABLED_LINK_WORKAROUND)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath-link,\"${CUDA_STUB_TARGET_PATH}\"")
+ endif()
+ else()
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-shlib-undefined")
+ endif()
+ if(NOT CUDA_STUB_ENABLED_LINK_WORKAROUND)
+ message(WARNING "CUDA: workaround for stubs/libcuda.so.1 is not applied")
+ endif()
+ endif()
+
+ set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
+ if(HAVE_CUBLAS)
+ set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_cublas_LIBRARY})
+ endif()
+ if(HAVE_CUDNN)
+ set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDNN_LIBRARIES})
+ endif()
+ if(HAVE_CUFFT)
+ set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_cufft_LIBRARY})
+ endif()
+ foreach(p ${CUDA_LIBS_PATH})
+ if(MSVC AND CMAKE_GENERATOR MATCHES "Ninja|JOM")
+ set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CMAKE_LIBRARY_PATH_FLAG}"${p}")
+ else()
+ set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CMAKE_LIBRARY_PATH_FLAG}${p})
+ endif()
+ endforeach()
+endif()