#![allow(dead_code)]
use std::{env, fs, io, path::Path};
const CPP_FILES: &[&str] = &["third-party/ImGuiFileDialog/ImGuiFileDialog.cpp"];
fn assert_file_exists(path: &str) -> io::Result<()> {
match fs::metadata(path) {
Ok(_) => Ok(()),
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {
panic!(
"Can't access {}. Did you forget to fetch git submodules?",
path
);
}
Err(e) => Err(e),
}
}
fn main() -> io::Result<()> {
let mut build = cc::Build::new();
env::vars()
.filter_map(|(key, val)| {
key.strip_prefix("DEP_IMGUI_DEFINE_")
.and_then(|suffix| Some((suffix.to_string(), val.to_string())))
})
.for_each(|(key, value)| {
build.define(&key, value.as_str());
});
for path in CPP_FILES {
assert_file_exists(path)?;
build.file(path);
}
let cimgui_include_path =
env::var_os("DEP_IMGUI_THIRD_PARTY").expect("DEP_IMGUI_THIRD_PARTY not defined");
let imgui_include_path = Path::new(&cimgui_include_path).join("imgui");
build
.include(&cimgui_include_path)
.include(&imgui_include_path)
.include("third-party/cimnodes/imnodes/")
.warnings(false)
.cpp(true)
.flag("-std=c++11")
.compile("cimnodes");
let compiler = build.get_compiler();
if compiler.is_like_gnu() || compiler.is_like_clang() {
build.flag("-fno-exceptions").flag("-fno-rtti");
}
Ok(())
}