2020-07-02 19:15:22 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
|
|
// This is taken pretty vanilla from
|
|
|
|
// https://github.com/Gekkio/imgui-rs/blob/master/imgui-sys/build.rs
|
|
|
|
// for now, but expected to diverge from that over time.
|
2020-07-12 20:25:27 +00:00
|
|
|
use std::{env, fs, io, path::Path};
|
2020-07-12 12:29:02 +00:00
|
|
|
|
2020-10-04 12:43:18 +00:00
|
|
|
const CPP_FILES: &[&str] = &[
|
2020-07-02 19:15:22 +00:00
|
|
|
"third-party/cimplot/cimplot.cpp",
|
|
|
|
"third-party/cimplot/implot/implot.cpp",
|
2020-10-04 12:43:18 +00:00
|
|
|
"third-party/cimplot/implot/implot_items.cpp",
|
2020-08-08 12:42:22 +00:00
|
|
|
"third-party/cimplot/implot/implot_demo.cpp", // Could remove this if demo not used
|
2020-07-02 19:15:22 +00:00
|
|
|
];
|
|
|
|
|
2020-10-04 12:43:18 +00:00
|
|
|
const IMPLOT_INCLUDE_DIRECTORIES: &[&str] = &["third-party/cimplot/implot/"];
|
|
|
|
|
2020-07-02 19:15:22 +00:00
|
|
|
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),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 19:35:13 +00:00
|
|
|
fn main() -> io::Result<()> {
|
2020-07-12 12:29:02 +00:00
|
|
|
// --- Compile cimgui
|
2020-07-02 19:15:22 +00:00
|
|
|
let mut build = cc::Build::new();
|
|
|
|
build.cpp(true);
|
|
|
|
|
2020-07-12 20:25:27 +00:00
|
|
|
// Take over imgui preprocessor defines from the imgui-sys crate.
|
|
|
|
// Taken from https://github.com/aloucks/imguizmo-rs/blob/master/imguizmo-sys/build.rs
|
|
|
|
for (key, val) in env::vars().filter(|(key, _)| key.starts_with("DEP_IMGUI_DEFINE_")) {
|
|
|
|
let key = key.trim_start_matches("DEP_IMGUI_DEFINE_");
|
|
|
|
let val = if !val.is_empty() {
|
|
|
|
Some(val.as_str())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
build.define(key, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2020-08-01 16:28:17 +00:00
|
|
|
build.include(&cimgui_include_path);
|
|
|
|
build.include(&imgui_include_path);
|
2020-10-04 12:43:18 +00:00
|
|
|
for path in IMPLOT_INCLUDE_DIRECTORIES {
|
|
|
|
build.include(path);
|
|
|
|
}
|
2020-07-02 19:15:22 +00:00
|
|
|
|
2020-07-12 20:25:27 +00:00
|
|
|
// Taken from the imgui-sys build as well
|
2020-07-02 19:15:22 +00:00
|
|
|
build.flag_if_supported("-Wno-return-type-c-linkage");
|
2020-10-12 22:36:31 +00:00
|
|
|
build.flag_if_supported("-Wno-unused-parameter");
|
2020-10-11 17:50:45 +00:00
|
|
|
build.flag_if_supported("-std=c++11");
|
2020-10-04 12:43:18 +00:00
|
|
|
for path in CPP_FILES {
|
2020-07-02 19:15:22 +00:00
|
|
|
assert_file_exists(path)?;
|
|
|
|
build.file(path);
|
|
|
|
}
|
2020-07-12 20:25:27 +00:00
|
|
|
build.compile("cimplot");
|
2020-07-01 19:35:13 +00:00
|
|
|
Ok(())
|
|
|
|
}
|