Skip to content

Commit

Permalink
Add define_bool convention method
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Feb 9, 2025
1 parent faccc07 commit 663888b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
//! use cmake::Config;
//!
//! let dst = Config::new("libfoo")
//! .define("FOO", "BAR")
//! .define("FOO", "BAR") // -DFOO=BAR
//! .define_bool("BAZ", true) // -DBAZ=ON
//! .cflag("-foo")
//! .build();
//! println!("cargo:rustc-link-search=native={}", dst.display());
Expand Down Expand Up @@ -272,6 +273,11 @@ impl Config {
self
}

/// Adds a new `-D` flag with a `ON`/`OFF` value to pass to cmake during the generation step.
pub fn define_bool<K: AsRef<OsStr>>(&mut self, k: K, v: bool) -> &mut Config {
self.define(k, if v { "ON" } else { "OFF" })
}

/// Registers a dependency for this compilation on the native library built
/// by Cargo previously.
///
Expand Down

0 comments on commit 663888b

Please sign in to comment.