Skip to content

Support common boolean convention of defining ON|OFF values #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nyurik opened this issue Feb 8, 2025 · 0 comments
Open

Support common boolean convention of defining ON|OFF values #236

nyurik opened this issue Feb 8, 2025 · 0 comments

Comments

@nyurik
Copy link

nyurik commented Feb 8, 2025

Most CMake configurations use the ON|OFF convention to indicate a boolean value. It would be more ergonomic to add a new setter like fn define_bool(&mut self, key: &str, value: bool). Some build.rs scripts could also compute these values during execution, so having this function would simplify

cfg.define("SOMETHING", if flag { "ON" } else { "OFF" });

into

cfg.define_bool("SOMETHING", flag);

Workaround

Without this, I had to add this to all projects that needed this functionality:

trait CfgBool {
    fn define_bool(&mut self, key: &str, value: bool);
}

impl CfgBool for cmake::Config {
    fn define_bool(&mut self, key: &str, value: bool) {
        self.define(key, if value { "ON" } else { "OFF" });
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant