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
32
build.zig
32
build.zig
|
@ -35,7 +35,12 @@ pub const Options = struct {
|
||||||
gles: bool = false,
|
gles: bool = false,
|
||||||
|
|
||||||
/// Only respected on Linux.
|
/// 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 options.
|
||||||
system_sdk: 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);
|
lib.setTarget(step.target);
|
||||||
|
|
||||||
var sources = std.ArrayList([]const u8).init(b.allocator);
|
var sources = std.ArrayList([]const u8).init(b.allocator);
|
||||||
const flag = switch (options.linux_window_manager) {
|
var flags = std.ArrayList([]const u8).init(b.allocator);
|
||||||
.X11 => "-D_GLFW_X11",
|
|
||||||
.Wayland => "-D_GLFW_WAYLAND",
|
|
||||||
};
|
|
||||||
sources.append(thisDir() ++ "/src/sources_all.c") catch unreachable;
|
sources.append(thisDir() ++ "/src/sources_all.c") catch unreachable;
|
||||||
sources.append(thisDir() ++ "/src/sources_linux.c") catch unreachable;
|
sources.append(thisDir() ++ "/src/sources_linux.c") catch unreachable;
|
||||||
switch (options.linux_window_manager) {
|
if (options.x11) {
|
||||||
.X11 => sources.append(thisDir() ++ "/src/sources_linux_x11.c") catch unreachable,
|
sources.append(thisDir() ++ "/src/sources_linux_x11.c") catch unreachable;
|
||||||
.Wayland => sources.append(thisDir() ++ "/src/sources_linux_wayland.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);
|
linkGLFWDependencies(b, lib, options);
|
||||||
|
@ -162,14 +170,12 @@ fn linkGLFWDependencies(b: *Builder, step: *std.build.LibExeObjStep, options: Op
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
// Assume Linux-like
|
// Assume Linux-like
|
||||||
switch (options.linux_window_manager) {
|
if (options.wayland) step.linkSystemLibraryName("wayland-client");
|
||||||
.X11 => {
|
if (options.x11) {
|
||||||
step.linkSystemLibraryName("X11");
|
step.linkSystemLibraryName("X11");
|
||||||
step.linkSystemLibraryName("xcb");
|
step.linkSystemLibraryName("xcb");
|
||||||
step.linkSystemLibraryName("Xau");
|
step.linkSystemLibraryName("Xau");
|
||||||
step.linkSystemLibraryName("Xdmcp");
|
step.linkSystemLibraryName("Xdmcp");
|
||||||
},
|
|
||||||
.Wayland => step.linkSystemLibraryName("wayland-client"),
|
|
||||||
}
|
}
|
||||||
// Note: no need to link against vulkan, GLFW finds it dynamically at runtime.
|
// 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
|
// https://www.glfw.org/docs/3.3/vulkan_guide.html#vulkan_loader
|
||||||
|
|
Loading…
Add table
Reference in a new issue