Support Wayland in build.zig
This commit is contained in:
parent
954352db4f
commit
35c01159c2
62
build.zig
62
build.zig
@ -9,6 +9,32 @@ const base_cflags: []const []const u8 = &.{
|
|||||||
"-Wno-implicit-fallthrough",
|
"-Wno-implicit-fallthrough",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Backend = enum {
|
||||||
|
default,
|
||||||
|
x11,
|
||||||
|
wayland,
|
||||||
|
opengl,
|
||||||
|
gdi,
|
||||||
|
};
|
||||||
|
|
||||||
|
const ConfigError = error {
|
||||||
|
PlatformNotSupported,
|
||||||
|
BackendNotSupported,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Returns a comma-separated list of the names of an enum's values
|
||||||
|
/// in declaration order.
|
||||||
|
fn enumNames(comptime E: type) []const u8 {
|
||||||
|
var s: []const u8 = &[_]u8{};
|
||||||
|
for (std.enums.values(E)) |value| {
|
||||||
|
if (s.len > 0) {
|
||||||
|
s = s ++ ", ";
|
||||||
|
}
|
||||||
|
s = s ++ @tagName(value);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build(b: *std.build.Builder) !void {
|
pub fn build(b: *std.build.Builder) !void {
|
||||||
const mode = b.standardReleaseOptions();
|
const mode = b.standardReleaseOptions();
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
@ -25,7 +51,7 @@ pub fn build(b: *std.build.Builder) !void {
|
|||||||
"src/MiniFB_timer.c",
|
"src/MiniFB_timer.c",
|
||||||
});
|
});
|
||||||
|
|
||||||
const use_opengl = b.option(bool, "opengl", "Use OpenGL") orelse false;
|
const use_backend = b.option(Backend, "backend", "Which rendering back-end to use (" ++ enumNames(Backend) ++ ")") orelse .default;
|
||||||
|
|
||||||
const lib = b.addStaticLibrary("minifb-zig-port", null);
|
const lib = b.addStaticLibrary("minifb-zig-port", null);
|
||||||
lib.addIncludeDir("src");
|
lib.addIncludeDir("src");
|
||||||
@ -37,29 +63,47 @@ pub fn build(b: *std.build.Builder) !void {
|
|||||||
switch (target.getOsTag()) {
|
switch (target.getOsTag()) {
|
||||||
std.Target.Os.Tag.windows => {
|
std.Target.Os.Tag.windows => {
|
||||||
try c_sources.append("src/windows/WinMiniFB.c");
|
try c_sources.append("src/windows/WinMiniFB.c");
|
||||||
lib.linkSystemLibraryName("gdi32");
|
lib.linkSystemLibrary("gdi32");
|
||||||
if (use_opengl) {
|
switch (use_backend) {
|
||||||
|
.gdi, .default => {},
|
||||||
|
.opengl => {
|
||||||
try c_flags.append("-DUSE_OPENGL_API");
|
try c_flags.append("-DUSE_OPENGL_API");
|
||||||
try c_sources.append("src/gl/MiniFB_GL.c");
|
try c_sources.append("src/gl/MiniFB_GL.c");
|
||||||
lib.linkSystemLibraryName("opengl32");
|
lib.linkSystemLibraryName("opengl32");
|
||||||
|
},
|
||||||
|
else => {
|
||||||
|
return ConfigError.BackendNotSupported;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
std.Target.Os.Tag.linux => {
|
std.Target.Os.Tag.linux => {
|
||||||
try c_sources.append("src/MiniFB_linux.c");
|
try c_sources.append("src/MiniFB_linux.c");
|
||||||
try c_sources.append("src/x11/X11MiniFB.c");
|
|
||||||
lib.linkSystemLibrary("rt");
|
lib.linkSystemLibrary("rt");
|
||||||
|
switch (use_backend) {
|
||||||
|
.x11, .default => {
|
||||||
|
try c_sources.append("src/x11/X11MiniFB.c");
|
||||||
|
lib.linkSystemLibrary("X11");
|
||||||
|
},
|
||||||
|
.opengl => {
|
||||||
|
try c_sources.append("src/x11/X11MiniFB.c");
|
||||||
lib.linkSystemLibrary("X11");
|
lib.linkSystemLibrary("X11");
|
||||||
|
|
||||||
if (use_opengl) {
|
|
||||||
try c_flags.append("-DUSE_OPENGL_API");
|
try c_flags.append("-DUSE_OPENGL_API");
|
||||||
try c_sources.append("src/gl/MiniFB_GL.c");
|
try c_sources.append("src/gl/MiniFB_GL.c");
|
||||||
lib.linkSystemLibrary("GL");
|
lib.linkSystemLibrary("GL");
|
||||||
}
|
},
|
||||||
|
.wayland => {
|
||||||
// TODO wayland
|
try c_sources.append("src/wayland/WaylandMiniFB.c");
|
||||||
|
lib.linkSystemLibrary("wayland-client");
|
||||||
|
lib.linkSystemLibrary("wayland-cursor");
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
return error.PlatformNotSupported;
|
return ConfigError.BackendNotSupported;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
else => {
|
||||||
|
return ConfigError.PlatformNotSupported;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user