From f10cecf8039fb74e55eca0083737dce4372bfde1 Mon Sep 17 00:00:00 2001 From: Xie Ruifeng Date: Tue, 7 Dec 2021 18:50:01 +0800 Subject: [PATCH] add vcpkg-rs for locating freetype --- imgui-sys/Cargo.toml | 3 ++- imgui-sys/build.rs | 29 +++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/imgui-sys/Cargo.toml b/imgui-sys/Cargo.toml index 6923859..9779e54 100644 --- a/imgui-sys/Cargo.toml +++ b/imgui-sys/Cargo.toml @@ -33,9 +33,10 @@ cfg-if = "1" [build-dependencies] cc = "1.0" pkg-config = { version="0.3", optional=true } +vcpkg = { version="0.2.15", optional=true } [features] default = [] wasm = [] -freetype = ["pkg-config"] docking = [] +freetype = ["pkg-config", "vcpkg"] diff --git a/imgui-sys/build.rs b/imgui-sys/build.rs index 9b37c04..d796ea6 100644 --- a/imgui-sys/build.rs +++ b/imgui-sys/build.rs @@ -9,11 +9,34 @@ const DEFINES: &[(&str, Option<&str>)] = &[ ("IMGUI_DISABLE_OSX_FUNCTIONS", None), ]; +// Output define args for compiler fn main() -> std::io::Result<()> { // Root of imgui-sys let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")); - // Output define args for compiler + #[cfg(feature = "freetype")] + fn find_freetype() -> Vec> { + let err_pkg_config; + let err_vcpkg; + match pkg_config::Config::new().find("freetype2") { + Ok(freetype) => return freetype.include_paths, + Err(err) => err_pkg_config = err, + } + match vcpkg::find_package("freetype") { + Ok(freetype) => return freetype.include_paths, + Err(err) => err_vcpkg = err, + } + panic!( + "cannot find freetype:\n\ + - pkg-config failed with: {}\n\ + - vcpkg failed with: {}", + err_pkg_config, err_vcpkg + ); + } + println!( + "cargo:THIRD_PARTY={}", + manifest_dir.join("third-party").display() + ); for (key, value) in DEFINES.iter() { println!("cargo:DEFINE_{}={}", key, value.unwrap_or("")); } @@ -48,9 +71,7 @@ fn main() -> std::io::Result<()> { // Freetype font rasterizer feature #[cfg(feature = "freetype")] { - // Find library - let freetype = pkg_config::Config::new().find("freetype2").unwrap(); - for include in freetype.include_paths.iter() { + for include in find_freetype() { build.include(include); } // Set flag for dear imgui