Support Linux with GL or X11 in build.zig

This commit is contained in:
Brandon Dyck 2021-12-12 13:30:32 -07:00
parent d7ae5488c8
commit 954352db4f

View File

@ -7,7 +7,6 @@ const base_cflags: []const []const u8 = &.{
"-Wno-switch",
"-Wno-unused-function",
"-Wno-implicit-fallthrough",
"-std=c11",
};
pub fn build(b: *std.build.Builder) !void {
@ -24,7 +23,6 @@ pub fn build(b: *std.build.Builder) !void {
"src/MiniFB_common.c",
"src/MiniFB_internal.c",
"src/MiniFB_timer.c",
"src/windows/WinMiniFB.c",
});
const use_opengl = b.option(bool, "opengl", "Use OpenGL") orelse false;
@ -32,15 +30,39 @@ pub fn build(b: *std.build.Builder) !void {
const lib = b.addStaticLibrary("minifb-zig-port", null);
lib.addIncludeDir("src");
lib.addIncludeDir("include");
lib.linkSystemLibraryName("gdi32");
lib.linkLibC();
lib.setBuildMode(mode);
lib.install();
if (use_opengl) {
try c_flags.append("-DUSE_OPENGL_API");
try c_sources.append("src/gl/MiniFB_GL.c");
lib.linkSystemLibraryName("Opengl32");
switch (target.getOsTag()) {
std.Target.Os.Tag.windows => {
try c_sources.append("src/windows/WinMiniFB.c");
lib.linkSystemLibraryName("gdi32");
if (use_opengl) {
try c_flags.append("-DUSE_OPENGL_API");
try c_sources.append("src/gl/MiniFB_GL.c");
lib.linkSystemLibraryName("opengl32");
}
},
std.Target.Os.Tag.linux => {
try c_sources.append("src/MiniFB_linux.c");
try c_sources.append("src/x11/X11MiniFB.c");
lib.linkSystemLibrary("rt");
lib.linkSystemLibrary("X11");
if (use_opengl) {
try c_flags.append("-DUSE_OPENGL_API");
try c_sources.append("src/gl/MiniFB_GL.c");
lib.linkSystemLibrary("GL");
}
// TODO wayland
},
else => {
return error.PlatformNotSupported;
},
}
lib.addCSourceFiles(c_sources.items, c_flags.items);
addExample(b, "noise", "tests/noise.c", lib, target, mode);