From 663888be462e54ec0ace8b795ad2d84712bec435 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 8 Feb 2025 19:03:07 -0500 Subject: [PATCH] Add `define_bool` convention method --- src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a569184..b57c442 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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()); @@ -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>(&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. ///