Expand description
This crate provides a parser for CMakeCache.txt files.
The primary entry points are parse_raw and parse_file_to_raw, which produces
a vector of the minimally-processed CMake flags from a supplied
path.
use cmake_config::{CMakeType, RawFlag};
use std::io::{BufReader, Cursor};
let s = r"FOO:BOOL=ON
BAR:STRING=BAZ";
let reader = BufReader::new(Cursor::new(s));
let flags = cmake_config::parse_raw(reader).expect("Parsing error!");
assert_eq!(vec![
RawFlag {
key: "FOO".into(),
cmake_type: CMakeType::Bool,
value: "ON".into(),
},
RawFlag {
key: "BAR".into(),
cmake_type: CMakeType::String,
value: "BAZ".into(),
},
], flags);Optionally, Flags can be summarized from their initial RawFlag form
into SimpleFlag instances for representation in Rust.
use cmake_config::{CMakeType, RawFlag, SimpleFlag, Key};
let raw = RawFlag {
key: "FOO".into(),
cmake_type: CMakeType::Bool,
value: "ON".into(),
};
let simplified = SimpleFlag::from(&raw);
assert_eq!(SimpleFlag::Boolish(Key("FOO".into()), true), simplified);SimpleFlag also provides a convenience method, generate_rust_const_item,
which produces the text of a Rust-lang const definition for that flag.
Structs§
- Key
- A newtype wrapper for the key / property-name
of a CMake flag. Mostly here to avoid confusion
between the similarly-shaped key and value of a
SimpleFlag::Stringishvariant. - RawFlag
- Represents a single CMake property
- Rust
Const Item
Enums§
- CMake
Type - The type hint associated with a CMake property
- Parse
Error - The usual things that might go wrong when interpreting a CMakeCache blob of data
- Rust
Code Generation Error - Simple
Flag - A pared-down and interpreted representation of a CMake flag
Functions§
- interpret_
value_ as_ boolish - is_
valid_ rust_ identifier - Convenience function determining if a string is usable without alteration as a Rust identifier for an item.
- parse_
file_ to_ raw - Convenience wrapper around
parse_rawfor reading a CMakeCache.txt file and handing back either aVecof flags or a very simple error. - parse_
raw - Most generic entry point, intended to interpret a buffered reader of CMakeCache textual data into the represented flags.