enable freetype with imgui

This commit is contained in:
Mitchell Hashimoto
2022-10-17 11:41:46 -07:00
parent ab721b5b26
commit 20f1077e86
2 changed files with 44 additions and 4 deletions

View File

@ -219,12 +219,12 @@ fn addDeps(
const glfw_opts: glfw.Options = .{ .metal = false, .opengl = false };
try glfw.link(b, step, glfw_opts);
// Imgui
// Imgui, we have to do this later since we need some information
const imgui_backends = [_][]const u8{ "glfw", "opengl3" };
const imgui_step = try imgui.link(b, step, .{
var imgui_opts: imgui.Options = .{
.backends = &imgui_backends,
});
try glfw.link(b, imgui_step, glfw_opts);
.freetype = .{ .enabled = true },
};
// Dynamic link
if (!static) {
@ -305,7 +305,15 @@ fn addDeps(
});
libxml2_lib.link(fontconfig_step);
}
// Imgui
imgui_opts.freetype.step = freetype_step;
imgui_opts.freetype.include = &freetype.include_paths;
}
// Imgui
const imgui_step = try imgui.link(b, step, imgui_opts);
try glfw.link(b, imgui_step, glfw_opts);
}
fn conformanceSteps(

View File

@ -19,6 +19,14 @@ fn thisDir() []const u8 {
pub const Options = struct {
backends: ?[]const []const u8 = null,
freetype: Freetype = .{},
pub const Freetype = struct {
enabled: bool = false,
step: ?*std.build.LibExeObjStep = null,
include: ?[]const []const u8 = null,
};
};
pub fn link(
@ -54,6 +62,10 @@ pub fn buildImgui(
try flags.appendSlice(&.{
"-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1",
// We want to always have STB in addition to Freetype to
// fix compilation issues with cimgui.
"-DIMGUI_ENABLE_STB_TRUETYPE=1",
//"-fno-sanitize=undefined",
});
switch (target.getOsTag()) {
@ -65,6 +77,26 @@ pub fn buildImgui(
}),
}
// Freetype
if (opt.freetype.enabled) {
if (opt.freetype.step) |freetype|
lib.linkLibrary(freetype)
else
lib.linkSystemLibrary("freetype2");
if (opt.freetype.include) |dirs|
for (dirs) |dir| lib.addIncludePath(dir);
// Enable in defines
try flags.appendSlice(&.{
"-DIMGUI_ENABLE_FREETYPE=1",
"-DCIMGUI_FREETYPE=1",
});
// Add necessary C file
lib.addCSourceFile(root ++ "imgui/misc/freetype/imgui_freetype.cpp", flags.items);
}
// C files
lib.addCSourceFiles(srcs, flags.items);
if (opt.backends) |backends| {