Skip to content

Commit 663888b

Browse files
committed
Add define_bool convention method
1 parent faccc07 commit 663888b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
//! use cmake::Config;
3636
//!
3737
//! let dst = Config::new("libfoo")
38-
//! .define("FOO", "BAR")
38+
//! .define("FOO", "BAR") // -DFOO=BAR
39+
//! .define_bool("BAZ", true) // -DBAZ=ON
3940
//! .cflag("-foo")
4041
//! .build();
4142
//! println!("cargo:rustc-link-search=native={}", dst.display());
@@ -272,6 +273,11 @@ impl Config {
272273
self
273274
}
274275

276+
/// Adds a new `-D` flag with a `ON`/`OFF` value to pass to cmake during the generation step.
277+
pub fn define_bool<K: AsRef<OsStr>>(&mut self, k: K, v: bool) -> &mut Config {
278+
self.define(k, if v { "ON" } else { "OFF" })
279+
}
280+
275281
/// Registers a dependency for this compilation on the native library built
276282
/// by Cargo previously.
277283
///

0 commit comments

Comments
 (0)