pkg/dcimgui: add freetype
parent
f1ba5297b8
commit
965ffb1750
|
|
@ -4,12 +4,14 @@ const NativeTargetInfo = std.zig.system.NativeTargetInfo;
|
||||||
pub fn build(b: *std.Build) !void {
|
pub fn build(b: *std.Build) !void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
const freetype = b.option(bool, "freetype", "Use Freetype") orelse false;
|
||||||
const backend_opengl3 = b.option(bool, "backend-opengl3", "OpenGL3 backend") orelse false;
|
const backend_opengl3 = b.option(bool, "backend-opengl3", "OpenGL3 backend") orelse false;
|
||||||
const backend_metal = b.option(bool, "backend-metal", "Metal backend") orelse false;
|
const backend_metal = b.option(bool, "backend-metal", "Metal backend") orelse false;
|
||||||
const backend_osx = b.option(bool, "backend-osx", "OSX backend") orelse false;
|
const backend_osx = b.option(bool, "backend-osx", "OSX backend") orelse false;
|
||||||
|
|
||||||
// Build options
|
// Build options
|
||||||
const options = b.addOptions();
|
const options = b.addOptions();
|
||||||
|
options.addOption(bool, "freetype", freetype);
|
||||||
options.addOption(bool, "backend_opengl3", backend_opengl3);
|
options.addOption(bool, "backend_opengl3", backend_opengl3);
|
||||||
options.addOption(bool, "backend_metal", backend_metal);
|
options.addOption(bool, "backend_metal", backend_metal);
|
||||||
options.addOption(bool, "backend_osx", backend_osx);
|
options.addOption(bool, "backend_osx", backend_osx);
|
||||||
|
|
@ -50,6 +52,9 @@ pub fn build(b: *std.Build) !void {
|
||||||
"-DIMGUI_USE_WCHAR32=1",
|
"-DIMGUI_USE_WCHAR32=1",
|
||||||
"-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1",
|
"-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1",
|
||||||
});
|
});
|
||||||
|
if (freetype) try flags.appendSlice(b.allocator, &.{
|
||||||
|
"-DIMGUI_ENABLE_FREETYPE=1",
|
||||||
|
});
|
||||||
if (target.result.os.tag == .windows) {
|
if (target.result.os.tag == .windows) {
|
||||||
try flags.appendSlice(b.allocator, &.{
|
try flags.appendSlice(b.allocator, &.{
|
||||||
"-DIMGUI_IMPL_API=extern\t\"C\"\t__declspec(dllexport)",
|
"-DIMGUI_IMPL_API=extern\t\"C\"\t__declspec(dllexport)",
|
||||||
|
|
@ -84,6 +89,30 @@ pub fn build(b: *std.Build) !void {
|
||||||
.{ .include_extensions = &.{".h"} },
|
.{ .include_extensions = &.{".h"} },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (freetype) {
|
||||||
|
lib.addCSourceFile(.{
|
||||||
|
.file = upstream.path("misc/freetype/imgui_freetype.cpp"),
|
||||||
|
.flags = flags.items,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (b.systemIntegrationOption("freetype", .{})) {
|
||||||
|
lib.linkSystemLibrary2("freetype2", dynamic_link_opts);
|
||||||
|
} else {
|
||||||
|
const freetype_dep = b.dependency("freetype", .{
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
.@"enable-libpng" = true,
|
||||||
|
});
|
||||||
|
lib.linkLibrary(freetype_dep.artifact("freetype"));
|
||||||
|
if (freetype_dep.builder.lazyDependency(
|
||||||
|
"freetype",
|
||||||
|
.{},
|
||||||
|
)) |freetype_upstream| {
|
||||||
|
mod.addIncludePath(freetype_upstream.path("include"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (backend_metal) {
|
if (backend_metal) {
|
||||||
lib.addCSourceFiles(.{
|
lib.addCSourceFiles(.{
|
||||||
.root = upstream.path("backends"),
|
.root = upstream.path("backends"),
|
||||||
|
|
@ -160,3 +189,11 @@ pub fn build(b: *std.Build) !void {
|
||||||
const test_step = b.step("test", "Run tests");
|
const test_step = b.step("test", "Run tests");
|
||||||
test_step.dependOn(&tests_run.step);
|
test_step.dependOn(&tests_run.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For dynamic linking, we prefer dynamic linking and to search by
|
||||||
|
// mode first. Mode first will search all paths for a dynamic library
|
||||||
|
// before falling back to static.
|
||||||
|
const dynamic_link_opts: std.Build.Module.LinkSystemLibraryOptions = .{
|
||||||
|
.preferred_link_mode = .dynamic,
|
||||||
|
.search_strategy = .mode_first,
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -135,29 +135,28 @@ pub fn add(
|
||||||
// Every exe needs the terminal options
|
// Every exe needs the terminal options
|
||||||
self.config.terminalOptions().add(b, step.root_module);
|
self.config.terminalOptions().add(b, step.root_module);
|
||||||
|
|
||||||
// Freetype
|
// Freetype. We always include this even if our font backend doesn't
|
||||||
|
// use it because Dear Imgui uses Freetype.
|
||||||
_ = b.systemIntegrationOption("freetype", .{}); // Shows it in help
|
_ = b.systemIntegrationOption("freetype", .{}); // Shows it in help
|
||||||
if (self.config.font_backend.hasFreetype()) {
|
if (b.lazyDependency("freetype", .{
|
||||||
if (b.lazyDependency("freetype", .{
|
.target = target,
|
||||||
.target = target,
|
.optimize = optimize,
|
||||||
.optimize = optimize,
|
.@"enable-libpng" = true,
|
||||||
.@"enable-libpng" = true,
|
})) |freetype_dep| {
|
||||||
})) |freetype_dep| {
|
step.root_module.addImport(
|
||||||
step.root_module.addImport(
|
"freetype",
|
||||||
"freetype",
|
freetype_dep.module("freetype"),
|
||||||
freetype_dep.module("freetype"),
|
);
|
||||||
);
|
|
||||||
|
|
||||||
if (b.systemIntegrationOption("freetype", .{})) {
|
if (b.systemIntegrationOption("freetype", .{})) {
|
||||||
step.linkSystemLibrary2("bzip2", dynamic_link_opts);
|
step.linkSystemLibrary2("bzip2", dynamic_link_opts);
|
||||||
step.linkSystemLibrary2("freetype2", dynamic_link_opts);
|
step.linkSystemLibrary2("freetype2", dynamic_link_opts);
|
||||||
} else {
|
} else {
|
||||||
step.linkLibrary(freetype_dep.artifact("freetype"));
|
step.linkLibrary(freetype_dep.artifact("freetype"));
|
||||||
try static_libs.append(
|
try static_libs.append(
|
||||||
b.allocator,
|
b.allocator,
|
||||||
freetype_dep.artifact("freetype").getEmittedBin(),
|
freetype_dep.artifact("freetype").getEmittedBin(),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -482,6 +481,7 @@ pub fn add(
|
||||||
if (b.lazyDependency("dcimgui", .{
|
if (b.lazyDependency("dcimgui", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
|
.freetype = true,
|
||||||
.@"backend-metal" = target.result.os.tag.isDarwin(),
|
.@"backend-metal" = target.result.os.tag.isDarwin(),
|
||||||
.@"backend-osx" = target.result.os.tag == .macos,
|
.@"backend-osx" = target.result.os.tag == .macos,
|
||||||
.@"backend-opengl3" = target.result.os.tag != .macos,
|
.@"backend-opengl3" = target.result.os.tag != .macos,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue