Skip to content

Commit

Permalink
Fixes opencv#23187 (part 1)
Browse files Browse the repository at this point in the history
Supports delay-loading for Ninja generators and Python bindings.
  • Loading branch information
CSBVision committed Feb 7, 2023
1 parent a6b178a commit 6ea2253
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cmake/OpenCVDetectCUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ if(CUDA_FOUND)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --use_fast_math)
endif()

OCV_OPTION(CUDA_ENABLE_DELAYLOAD "Enable delayed loading of CUDA DLLs" OFF VISIBLE_IF MSVC AND (CMAKE_GENERATOR MATCHES "Visual Studio"))
OCV_OPTION(CUDA_ENABLE_DELAYLOAD "Enable delayed loading of CUDA DLLs" OFF VISIBLE_IF MSVC)

mark_as_advanced(CUDA_BUILD_CUBIN CUDA_BUILD_EMULATION CUDA_VERBOSE_BUILD CUDA_SDK_ROOT_DIR)

Expand Down Expand Up @@ -565,13 +565,17 @@ if(HAVE_CUDA)
endforeach()

if(MSVC AND CUDA_ENABLE_DELAYLOAD)
set(DELAYFLAGS "delayimp.lib")
file(GLOB CUDA_DLLS "${CUDA_TOOLKIT_ROOT_DIR}/bin/*.dll")
foreach(d ${CUDA_DLLS})
cmake_path(GET "d" FILENAME DLL_NAME)
if(NOT ${DLL_NAME} MATCHES "cudart")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DELAYLOAD:${DLL_NAME}")
set(DELAYFLAGS "${DELAYFLAGS} /DELAYLOAD:${DLL_NAME}")
endif()
endforeach()
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /IGNORE:4199")
set(DELAYFLAGS "${DELAYFLAGS} /DELAYLOAD:nvcuda.dll /DELAYLOAD:nvml.dll /IGNORE:4199")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${DELAYFLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${DELAYFLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${DELAYFLAGS}")
endif()
endif()

0 comments on commit 6ea2253

Please sign in to comment.