Support Wayland in build.zig
This commit is contained in:
parent
954352db4f
commit
35c01159c2
74
build.zig
74
build.zig
@ -9,6 +9,32 @@ const base_cflags: []const []const u8 = &.{
|
||||
"-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 {
|
||||
const mode = b.standardReleaseOptions();
|
||||
const target = b.standardTargetOptions(.{});
|
||||
@ -25,7 +51,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
"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);
|
||||
lib.addIncludeDir("src");
|
||||
@ -37,29 +63,47 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
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");
|
||||
lib.linkSystemLibrary("gdi32");
|
||||
switch (use_backend) {
|
||||
.gdi, .default => {},
|
||||
.opengl => {
|
||||
try c_flags.append("-DUSE_OPENGL_API");
|
||||
try c_sources.append("src/gl/MiniFB_GL.c");
|
||||
lib.linkSystemLibraryName("opengl32");
|
||||
},
|
||||
else => {
|
||||
return ConfigError.BackendNotSupported;
|
||||
}
|
||||
}
|
||||
},
|
||||
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");
|
||||
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");
|
||||
|
||||
if (use_opengl) {
|
||||
try c_flags.append("-DUSE_OPENGL_API");
|
||||
try c_sources.append("src/gl/MiniFB_GL.c");
|
||||
lib.linkSystemLibrary("GL");
|
||||
try c_flags.append("-DUSE_OPENGL_API");
|
||||
try c_sources.append("src/gl/MiniFB_GL.c");
|
||||
lib.linkSystemLibrary("GL");
|
||||
},
|
||||
.wayland => {
|
||||
try c_sources.append("src/wayland/WaylandMiniFB.c");
|
||||
lib.linkSystemLibrary("wayland-client");
|
||||
lib.linkSystemLibrary("wayland-cursor");
|
||||
},
|
||||
else => {
|
||||
return ConfigError.BackendNotSupported;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO wayland
|
||||
},
|
||||
else => {
|
||||
return error.PlatformNotSupported;
|
||||
return ConfigError.PlatformNotSupported;
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user