cmake-rs icon indicating copy to clipboard operation
cmake-rs copied to clipboard

Definitions added via `Config::define` are not present

Open lever1209 opened this issue 8 months ago • 2 comments

as the title states, i try defining a variable like i would from the commandline with -D, and i get nothing in cmake itself or the source code, nothing is defined at all

lever1209 avatar Apr 17 '25 15:04 lever1209

Could you produce a code sample?

tgross35 avatar Apr 17 '25 18:04 tgross35

damn, im sorry for leaving you hanging for 4 days

fn gxmite() -> Result<(), Box<dyn std::error::Error>> {
	println!("cargo:rerun-if-changed=submodules/gxmite");

	let mut cfg = cmake::Config::new("submodules/gxmite");

	if std::env::var("PROFILE")?.as_str() == "debug" {
		cfg.define("debug_assertions", "true"); // here
	}
	cfg.build_target("gxmite");
	let dst = cfg.build();

	println!("cargo:rustc-link-search=native={}", dst.join("lib").display());
	println!("cargo:rustc-link-lib=static=gxmite");

	Ok(())
}

since i made the issue ive figured out that it gets defined for cmake and not my program, so things like #ifdef dont ever see it, meaning i most likely need to do something in my cmake file or there is some other part of this crate i dont know of yet

lever1209 avatar Apr 21 '25 08:04 lever1209