Skip to content

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

Open
@nyurik

Description

@nyurik

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" });
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions