Skip to content

Commit 6152158

Browse files
committed
Add conditional compilation macros for inherent features
1 parent d1f4513 commit 6152158

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// Conditional compilation macro based on whether OpenCV was built with the OPENCV_INHERENT_FEATURE feature
2+
///
3+
/// This macro is intended for usage in external crates.
4+
///
5+
/// # Example
6+
/// ```
7+
/// let mut cuda_available = false;
8+
/// opencv::opencv_has_inherent_feature_cuda! {
9+
/// cuda_available = true;
10+
/// }
11+
/// if !cuda_available {
12+
/// panic!("CUDA is required");
13+
/// }
14+
/// ```
15+
#[cfg(ocvrs_has_inherent_feature_OPENCV_INHERENT_FEATURE)]
16+
#[macro_export]
17+
macro_rules! opencv_has_inherent_feature_OPENCV_INHERENT_FEATURE {
18+
($($tt:tt)*) => { $($tt)* }
19+
}
20+
21+
/// Conditional compilation macro based on whether OpenCV was built with the OPENCV_INHERENT_FEATURE feature
22+
///
23+
/// This macro is intended for usage in external crates.
24+
///
25+
/// # Example
26+
/// ```
27+
/// let mut cuda_available = false;
28+
/// opencv::opencv_has_inherent_feature_cuda! {
29+
/// cuda_available = true;
30+
/// }
31+
/// if !cuda_available {
32+
/// panic!("CUDA is required");
33+
/// }
34+
/// ```
35+
#[cfg(not(ocvrs_has_inherent_feature_OPENCV_INHERENT_FEATURE))]
36+
#[macro_export]
37+
macro_rules! opencv_has_inherent_feature_OPENCV_INHERENT_FEATURE {
38+
($($tt:tt)*) => {};
39+
}

build/generator.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use collector::Collector;
1111
use opencv_binding_generator::{Generator, IteratorExt, SupportedModule};
1212

1313
use super::docs::transfer_bindings_to_docs;
14-
use super::{files_with_predicate, Library, Result, OUT_DIR, SRC_CPP_DIR, SRC_DIR, SUPPORTED_MODULES, SUPPORTED_OPENCV_BRANCHES};
14+
use super::{
15+
files_with_predicate, Library, Result, OUT_DIR, SRC_CPP_DIR, SRC_DIR, SUPPORTED_INHERENT_FEATURES, SUPPORTED_MODULES,
16+
SUPPORTED_OPENCV_BRANCHES,
17+
};
1518

1619
#[path = "generator/collector.rs"]
1720
mod collector;
@@ -71,6 +74,7 @@ impl<'r> BindingGenerator<'r> {
7174
.collect_bindings()?;
7275
self.generate_opencv_branch_cond_macros()?;
7376
self.generate_opencv_module_cond_macros()?;
77+
self.generate_opencv_inherent_feature_cond_macros()?;
7478

7579
if let Some(target_docs_dir) = target_docs_dir {
7680
if !target_docs_dir.exists() {
@@ -102,6 +106,21 @@ impl<'r> BindingGenerator<'r> {
102106
Ok(())
103107
}
104108

109+
fn generate_opencv_inherent_feature_cond_macros(&self) -> Result<()> {
110+
static COND_MACRO_TPL: &str = include_str!("cond_macros/opencv_inherent_feature.rs");
111+
112+
let mut cond_macros_file = BufWriter::new(File::options().append(true).open(OUT_DIR.join("opencv/cond_macros.rs"))?);
113+
for inherent_feature in SUPPORTED_INHERENT_FEATURES {
114+
write_replace(
115+
COND_MACRO_TPL,
116+
"OPENCV_INHERENT_FEATURE",
117+
inherent_feature,
118+
&mut cond_macros_file,
119+
)?;
120+
}
121+
Ok(())
122+
}
123+
105124
fn run(&self, opencv_header_dir: &Path, opencv: &Library) -> Result<()> {
106125
let additional_include_dirs = opencv
107126
.include_paths

0 commit comments

Comments
 (0)