#![allow(dead_code)]
const DEFINES: &[(&str, Option<&str>)] = &[
("IMGUI_USE_WCHAR32", None),
("CIMGUI_NO_EXPORT", None),
("IMGUI_DISABLE_WIN32_FUNCTIONS", None),
("IMGUI_DISABLE_OSX_FUNCTIONS", None),
];
#[cfg(feature = "freetype")]
fn find_freetype() -> Vec<impl AsRef<std::path::Path>> {
#[cfg(not(feature = "use-vcpkg"))]
match pkg_config::Config::new().find("freetype2") {
Ok(freetype) => freetype.include_paths,
Err(err) => panic!("cannot find freetype: {}", err),
}
#[cfg(feature = "use-vcpkg")]
match vcpkg::find_package("freetype") {
Ok(freetype) => freetype.include_paths,
Err(err) => panic!("cannot find freetype: {}", err),
}
}
fn main() -> std::io::Result<()> {
let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
println!(
"cargo:THIRD_PARTY={}",
manifest_dir.join("third-party").display()
);
for (key, value) in DEFINES.iter() {
println!("cargo:DEFINE_{}={}", key, value.unwrap_or(""));
}
let docking_enabled = std::env::var_os("CARGO_FEATURE_DOCKING").is_some();
let freetype_enabled = std::env::var_os("CARGO_FEATURE_FREETYPE").is_some();
let wasm_enabled = std::env::var_os("CARGO_FEATURE_WASM").is_some();
let cimgui_dir = manifest_dir.join(match (docking_enabled, freetype_enabled) {
(false, false) => "third-party/imgui-master",
(true, false) => "third-party/imgui-docking",
(false, true) => "third-party/imgui-master-freetype",
(true, true) => "third-party/imgui-docking-freetype",
});
println!("cargo:THIRD_PARTY={}", cimgui_dir.display());
if !wasm_enabled {
let mut build = cc::Build::new();
build.cpp(true);
build.flag_if_supported("-std=c++11");
for (key, value) in DEFINES.iter() {
build.define(key, *value);
}
#[cfg(feature = "freetype")]
{
build.flag_if_supported("-Wno-subobject-linkage");
for include in find_freetype() {
build.include(include);
}
build.define("CIMGUI_FREETYPE", None); println!("cargo:DEFINE_IMGUI_ENABLE_FREETYPE=");
build.include(dbg!(cimgui_dir.join("imgui")));
}
let imgui_cpp = match (docking_enabled, freetype_enabled) {
(false, false) => "include_imgui_master.cpp",
(true, false) => "include_imgui_docking.cpp",
(false, true) => "include_imgui_master_freetype.cpp",
(true, true) => "include_imgui_docking_freetype.cpp",
};
let compiler = build.get_compiler();
if compiler.is_like_gnu() || compiler.is_like_clang() {
build.flag("-fno-exceptions").flag("-fno-rtti");
}
build.warnings(false).file(imgui_cpp).compile("libcimgui.a");
}
Ok(())
}