1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
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 = b.addTranslateC(.{
.root_source_file = b.path("include/RGFW.h"),
.target = target,
.optimize = optimize,
});
for (macros.items) |macro| {rgfw_raw.defineCMacro(macro[0], macro[1]);}
const rgfw_raw_mod = rgfw_raw.addModule("rgfw_raw");
const rsgl_raw = b.addTranslateC(.{
.root_source_file = b.path("include/RSGL_gl.h"),
.target = target,
.optimize = optimize,
});
for (macros.items) |macro| {rsgl_raw.defineCMacro(macro[0], macro[1]);}
const rsgl_raw_mod = rsgl_raw.addModule("rsgl");
const rsgl_mod = b.createModule(.{
.root_source_file = b.path("rsgl.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{.name = "rsgl_raw", .module = rsgl_raw_mod},
},
});
const term = b.createModule(.{
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{.name = "rgfw_raw", .module = rgfw_raw_mod},
.{.name = "rsgl_raw", .module = rsgl_raw_mod},
.{.name = "rsgl", .module = rsgl_mod},
},
});
term.addCMacro("RGFW_IMPLEMENTATION", "");
term.addCMacro("RFONT_IMPLEMENTATION", "");
term.addCMacro("RSGL_IMPLEMENTATION", "");
for (macros.items) |macro| {term.addCMacro(macro[0], macro[1]);}
term.addIncludePath(b.path("include"));
term.addCSourceFile(.{.file = b.addWriteFiles().add("rgfw.c", "#include <RSGL_gl.h>\n#include <RGFW.h>"),});
for (syslibs.items) |lib| {term.linkSystemLibrary(lib[0], lib[1]);}
const exe = b.addExecutable(.{
.name = "term",
.root_module = term,
});
b.installArtifact(exe);
const run_exe = b.addRunArtifact(exe);
const run_step = b.step("run", "Run the application");
run_step.dependOn(&run_exe.step);
}
|