[][src]Crate cmake_config

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::Stringish variant.

RawFlag

Represents a single CMake property

RustConstItem

Enums

CMakeType

The type hint associated with a CMake property

ParseError

The usual things that might go wrong when interpreting a CMakeCache blob of data

RustCodeGenerationError
SimpleFlag

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_raw for reading a CMakeCache.txt file and handing back either a Vec of 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.