Support Linux with GL or X11 in build.zig
This commit is contained in:
parent
d7ae5488c8
commit
954352db4f
36
build.zig
36
build.zig
@ -7,7 +7,6 @@ const base_cflags: []const []const u8 = &.{
|
|||||||
"-Wno-switch",
|
"-Wno-switch",
|
||||||
"-Wno-unused-function",
|
"-Wno-unused-function",
|
||||||
"-Wno-implicit-fallthrough",
|
"-Wno-implicit-fallthrough",
|
||||||
"-std=c11",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn build(b: *std.build.Builder) !void {
|
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_common.c",
|
||||||
"src/MiniFB_internal.c",
|
"src/MiniFB_internal.c",
|
||||||
"src/MiniFB_timer.c",
|
"src/MiniFB_timer.c",
|
||||||
"src/windows/WinMiniFB.c",
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const use_opengl = b.option(bool, "opengl", "Use OpenGL") orelse false;
|
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);
|
const lib = b.addStaticLibrary("minifb-zig-port", null);
|
||||||
lib.addIncludeDir("src");
|
lib.addIncludeDir("src");
|
||||||
lib.addIncludeDir("include");
|
lib.addIncludeDir("include");
|
||||||
lib.linkSystemLibraryName("gdi32");
|
|
||||||
lib.linkLibC();
|
lib.linkLibC();
|
||||||
lib.setBuildMode(mode);
|
lib.setBuildMode(mode);
|
||||||
lib.install();
|
lib.install();
|
||||||
if (use_opengl) {
|
|
||||||
try c_flags.append("-DUSE_OPENGL_API");
|
switch (target.getOsTag()) {
|
||||||
try c_sources.append("src/gl/MiniFB_GL.c");
|
std.Target.Os.Tag.windows => {
|
||||||
lib.linkSystemLibraryName("Opengl32");
|
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);
|
lib.addCSourceFiles(c_sources.items, c_flags.items);
|
||||||
|
|
||||||
addExample(b, "noise", "tests/noise.c", lib, target, mode);
|
addExample(b, "noise", "tests/noise.c", lib, target, mode);
|
||||||
|
Loading…
Reference in New Issue
Block a user