This repository has been archived by the owner on Sep 28, 2023. It is now read-only.
generated from machlibs/template
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.zig
129 lines (110 loc) · 5.24 KB
/
build.zig
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const std = @import("std");
pub fn Package(comptime deps: anytype) type {
return struct {
pub const Backend = enum {
no_backend,
glfw_wgpu,
win32_dx12,
mach,
};
pub const Options = struct {
backend: Backend,
shared: bool = false,
};
options: Options,
zgui: *std.Build.Module,
zgui_options: *std.Build.Module,
zgui_c_cpp: *std.Build.CompileStep,
pub fn build(
b: *std.Build,
target: std.zig.CrossTarget,
optimize: std.builtin.Mode,
args: struct {
options: Options,
gpu_dawn_options: deps.gpu_dawn.Options,
},
) !@This() {
const step = b.addOptions();
step.addOption(Backend, "backend", args.options.backend);
step.addOption(bool, "shared", args.options.shared);
const zgui_options = step.createModule();
const zgui = b.createModule(.{
.source_file = .{ .path = thisDir() ++ "/src/main.zig" },
.dependencies = &.{
.{ .name = "zgui_options", .module = zgui_options },
},
});
const zgui_c_cpp = if (args.options.shared) blk: {
const lib = b.addSharedLibrary(.{
.name = "zgui",
.target = target,
.optimize = optimize,
});
b.installArtifact(lib);
if (target.isWindows()) {
lib.defineCMacro("IMGUI_API", "__declspec(dllexport)");
lib.defineCMacro("IMPLOT_API", "__declspec(dllexport)");
lib.defineCMacro("ZGUI_API", "__declspec(dllexport)");
}
break :blk lib;
} else b.addStaticLibrary(.{
.name = "zgui",
.target = target,
.optimize = optimize,
});
zgui_c_cpp.addIncludePath(thisDir() ++ "/libs");
zgui_c_cpp.addIncludePath(thisDir() ++ "/libs/imgui");
zgui_c_cpp.linkLibC();
zgui_c_cpp.linkLibCpp();
const cflags = &.{"-fno-sanitize=undefined"};
zgui_c_cpp.addCSourceFile(thisDir() ++ "/src/zgui.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_widgets.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_tables.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_draw.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_demo.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/implot_demo.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/implot.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/implot_items.cpp", cflags);
switch (args.options.backend) {
.mach => {
// zgui_c_cpp.addIncludePath(thisDir() ++ "/../zglfw/libs/glfw/include");
// zgui_c_cpp.addIncludePath(thisDir() ++ "/../zgpu/libs/dawn/include");
// zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_glfw.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_wgpu.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_impl_mach.cpp", cflags);
try deps.gpu_dawn.link(b, zgui_c_cpp, args.gpu_dawn_options);
},
.glfw_wgpu => {
zgui_c_cpp.addIncludePath(thisDir() ++ "/../zglfw/libs/glfw/include");
zgui_c_cpp.addIncludePath(thisDir() ++ "/../zgpu/libs/dawn/include");
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_glfw.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_wgpu.cpp", cflags);
},
.win32_dx12 => {
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_win32.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_dx12.cpp", cflags);
zgui_c_cpp.linkSystemLibraryName("d3dcompiler_47");
zgui_c_cpp.linkSystemLibraryName("dwmapi");
},
.no_backend => {},
}
return .{
.options = args.options,
.zgui = zgui,
.zgui_options = zgui_options,
.zgui_c_cpp = zgui_c_cpp,
};
}
pub fn link(zgui_pkg: @This(), exe: *std.Build.CompileStep) void {
exe.linkLibrary(zgui_pkg.zgui_c_cpp);
exe.addIncludePath(thisDir() ++ "/src");
exe.addIncludePath(thisDir() ++ "/libs");
exe.addIncludePath(thisDir() ++ "/libs/imgui");
}
};
}
pub fn build(_: *std.Build) void {}
inline fn thisDir() []const u8 {
return comptime std.fs.path.dirname(@src().file) orelse ".";
}