Merge pull request #582 from ruifengx/freetype-vcpkg

add vcpkg-rs for locating freetype
This commit is contained in:
dbr/Ben 2023-01-12 09:59:15 +10:30 committed by GitHub
commit d0ccbd33d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 10 deletions

View File

@ -136,17 +136,23 @@ jobs:
- name: docking feature - name: docking feature
run: cargo test --workspace --all-targets --features docking run: cargo test --workspace --all-targets --features docking
- name: freetype feature - name: freetype feature (non-Windows, pkg-config)
if: matrix.os != 'windows-latest' if: matrix.os != 'windows-latest'
run: cargo test --workspace --all-targets --features freetype run: cargo test --workspace --all-targets --features freetype
- name: all features - name: freetype and docking (non-Windows, pkg-config)
if: matrix.os != 'windows-latest' if: matrix.os != 'windows-latest'
run: cargo test --workspace --all-targets --features docking,freetype run: cargo test --workspace --all-targets --features freetype,docking
- name: doc tests - name: freetype feature (Windows, vcpkg)
run: cargo test --workspace --doc if: matrix.os == 'windows-latest'
run: cargo test --workspace --all-targets --features freetype,use-vcpkg
- name: freetype and docking (Windows, vcpkg)
if: matrix.os == 'windows-latest'
run: cargo test --workspace --all-targets --features freetype,docking,use-vcpkg
- run: cargo test --workspace --doc
# run to check for lint problems # run to check for lint problems
- name: build documentation - name: build documentation
run: cargo doc run: cargo doc

View File

@ -33,9 +33,11 @@ cfg-if = "1"
[build-dependencies] [build-dependencies]
cc = "1.0" cc = "1.0"
pkg-config = { version="0.3", optional=true } pkg-config = { version="0.3", optional=true }
vcpkg = { version="0.2.15", optional=true }
[features] [features]
default = [] default = []
wasm = [] wasm = []
freetype = ["pkg-config"]
docking = [] docking = []
freetype = ["pkg-config"]
use-vcpkg = ["vcpkg"]

View File

@ -9,11 +9,29 @@ const DEFINES: &[(&str, Option<&str>)] = &[
("IMGUI_DISABLE_OSX_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),
}
}
// Output define args for compiler
fn main() -> std::io::Result<()> { fn main() -> std::io::Result<()> {
// Root of imgui-sys // Root of imgui-sys
let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")); let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
// Output define args for compiler println!(
"cargo:THIRD_PARTY={}",
manifest_dir.join("third-party").display()
);
for (key, value) in DEFINES.iter() { for (key, value) in DEFINES.iter() {
println!("cargo:DEFINE_{}={}", key, value.unwrap_or("")); println!("cargo:DEFINE_{}={}", key, value.unwrap_or(""));
} }
@ -53,9 +71,7 @@ fn main() -> std::io::Result<()> {
// Freetype font rasterizer feature // Freetype font rasterizer feature
#[cfg(feature = "freetype")] #[cfg(feature = "freetype")]
{ {
// Find library for include in find_freetype() {
let freetype = pkg_config::Config::new().find("freetype2").unwrap();
for include in freetype.include_paths.iter() {
build.include(include); build.include(include);
} }
// Set flag for dear imgui // Set flag for dear imgui

View File

@ -5245,7 +5245,11 @@ CIMGUI_API bool igIsKeyPressedMap(ImGuiKey key,bool repeat)
} }
CIMGUI_API const ImFontBuilderIO* igImFontAtlasGetBuilderForStbTruetype() CIMGUI_API const ImFontBuilderIO* igImFontAtlasGetBuilderForStbTruetype()
{ {
#ifdef IMGUI_ENABLE_FREETYPE
return static_cast<const ImFontBuilderIO*>(0);
#else
return ImFontAtlasGetBuilderForStbTruetype(); return ImFontAtlasGetBuilderForStbTruetype();
#endif
} }
CIMGUI_API void igImFontAtlasBuildInit(ImFontAtlas* atlas) CIMGUI_API void igImFontAtlasBuildInit(ImFontAtlas* atlas)
{ {