summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig61
1 files changed, 61 insertions, 0 deletions
diff --git a/build.zig b/build.zig
new file mode 100644
index 0000000..96808aa
--- /dev/null
+++ b/build.zig
@@ -0,0 +1,61 @@
+const std = @import("std");
+
+pub fn build(b: *std.Build) !void {
+ const opengl = b.option(bool, "opengl", "Exposes OpenGL helper functions in RGFW.h and links OpenGL. Default: true") orelse true;
+ const x11 = b.option(bool, "x11", "X11 backend. Default: true") orelse true;
+
+ const target = b.standardTargetOptions(.{});
+ const optimize = b.standardOptimizeOption(.{});
+ var macros = std.ArrayList([2][]const u8).empty;
+ defer macros.deinit(b.allocator);
+ var syslibs = std.ArrayList(struct {[]const u8, std.Build.Module.LinkSystemLibraryOptions}).empty;
+ defer syslibs.deinit(b.allocator);
+
+ try macros.append(b.allocator, [2][]const u8{"RSGL_RFONT", ""});
+
+ if (target.result.os.tag == std.Target.Os.Tag.linux or target.result.os.tag == std.Target.Os.Tag.macos)
+ try macros.append(b.allocator, [2][]const u8{"RGFW_UNIX", ""});
+
+ if (x11) {
+ try macros.append(b.allocator, [2][]const u8{"RGFW_X11", ""});
+ try syslibs.append(b.allocator, struct {[]const u8, std.Build.Module.LinkSystemLibraryOptions}{"X11", .{}});
+ try syslibs.append(b.allocator, struct {[]const u8, std.Build.Module.LinkSystemLibraryOptions}{"Xrandr", .{}});
+ } else {
+ try macros.append(b.allocator, [2][]const u8{"RGFW_NO_X11", ""});
+ }
+ if (opengl) {
+ try macros.append(b.allocator, [2][]const u8{"RGFW_OPENGL", ""});
+ try syslibs.append(b.allocator, struct {[]const u8, std.Build.Module.LinkSystemLibraryOptions}{"GL", .{}});
+ } else {
+ std.debug.panic("no backend other than OpenGL supported by RSGL.h", .{});
+ }
+
+ const rgfw_raw_c = b.addTranslateC(.{
+ .root_source_file = b.path("include/RGFW.h"),
+ .target = target,
+ .optimize = optimize,
+ });
+ for (macros.items) |macro| {rgfw_raw_c.defineCMacro(macro[0], macro[1]);}
+ _ = rgfw_raw_c.addModule("rgfw_raw");
+
+ const rsgl_raw_c = b.addTranslateC(.{
+ .root_source_file = b.path("include/RSGL_gl.h"),
+ .target = target,
+ .optimize = optimize,
+ });
+ for (macros.items) |macro| {rsgl_raw_c.defineCMacro(macro[0], macro[1]);}
+ const rsgl_raw_mod = rsgl_raw_c.addModule("rsgl_raw");
+
+ const rsgl_mod = b.addModule("rsgl", .{
+ .root_source_file = b.path("rsgl.zig"),
+ .target = target,
+ .optimize = optimize,
+ .imports = &.{
+ .{.name = "rsgl_raw", .module = rsgl_raw_mod},
+ },
+ });
+ rsgl_mod.addCMacro("RSGL_IMPLEMENTATION", "");
+ rsgl_mod.addIncludePath(b.path("include"));
+ rsgl_mod.addCSourceFile(.{.file = b.addWriteFiles().add("rsgl_gl.c", "#include <RSGL_gl.h>"),});
+ for (syslibs.items) |lib| {rsgl_mod.linkSystemLibrary(lib[0], lib[1]);}
+} \ No newline at end of file