build freetype-gl

This commit is contained in:
Mitchell Hashimoto
2022-04-04 14:14:20 -07:00
parent ef55c1ac97
commit c42bf7c663
4 changed files with 72 additions and 1 deletions

View File

@ -3,6 +3,7 @@ const Builder = std.build.Builder;
const LibExeObjStep = std.build.LibExeObjStep;
const glfw = @import("vendor/mach/glfw/build.zig");
const ft = @import("src/freetype/build.zig");
const ftgl = @import("src/freetype-gl/build.zig");
pub fn build(b: *std.build.Builder) !void {
const target = b.standardTargetOptions(.{});
@ -16,6 +17,7 @@ pub fn build(b: *std.build.Builder) !void {
exe.addCSourceFile("src/gb_math.c", &.{});
exe.addPackagePath("glfw", "vendor/mach/glfw/src/main.zig");
glfw.link(b, exe, .{});
try ftgl.link(exe, b, target, mode, .{});
exe.linkSystemLibrary("epoxy");

68
src/freetype-gl/build.zig Normal file
View File

@ -0,0 +1,68 @@
const std = @import("std");
const ft = @import("../freetype/build.zig");
/// Compile-time options for the library. These mostly correspond to
/// options exposed by the native build system used by the library.
pub const Options = struct {};
/// Create this library. This is the primary API users of build.zig should
/// use to link this library to their application. On the resulting Library,
/// call the link function and given your own application step.
pub fn link(
exe: *std.build.LibExeObjStep,
b: *std.build.Builder,
target: std.zig.CrossTarget,
mode: std.builtin.Mode,
opts: Options,
) !void {
_ = opts;
const ret = b.addStaticLibrary("freetype-gl", null);
ret.setTarget(target);
ret.setBuildMode(mode);
var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit();
// try flags.appendSlice(&.{});
// C files
ret.addCSourceFiles(srcs, flags.items);
ret.addIncludeDir(root());
ret.linkLibC();
// For config.h
ret.addIncludeDir(thisDir());
// Dependencies
ret.linkSystemLibrary("gl");
const ftstep = try ft.create(b, target, mode, .{});
ftstep.addIncludeDirs(ret);
exe.addIncludeDir(root());
exe.linkLibrary(ret);
}
fn root() []const u8 {
return (std.fs.path.dirname(@src().file) orelse unreachable) ++ "/../../vendor/freetype-gl/";
}
fn thisDir() []const u8 {
return (std.fs.path.dirname(@src().file) orelse unreachable) ++ "/";
}
const srcs = &.{
root() ++ "distance-field.c",
root() ++ "edtaa3func.c",
root() ++ "platform.c",
root() ++ "text-buffer.c",
root() ++ "texture-atlas.c",
root() ++ "texture-font.c",
root() ++ "utf8-utils.c",
root() ++ "ftgl-utils.c",
root() ++ "vector.c",
root() ++ "vertex-attribute.c",
// optional stuff we don't need
// root() ++ "font-manager.c",
// root() ++ "vertex-buffer.c",
};

1
src/freetype-gl/config.h Normal file
View File

@ -0,0 +1 @@
// Purposely empty! This is just here so that freetype-gl will build.

View File

@ -7,7 +7,6 @@ pub const Library = struct {
/// statically link this library into the given step
pub fn link(self: Library, other: *std.build.LibExeObjStep) void {
self.addIncludeDirs(other);
other.addIncludeDir(include_dir);
other.linkLibrary(self.step);
}
@ -19,6 +18,7 @@ pub const Library = struct {
// We need to add this directory to the include path for the final
// app so that we can access "freetype-zig.h".
other.addIncludeDir(include_dir);
other.addIncludeDir(std.fs.path.dirname(@src().file) orelse unreachable);
}
};