Skip to content

Commit 3bd6b55

Browse files
committed
Pass OCVRS_TARGET_OS_WINDOWS from the build script
1 parent 485ab65 commit 3bd6b55

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

binding-generator/src/settings/func_cfg_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::collections::HashMap;
22

33
use crate::func::FuncMatcher;
44

5-
pub const CFG_ATTR_NOT_ON_WINDOWS: (&str, &str) = ("not(target_os = \"windows\")", "!defined(OCVRS_TARGET_OS_WINDOWS)");
6-
pub const CFG_ATTR_ONLY_OPENCV_5: (&str, &str) = ("ocvrs_opencv_branch_5", "CV_VERSION_MAJOR == 5");
5+
pub const CFG_ATTR_NOT_ON_WINDOWS: (&str, &str) = (r#"not(target_os = "windows")"#, r#"(!OCVRS_TARGET_OS_WINDOWS)"#);
6+
pub const CFG_ATTR_ONLY_OPENCV_5: (&str, &str) = ("ocvrs_opencv_branch_5", "(CV_VERSION_MAJOR == 5)");
77

88
pub type FuncCfgAttr = FuncMatcher<'static, (&'static str, &'static str)>;
99

build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,18 @@ fn make_compiler(opencv: &Library, ffi_export_suffix: &str) -> cc::Build {
278278
out.flag_if_supported("-Wa,-mbig-obj");
279279
}
280280
out.define("OCVRS_FFI_EXPORT_SUFFIX", ffi_export_suffix);
281+
out.define("OCVRS_TARGET_OS_WINDOWS", target_os_windows());
281282
out
282283
}
283284

285+
fn target_os_windows() -> &'static str {
286+
if env::var("CARGO_CFG_TARGET_OS").expect("Can't read CARGO_CFG_TARGET_OS env var") == "windows" {
287+
"1"
288+
} else {
289+
"0"
290+
}
291+
}
292+
284293
fn setup_rerun() -> Result<()> {
285294
for &v in AFFECTING_ENV_VARS.iter() {
286295
println!("cargo::rerun-if-env-changed={v}");

src_cpp/ocvrs_common.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818

1919
#include <opencv2/core.hpp>
2020

21-
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) \
22-
|| defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
23-
#define OCVRS_TARGET_OS_WINDOWS
24-
#endif
25-
2621
#define OCVRS_ONLY_DEPENDENT_TYPES
2722

2823
#define OCVRS_HANDLE(code, msg, return_name) Err(code, msg, return_name)

0 commit comments

Comments
 (0)