use std::path::PathBuf;
macro_rules! choices {
($(#[$doc:meta])* $name:ident { $($(#[$vdoc:meta])* $variant:ident = $text:literal),+ $(,)? }) => {
$(#[$doc])*
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum $name { $($(#[$vdoc])* $variant),+ }
impl $name {
pub const ALL: &[($name, &str)] = &[$(($name::$variant, $text)),+];
pub fn as_str(self) -> &'static str {
match self { $($name::$variant => $text),+ }
}
pub fn parse(text: &str) -> Option<$name> {
Self::ALL.iter().find(|(_, t)| *t == text).map(|(v, _)| *v)
}
}
};
}
choices!(
Lang { C = "c", Cxx = "c++" }
);
choices!(
Edition { Cxx17 = "c++17", Cxx20 = "c++20", Cxx23 = "c++23", C11 = "c11", C17 = "c17", C23 = "c23" }
);
choices!(
Warnings { Default = "default", All = "all", Pedantic = "pedantic" }
);
choices!(
Runtime { Dynamic = "dynamic", Static = "static" }
);
choices!(
Subsystem { Console = "console", Windows = "windows" }
);
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum OptLevel {
O0,
O1,
O2,
O3,
Size,
}
impl Lang {
pub fn default_entry(self) -> &'static str {
match self {
Lang::C => "src/main.c",
Lang::Cxx => "src/main.cpp",
}
}
pub fn default_edition(self) -> Edition {
match self {
Lang::C => Edition::C17,
Lang::Cxx => Edition::Cxx20,
}
}
}
impl Edition {
pub fn lang(self) -> Lang {
match self {
Edition::C11 | Edition::C17 | Edition::C23 => Lang::C,
_ => Lang::Cxx,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BuildSettings {
pub warnings: Warnings,
pub warnings_as_errors: bool,
pub defines: Vec<String>,
pub include_dirs: Vec<PathBuf>,
pub links: Vec<String>,
pub lib_dirs: Vec<PathBuf>,
pub link_flags: Vec<String>,
pub flags: Vec<String>,
pub runtime: Runtime,
pub exceptions: bool,
pub rtti: bool,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ProfileSettings {
pub opt_level: OptLevel,
pub debug_info: bool,
pub debug_assertions: bool,
pub lto: bool,
}