diff --git a/modules/core/include/opencv2/core/private.cuda.hpp b/modules/core/include/opencv2/core/private.cuda.hpp index 4250f61033..c087ee8028 100644 --- a/modules/core/include/opencv2/core/private.cuda.hpp +++ b/modules/core/include/opencv2/core/private.cuda.hpp @@ -54,6 +54,7 @@ #include "opencv2/core/base.hpp" #include "opencv2/core/cuda.hpp" +#include "opencv2/core/private/cuda_stubs.hpp" #ifdef HAVE_CUDA # include @@ -101,16 +102,10 @@ namespace cv { namespace cuda { CV_EXPORTS void syncOutput(const GpuMat& dst, OutputArray _dst, Stream& stream); }} -#ifndef HAVE_CUDA - -static inline CV_NORETURN void throw_no_cuda() { CV_Error(cv::Error::GpuNotSupported, "The library is compiled without CUDA support"); } - -#else // HAVE_CUDA +#ifdef HAVE_CUDA #define nppSafeSetStream(oldStream, newStream) { if(oldStream != newStream) { cudaStreamSynchronize(oldStream); nppSetStream(newStream); } } -static inline CV_NORETURN void throw_no_cuda() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); } - namespace cv { namespace cuda { static inline void checkNppError(int code, const char* file, const int line, const char* func) diff --git a/modules/core/include/opencv2/core/private/cuda_stubs.hpp b/modules/core/include/opencv2/core/private/cuda_stubs.hpp new file mode 100644 index 0000000000..478a9fdd20 --- /dev/null +++ b/modules/core/include/opencv2/core/private/cuda_stubs.hpp @@ -0,0 +1,21 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_PRIVATE_CUDA_STUBS_HPP +#define OPENCV_CORE_PRIVATE_CUDA_STUBS_HPP + +#ifndef __OPENCV_BUILD +# error this is a private header which should not be used from outside of the OpenCV library +#endif + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/base.hpp" + +#ifndef HAVE_CUDA +static inline CV_NORETURN void throw_no_cuda() { CV_Error(cv::Error::GpuNotSupported, "The library is compiled without CUDA support"); } +#else +static inline CV_NORETURN void throw_no_cuda() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); } +#endif + +#endif // OPENCV_CORE_PRIVATE_CUDA_STUBS_HPP diff --git a/modules/photo/CMakeLists.txt b/modules/photo/CMakeLists.txt index 34e3741601..f65cf9e678 100644 --- a/modules/photo/CMakeLists.txt +++ b/modules/photo/CMakeLists.txt @@ -5,3 +5,7 @@ if(HAVE_CUDA) endif() ocv_define_module(photo opencv_imgproc OPTIONAL opencv_cudaarithm opencv_cudaimgproc WRAP java objc python js) + +if(HAVE_CUDA AND ENABLE_CUDA_FIRST_CLASS_LANGUAGE AND HAVE_OPENCV_CUDAARITHM AND HAVE_OPENCV_CUDAIMGPROC) + ocv_target_link_libraries(${the_module} PUBLIC "CUDA::cudart${CUDA_LIB_EXT}") +endif() diff --git a/modules/photo/src/denoising.cuda.cpp b/modules/photo/src/denoising.cuda.cpp index 7ea37f6951..d9e265cda9 100644 --- a/modules/photo/src/denoising.cuda.cpp +++ b/modules/photo/src/denoising.cuda.cpp @@ -43,7 +43,6 @@ #include "precomp.hpp" #include "opencv2/photo/cuda.hpp" -#include "opencv2/core/private.cuda.hpp" #include "opencv2/opencv_modules.hpp" @@ -60,12 +59,15 @@ using namespace cv::cuda; #if !defined (HAVE_CUDA) || !defined(HAVE_OPENCV_CUDAARITHM) || !defined(HAVE_OPENCV_CUDAIMGPROC) +#include "opencv2/core/private/cuda_stubs.hpp" void cv::cuda::nonLocalMeans(InputArray, OutputArray, float, int, int, int, Stream&) { throw_no_cuda(); } void cv::cuda::fastNlMeansDenoising(InputArray, OutputArray, float, int, int, Stream&) { throw_no_cuda(); } void cv::cuda::fastNlMeansDenoisingColored(InputArray, OutputArray, float, float, int, int, Stream&) { throw_no_cuda(); } #else +#include "opencv2/core/private.cuda.hpp" + ////////////////////////////////////////////////////////////////////////////////// //// Non Local Means Denosing (brute force) diff --git a/modules/stitching/CMakeLists.txt b/modules/stitching/CMakeLists.txt index 44f35eb59b..e488369de8 100644 --- a/modules/stitching/CMakeLists.txt +++ b/modules/stitching/CMakeLists.txt @@ -11,3 +11,7 @@ endif() ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_flann OPTIONAL opencv_cudaarithm opencv_cudawarping opencv_cudafeatures2d opencv_cudalegacy opencv_cudaimgproc ${STITCHING_CONTRIB_DEPS} WRAP python) + +if(HAVE_CUDA AND ENABLE_CUDA_FIRST_CLASS_LANGUAGE) + ocv_target_link_libraries(${the_module} PUBLIC "CUDA::cudart${CUDA_LIB_EXT}") +endif()