title: CMake Error ...: DNN: CUDA backend requires CUDA Toolkit. Please resolve dependency or disable OPENCV_DNN_CUDA=OFF
body: <p>Here is the error I am getting when I am compiling OpenCV on ubuntu 20.04 with cuda 10.1.</p>
  <pre><code>-- Detected processor: x86_64
  CMake Warning at cmake/OpenCVUtils.cmake:721 (message):
    Unexpected option: WITH_CUBLAS (=ON)
  
    Condition: IF (WITH_CUDA)
  Call Stack (most recent call first):
    CMakeLists.txt:249 (OCV_OPTION)
  
  
  CMake Warning at cmake/OpenCVUtils.cmake:721 (message):
    Unexpected option: WITH_CUDNN (=ON)
  
    Condition: IF (WITH_CUDA)
  Call Stack (most recent call first):
    CMakeLists.txt:252 (OCV_OPTION)
  
  
  -- Looking for ccache - not found
  -- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found suitable version &quot;1.2.11&quot;, minimum required is &quot;1.2.3&quot;) 
  -- Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version &gt;= 2.3.1)
  -- Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR) 
  -- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version &quot;1.2.11&quot;) 
  -- Found OpenEXR: /usr/lib/x86_64-linux-gnu/libIlmImf.so
  -- found Intel IPP (ICV version): 2020.0.0 [2020.0.0 Gold]
  -- at: /home/murat/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
  -- found Intel IPP Integration Wrappers sources: 2020.0.0
  -- at: /home/murat/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
  -- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
  -- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
  -- Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR) 
  -- A library with LAPACK API found.
  -- OpenCV Python: during development append to PYTHONPATH: /home/murat/opencv/build/python_loader
  -- Caffe:   NO
  -- Protobuf:   NO
  -- Glog:   YES
  -- freetype2:   YES (ver 23.1.17)
  -- harfbuzz:    YES (ver 2.6.4)
  -- HDF5: Using hdf5 compiler wrapper to determine C configuration
  -- Julia not found. Not compiling Julia Bindings. 
  -- Module opencv_ovis disabled because OGRE3D was not found
  -- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
  -- Found installed version of gflags: /usr/lib/x86_64-linux-gnu/cmake/gflags
  -- Detected gflags version: 2.2.2
  -- Checking SFM deps... TRUE
  -- CERES support is disabled. Ceres Solver for reconstruction API is required.
  -- Checking for module 'tesseract'
  --   No package 'tesseract' found
  -- Tesseract:   NO
  -- Allocator metrics storage type: 'long long'
  -- HDF5: Using hdf5 compiler wrapper to determine C configuration
  CMake Error at modules/dnn/CMakeLists.txt:35 (message):
    DNN: CUDA backend requires CUDA Toolkit.  Please resolve dependency or
    disable OPENCV_DNN_CUDA=OFF
  
  -- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /home/murat/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
  -- opencv_dnn: filter out cuda4dnn source code
  -- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
  -- Found installed version of gflags: /usr/lib/x86_64-linux-gnu/cmake/gflags
  -- Detected gflags version: 2.2.2
  -- Checking SFM deps... TRUE
  -- CERES support is disabled. Ceres Solver for reconstruction API is required.
  -- 
  -- General configuration for OpenCV 4.4.0 =====================================
  --   Version control:               unknown
  -- 
  --   Extra modules:
  --     Location (extra):            /home/murat/opencv_contrib/modules
  --     Version control (extra):     unknown
  -- 
  --   Platform:
  --     Timestamp:                   2021-02-18T12:05:50Z
  --     Host:                        Linux 5.8.0-43-generic x86_64
  --     CMake:                       3.16.3
  --     CMake generator:             Unix Makefiles
  --     CMake build tool:            /usr/bin/make
  --     Configuration:               RELEASE
  -- 
  --   CPU/HW features:
  --     Baseline:                    SSE SSE2 SSE3
  --       requested:                 SSE3
  --     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
  --       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
  --       SSE4_1 (15 files):         + SSSE3 SSE4_1
  --       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
  --       FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
  --       AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
  --       AVX2 (29 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
  --       AVX512_SKX (4 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
  -- 
  --   C/C++:
  --     Built as dynamic libs?:      YES
  --     C++ standard:                11
  --     C++ Compiler:                /usr/bin/c++  (ver 9.3.0)
  --     C++ flags (Release):         -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
  --     C++ flags (Debug):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
  --     C Compiler:                  /usr/bin/cc
  --     C flags (Release):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
  --     C flags (Debug):             -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
  --     Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed  
  --     Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed  
  --     ccache:                      NO
  --     Precompiled headers:         NO
  --     Extra dependencies:          dl m pthread rt
  --     3rdparty dependencies:
  -- 
  --   OpenCV modules:
  --     To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
  --     Disabled:                    world
  --     Disabled by dependency:      -
  --     Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv java js julia matlab ovis python2 viz
  --     Applications:                perf_tests apps
  --     Documentation:               NO
  --     Non-free algorithms:         YES
  -- 
  --   GUI: 
  --     GTK+:                        YES (ver 3.24.20)
  --       GThread :                  YES (ver 2.64.6)
  --       GtkGlExt:                  NO
  --     OpenGL support:              NO
  -- 
  --   Media I/O: 
  --     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
  --     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
  --     WEBP:                        build (ver encoder: 0x020f)
  --     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
  --     TIFF:                        build (ver 42 - 4.0.10)
  --     JPEG 2000:                   build Jasper (ver 1.900.1)
  --     OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2_3)
  --     HDR:                         YES
  --     SUNRASTER:                   YES
  --     PXM:                         YES
  --     PFM:                         YES
  -- 
  --   Video I/O:
  --     DC1394:                      YES (2.2.5)
  --     FFMPEG:                      YES
  --       avcodec:                   YES (58.54.100)
  --       avformat:                  YES (58.29.100)
  --       avutil:                    YES (56.31.100)
  --       swscale:                   YES (5.5.100)
  --       avresample:                YES (4.0.0)
  --     GStreamer:                   YES (1.16.2)
  --     v4l/v4l2:                    YES (linux/videodev2.h)
  -- 
  --   Parallel framework:            TBB (ver 2020.2 interface 11102)
  -- 
  --   Trace:                         YES (with Intel ITT)
  -- 
  --   Other third-party libraries:
  --     Intel IPP:                   2020.0.0 Gold [2020.0.0]
  --            at:                   /home/murat/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
  --     Intel IPP IW:                sources (2020.0.0)
  --               at:                /home/murat/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
  --     Lapack:                      NO
  --     Eigen:                       YES (ver 3.3.7)
  --     Custom HAL:                  NO
  --     Protobuf:                    build (3.5.1)
  -- 
  --   cuDNN:                         NO
  -- 
  --   OpenCL:                        YES (no extra features)
  --     Include path:                /home/murat/opencv/3rdparty/include/opencl/1.2
  --     Link libraries:              Dynamic load
  -- 
  --   Python 3:
  --     Interpreter:                 /usr/bin/python3 (ver 3.8.5)
  --     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.8.so (ver 3.8.5)
  --     numpy:                       /home/murat/.local/lib/python3.8/site-packages/numpy/core/include (ver 1.18.5)
  --     install path:                lib/python3.8/dist-packages/cv2/python-3.8
  -- 
  --   Python (for build):            /usr/bin/python3
  -- 
  --   Java:                          
  --     ant:                         NO
  --     JNI:                         /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include
  --     Java wrappers:               NO
  --     Java tests:                  NO
  -- 
  --   Install to:                    /usr/local
  -- -----------------------------------------------------------------
  -- 
  -- Configuring incomplete, errors occurred!
  See also &quot;/home/murat/opencv/build/CMakeFiles/CMakeOutput.log&quot;.
  See also &quot;/home/murat/opencv/build/CMakeFiles/CMakeError.log&quot;.
  </code></pre>
  <p>Here are my cmake flags:</p>
  <pre><code>cmake -D CMAKE_BUILD_TYPE=RELEASE 
  -D CMAKE_INSTALL_PREFIX=/usr/local 
  -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules 
  -D BUILD_TIFF=ON 
  -D WITH_FFMPEG=ON 
  -D WITH_GSTREAMER=ON 
  -D WITH_TBB=ON 
  -D BUILD_TBB=ON 
  -D WITH_EIGEN=ON 
  -D WITH_V4L=ON 
  -D WITH_LIBV4L=ON 
  -D WITH_VTK=OFF 
  -D WITH_QT=OFF 
  -D WITH_OPENGL=ON 
  -D OPENCV_ENABLE_NONFREE=ON 
  -D INSTALL_C_EXAMPLES=OFF 
  -D INSTALL_PYTHON_EXAMPLES=OFF 
  -D BUILD_NEW_PYTHON_SUPPORT=ON 
  -D OPENCV_GENERATE_PKGCONFIG=ON 
  -D BUILD_TESTS=OFF
  
  -D OPENCV_DNN_CUDA=ON 
  -D ENABLE_FAST_MATH=ON 
  -D CUDA_FAST_MATH=ON 
  -D CUDA_ARCH_BIN=7.0 
  -D WITH_CUBLAS=ON 
  -D WITH_CUDNN=ON 
  -D CUDNN_LIBRARY=/usr/lib/cuda/lib64/libcudnn.so.7.6.5 
  -D CUDNN_INCLUDE_DIR=/usr/lib/cuda/include 
  -D BUILD_EXAMPLES=OFF 
  -D PYTHON_DEFAULT_EXECUTABLE=$(which python3) ..
  </code></pre>
  <p>It works perfectly with the option <code>-D OPENCV_DNN_CUDA=OFF</code>. But I need CUDA libraries. My CUDA and CUDNN paths are correct, so I have no idea what is wrong with the cmake compilation. Did anyone face with a similar problem when installing opencv?</p>
  <p>Note: I am following this <a href="https://qengineering.eu/install-caffe-on-ubuntu-20.04-with-opencv-4.4.html" rel="nofollow noreferrer">link</a> to finally install caffe.</p>
  <pre><code>$ nvcc -V
  nvcc: NVIDIA (R) Cuda compiler driver
  Copyright (c) 2005-2019 NVIDIA Corporation
  Built on Sun_Jul_28_19:07:16_PDT_2019
  Cuda compilation tools, release 10.1, V10.1.243
  </code></pre>