diff --git a/cmake/OpenCVDetectCUDA.cmake b/cmake/OpenCVDetectCUDA.cmake index 98a00fdd87..37a77cd660 100644 --- a/cmake/OpenCVDetectCUDA.cmake +++ b/cmake/OpenCVDetectCUDA.cmake @@ -38,11 +38,30 @@ if(CUDA_FOUND) endif() if(WITH_NVCUVID) + macro(SEARCH_NVCUVID_HEADER _filename _result) + # place header file under CUDA_TOOLKIT_TARGET_DIR or CUDA_TOOLKIT_ROOT_DIR + find_path(_header_result + ${_filename} + PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}" + ENV CUDA_PATH + ENV CUDA_INC_PATH + PATH_SUFFIXES include + NO_DEFAULT_PATH + ) + if("x${_header_result}" STREQUAL "x_header_result-NOTFOUND") + set(${_result} 0) + else() + set(${_result} 1) + endif() + endmacro() + SEARCH_NVCUVID_HEADER("nvcuvid.h" HAVE_NVCUVID_HEADER) + SEARCH_NVCUVID_HEADER("dynlink_nvcuvid.h" HAVE_DYNLINK_NVCUVID_HEADER) find_cuda_helper_libs(nvcuvid) if(WIN32) find_cuda_helper_libs(nvcuvenc) endif() - if(CUDA_nvcuvid_LIBRARY) + if(CUDA_nvcuvid_LIBRARY AND (${HAVE_NVCUVID_HEADER} OR ${HAVE_DYNLINK_NVCUVID_HEADER})) + # make sure to have both header and library before enabling set(HAVE_NVCUVID 1) endif() if(CUDA_nvcuvenc_LIBRARY) diff --git a/cmake/templates/cvconfig.h.in b/cmake/templates/cvconfig.h.in index f7656e9d71..9a42bfa3d1 100644 --- a/cmake/templates/cvconfig.h.in +++ b/cmake/templates/cvconfig.h.in @@ -127,6 +127,8 @@ /* NVIDIA Video Decoding API*/ #cmakedefine HAVE_NVCUVID +#cmakedefine HAVE_NVCUVID_HEADER +#cmakedefine HAVE_DYNLINK_NVCUVID_HEADER /* NVIDIA Video Encoding API*/ #cmakedefine HAVE_NVCUVENC diff --git a/modules/cudacodec/src/cuvid_video_source.hpp b/modules/cudacodec/src/cuvid_video_source.hpp index 802e65a92c..4dd7761620 100644 --- a/modules/cudacodec/src/cuvid_video_source.hpp +++ b/modules/cudacodec/src/cuvid_video_source.hpp @@ -44,9 +44,9 @@ #ifndef __CUVID_VIDEO_SOURCE_HPP__ #define __CUVID_VIDEO_SOURCE_HPP__ -#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000 +#if defined(HAVE_DYNLINK_NVCUVID_HEADER) #include -#else +#elif defined(HAVE_NVCUVID_HEADER) #include #endif #include "opencv2/core/private.cuda.hpp" diff --git a/modules/cudacodec/src/frame_queue.hpp b/modules/cudacodec/src/frame_queue.hpp index 3ff06a67ed..f7fe7ad57d 100644 --- a/modules/cudacodec/src/frame_queue.hpp +++ b/modules/cudacodec/src/frame_queue.hpp @@ -47,9 +47,9 @@ #include "opencv2/core/utility.hpp" #include "opencv2/core/private.cuda.hpp" -#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000 +#if defined(HAVE_DYNLINK_NVCUVID_HEADER) #include -#else +#elif defined(HAVE_NVCUVID_HEADER) #include #endif diff --git a/modules/cudacodec/src/precomp.hpp b/modules/cudacodec/src/precomp.hpp index 728924fa61..e453d90197 100644 --- a/modules/cudacodec/src/precomp.hpp +++ b/modules/cudacodec/src/precomp.hpp @@ -56,9 +56,9 @@ #include "opencv2/core/private.cuda.hpp" #ifdef HAVE_NVCUVID - #if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000 + #if defined(HAVE_DYNLINK_NVCUVID_HEADER) #include - #else + #elif defined(HAVE_NVCUVID_HEADER) #include #endif diff --git a/modules/cudacodec/src/video_decoder.hpp b/modules/cudacodec/src/video_decoder.hpp index 30878caa7b..46caccaf83 100644 --- a/modules/cudacodec/src/video_decoder.hpp +++ b/modules/cudacodec/src/video_decoder.hpp @@ -44,9 +44,9 @@ #ifndef __VIDEO_DECODER_HPP__ #define __VIDEO_DECODER_HPP__ -#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000 +#if defined(HAVE_DYNLINK_NVCUVID_HEADER) #include -#else +#elif defined(HAVE_NVCUVID_HEADER) #include #endif diff --git a/modules/cudacodec/src/video_parser.hpp b/modules/cudacodec/src/video_parser.hpp index 5bd0f96562..03fff8e96a 100644 --- a/modules/cudacodec/src/video_parser.hpp +++ b/modules/cudacodec/src/video_parser.hpp @@ -44,9 +44,9 @@ #ifndef __VIDEO_PARSER_HPP__ #define __VIDEO_PARSER_HPP__ -#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000 +#if defined(HAVE_DYNLINK_NVCUVID_HEADER) #include -#else +#elif defined(HAVE_NVCUVID_HEADER) #include #endif