Skip to content

Commit d91a515

Browse files
committed
Don't include the cuda.hpp header when CUDA is not enabled
1 parent f0b22ed commit d91a515

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static SUPPORTED_MODULES: [SupportedModule; 73] = [
139139
SupportedModule::XStereo,
140140
];
141141

142-
static SUPPORTED_INHERENT_FEATURES: [&str; 2] = ["hfloat", "opencl"];
142+
static SUPPORTED_INHERENT_FEATURES: [&str; 3] = ["hfloat", "opencl", "cuda"];
143143

144144
/// The contents of these vars will be present in the debug log, but will not cause the source rebuild
145145
static DEBUG_ENV_VARS: [&str; 1] = ["PATH"];

src/manual/core.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub use vector::*;
2020
mod affine3;
2121
mod data_type;
2222
mod directx;
23+
#[cfg(ocvrs_has_inherent_feature_cuda)]
2324
mod gpumat;
2425
mod inplace;
2526
mod input_output_array;

src_cpp/core.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include <opencv2/core/va_intel.hpp>
1010
#include <opencv2/core/directx.hpp>
1111
#endif
12-
#include <opencv2/core/cuda.hpp>
12+
#ifdef HAVE_CUDA
13+
#include <opencv2/core/cuda.hpp>
14+
#endif
1315
#if (CV_VERSION_MAJOR == 3 && CV_VERSION_MINOR == 4 && CV_VERSION_REVISION >= 4) /* 3.4.4+ */ \
1416
|| (CV_VERSION_MAJOR == 4) /* 4.0+ */ \
1517
|| (CV_VERSION_MAJOR == 5) /* 5.0+ */

src_cpp/photo.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#include "ocvrs_common.hpp"
22
#include <opencv2/photo.hpp>
3-
#include <opencv2/photo/cuda.hpp>
3+
#ifdef HAVE_CUDA
4+
#include <opencv2/photo/cuda.hpp>
5+
#endif

src_cpp/stitching.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "ocvrs_common.hpp"
2+
3+
#ifndef HAVE_CUDA
4+
// <opencv2/stitching.hpp> unconditionally includes a bunch of CUDA stuff without a proper way to disable it. That creates an
5+
// issue as we don't generate GpuMat when HAVE_CUDA is not defined. A workaround is a couple of hacks that prevent the forced
6+
// inclusion of <opencv2/core/cuda.hpp> and generation of functions that have GpuMat arguments.
7+
8+
// prevent forced inclusion of the <opencv2/core/cuda.hpp> header
9+
#define OPENCV_CORE_CUDA_HPP
10+
11+
// generate a minimal stub for GpuMat so that C++ code compiles, but because of the missing export macro the bindings for the
12+
// functions using this type will not be generated
13+
namespace cv {
14+
namespace cuda {
15+
class GpuMat {
16+
public:
17+
void upload(InputArray arr);
18+
void download(OutputArray dst) const;
19+
};
20+
}
21+
}
22+
#endif
23+
24+
#include <opencv2/stitching.hpp>

src_cpp/xfeatures2d.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#include "ocvrs_common.hpp"
22
#include <opencv2/xfeatures2d.hpp>
3-
#include <opencv2/xfeatures2d/cuda.hpp>
3+
#ifdef HAVE_CUDA
4+
#include <opencv2/xfeatures2d/cuda.hpp>
5+
#endif

0 commit comments

Comments
 (0)