glfw: prepare build system to support runtime Wayland/X11 detection
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
05a2118ef5
commit
e328c652d0
1 changed files with 23 additions and 17 deletions
40
build.zig
40
build.zig
|
@ -35,7 +35,12 @@ pub const Options = struct {
|
|||
gles: bool = false,
|
||||
|
||||
/// Only respected on Linux.
|
||||
linux_window_manager: LinuxWindowManager = .X11,
|
||||
x11: bool = true,
|
||||
|
||||
/// Only respected on Linux.
|
||||
// TODO(build-system): update wayland-protocol source generation in linux system SDKs so we can
|
||||
// turn this on by default.
|
||||
wayland: bool = false,
|
||||
|
||||
/// System SDK options.
|
||||
system_sdk: system_sdk.Options = .{},
|
||||
|
@ -86,17 +91,20 @@ fn buildLibrary(b: *Builder, step: *std.build.LibExeObjStep, options: Options) *
|
|||
lib.setTarget(step.target);
|
||||
|
||||
var sources = std.ArrayList([]const u8).init(b.allocator);
|
||||
const flag = switch (options.linux_window_manager) {
|
||||
.X11 => "-D_GLFW_X11",
|
||||
.Wayland => "-D_GLFW_WAYLAND",
|
||||
};
|
||||
var flags = std.ArrayList([]const u8).init(b.allocator);
|
||||
sources.append(thisDir() ++ "/src/sources_all.c") catch unreachable;
|
||||
sources.append(thisDir() ++ "/src/sources_linux.c") catch unreachable;
|
||||
switch (options.linux_window_manager) {
|
||||
.X11 => sources.append(thisDir() ++ "/src/sources_linux_x11.c") catch unreachable,
|
||||
.Wayland => sources.append(thisDir() ++ "/src/sources_linux_wayland.c") catch unreachable,
|
||||
if (options.x11) {
|
||||
sources.append(thisDir() ++ "/src/sources_linux_x11.c") catch unreachable;
|
||||
flags.append("-D_GLFW_X11") catch unreachable;
|
||||
}
|
||||
lib.addCSourceFiles(sources.items, &.{ flag, "-I" ++ thisDir() ++ "/upstream/glfw/src" });
|
||||
if (options.wayland) {
|
||||
sources.append(thisDir() ++ "/src/sources_linux_wayland.c") catch unreachable;
|
||||
flags.append("-D_GLFW_WAYLAND") catch unreachable;
|
||||
}
|
||||
flags.append("-I" ++ thisDir() ++ "/upstream/glfw/src") catch unreachable;
|
||||
|
||||
lib.addCSourceFiles(sources.items, flags.items);
|
||||
},
|
||||
}
|
||||
linkGLFWDependencies(b, lib, options);
|
||||
|
@ -162,14 +170,12 @@ fn linkGLFWDependencies(b: *Builder, step: *std.build.LibExeObjStep, options: Op
|
|||
},
|
||||
else => {
|
||||
// Assume Linux-like
|
||||
switch (options.linux_window_manager) {
|
||||
.X11 => {
|
||||
step.linkSystemLibraryName("X11");
|
||||
step.linkSystemLibraryName("xcb");
|
||||
step.linkSystemLibraryName("Xau");
|
||||
step.linkSystemLibraryName("Xdmcp");
|
||||
},
|
||||
.Wayland => step.linkSystemLibraryName("wayland-client"),
|
||||
if (options.wayland) step.linkSystemLibraryName("wayland-client");
|
||||
if (options.x11) {
|
||||
step.linkSystemLibraryName("X11");
|
||||
step.linkSystemLibraryName("xcb");
|
||||
step.linkSystemLibraryName("Xau");
|
||||
step.linkSystemLibraryName("Xdmcp");
|
||||
}
|
||||
// Note: no need to link against vulkan, GLFW finds it dynamically at runtime.
|
||||
// https://www.glfw.org/docs/3.3/vulkan_guide.html#vulkan_loader
|
||||
|
|
Loading…
Add table
Reference in a new issue