Skip to content

Commit 007bbb7

Browse files
SageMiktwistedfall
authored andcommitted
Support toolchain and custom args for CMake
1 parent 5ee7bc6 commit 007bbb7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

build/cmake_probe.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub struct CmakeProbe<'r> {
110110
package_name: &'r str,
111111
toolchain: Option<&'r Path>,
112112
is_release: bool,
113+
args: Option<&'r str>,
113114
}
114115

115116
impl<'r> CmakeProbe<'r> {
@@ -120,6 +121,7 @@ impl<'r> CmakeProbe<'r> {
120121
package_name: &'r str,
121122
toolchain: Option<&'r Path>,
122123
is_release: bool,
124+
args: Option<&'r str>,
123125
) -> Self {
124126
Self {
125127
cmake_bin: cmake_bin.unwrap_or_else(|| "cmake".into()),
@@ -128,6 +130,7 @@ impl<'r> CmakeProbe<'r> {
128130
package_name,
129131
toolchain,
130132
is_release,
133+
args,
131134
}
132135
}
133136

@@ -162,6 +165,9 @@ impl<'r> CmakeProbe<'r> {
162165
} else {
163166
out.arg("-DCMAKE_BUILD_TYPE=Debug");
164167
}
168+
if let Some(args) = &self.args {
169+
out.args(args.split(' '));
170+
}
165171
out
166172
}
167173

build/library.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,16 @@ impl Library {
341341
cmake_bin: Option<&Path>,
342342
ninja_bin: Option<&Path>,
343343
) -> Result<Self> {
344+
let toolchain_var = env::var_os("OPENCV_CMAKE_TOOLCHAIN_FILE").map(PathBuf::from);
345+
let toolchain = toolchain.or_else(|| toolchain_var.as_ref().map(PathBuf::as_path));
344346
eprintln!(
345347
"=== Probing OpenCV library using cmake{}",
346348
toolchain.map_or_else(|| "".to_string(), |tc| format!(" with toolchain: {}", tc.display()))
347349
);
348350

349351
let src_dir = MANIFEST_DIR.join("cmake");
350352
let package_name = PackageName::cmake();
353+
let args = env::var_os("OPENCV_CMAKE_ARGS");
351354
let cmake = CmakeProbe::new(
352355
env::var_os("OPENCV_CMAKE_BIN")
353356
.map(PathBuf::from)
@@ -357,6 +360,7 @@ impl Library {
357360
package_name.as_ref(),
358361
toolchain,
359362
env::var_os("PROFILE").is_some_and(|p| p == "release"),
363+
args.as_ref().and_then(|p| p.to_str()),
360364
);
361365
let mut probe_result = cmake
362366
.probe_ninja(ninja_bin)

0 commit comments

Comments
 (0)