summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorJeffrey C. Ollie <jeff@ocjtech.us>2024-12-28 13:40:17 -0600
committerJeffrey C. Ollie <jeff@ocjtech.us>2024-12-28 13:40:17 -0600
commit8ecb11a602d2adc526c403590ea1e8fe46209072 (patch)
tree6ed2af0ffa55977ee0a826c2f9fae09a5cc571b4 /build.zig
parent6cbd69da7839260508466f9dfb2bc0c0fbb43991 (diff)
gtk: add option to not link against libX11
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig47
1 files changed, 47 insertions, 0 deletions
diff --git a/build.zig b/build.zig
index 0e183efd1..614026572 100644
--- a/build.zig
+++ b/build.zig
@@ -105,6 +105,53 @@ pub fn build(b: *std.Build) !void {
"Enables the use of Adwaita when using the GTK rendering backend.",
) orelse true;
+ config.x11 = b.option(
+ bool,
+ "gtk-x11",
+ "Enables linking against X11 libraries when using the GTK rendering backend.",
+ ) orelse x11: {
+ if (target.result.os.tag != .linux) break :x11 false;
+
+ var pkgconfig = std.process.Child.init(&.{ "pkg-config", "--variable=targets", "gtk4" }, b.allocator);
+
+ pkgconfig.stdout_behavior = .Pipe;
+ pkgconfig.stderr_behavior = .Pipe;
+
+ try pkgconfig.spawn();
+
+ const output_max_size = 50 * 1024;
+
+ var stdout = std.ArrayList(u8).init(b.allocator);
+ var stderr = std.ArrayList(u8).init(b.allocator);
+ defer {
+ stdout.deinit();
+ stderr.deinit();
+ }
+
+ try pkgconfig.collectOutput(&stdout, &stderr, output_max_size);
+
+ const term = try pkgconfig.wait();
+
+ if (stderr.items.len > 0) {
+ std.log.warn("pkg-config had errors:\n{s}", .{stderr.items});
+ }
+
+ switch (term) {
+ .Exited => |code| {
+ if (code == 0) {
+ if (std.mem.indexOf(u8, stdout.items, "x11")) |_| break :x11 true;
+ break :x11 false;
+ }
+ std.log.warn("pkg-config: {s} with code {d}", .{ @tagName(term), code });
+ return error.Unexpected;
+ },
+ inline else => |code| {
+ std.log.warn("pkg-config: {s} with code {d}", .{ @tagName(term), code });
+ return error.Unexpected;
+ },
+ }
+ };
+
const pie = b.option(
bool,
"pie",