diff --git a/cmake/OpenCVDetectCUDA.cmake b/cmake/OpenCVDetectCUDA.cmake index 98a00fdd87a190e5d0b2dc0db62609cfaef6a52a..37a77cd66071331cdeafddb29a12d7d4d8ed5c1e 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 f7656e9d7122b3310c9830982937140267e45e94..9a42bfa3d16a3ad92296772be453001817f0479d 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 802e65a92ccc64694a5940562e87482dda2da953..4dd776162049e33b49afe23bc3553d976d8ccee1 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 3ff06a67ed1afa72f61abadda25a91b3352f3163..f7fe7ad57dc2d0f71077d67dcc9e7f6293111728 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 728924fa61d56b0d30f54860a2b1b23f653270af..e453d9019715352a3d327b5b183add922db028cf 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 30878caa7bb1042dd85091ed428cfccf750a2564..46caccaf83f7895b0de81cff2fdf3961d258e453 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 5bd0f96562945e322b88669ffc56f854cca76b85..03fff8e96ae9277586971c74d36708606160f366 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