-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.zig
95 lines (76 loc) · 2.79 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
const std = @import("std");
const builtin = @import("builtin");
const mach_core = @import("mach_core");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const use_freetype = b.option(bool, "use_freetype", "Use Freetype") orelse false;
const mach_core_dep = b.dependency("mach_core", .{
.target = target,
.optimize = optimize,
});
const module = b.addModule("zig-imgui", .{
.root_source_file = .{ .path = "src/imgui.zig" },
.imports = &.{
.{ .name = "mach-core", .module = mach_core_dep.module("mach-core") },
},
});
const lib = b.addStaticLibrary(.{
.name = "imgui",
.target = target,
.optimize = optimize,
});
lib.linkLibC();
const imgui_dep = b.dependency("imgui", .{});
var files = std.ArrayList([]const u8).init(b.allocator);
defer files.deinit();
var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit();
try files.appendSlice(&.{
"src/cimgui.cpp",
imgui_dep.path("imgui.cpp").getPath(b),
imgui_dep.path("imgui_widgets.cpp").getPath(b),
imgui_dep.path("imgui_tables.cpp").getPath(b),
imgui_dep.path("imgui_draw.cpp").getPath(b),
imgui_dep.path("imgui_demo.cpp").getPath(b),
});
if (use_freetype) {
try flags.append("-DIMGUI_ENABLE_FREETYPE");
try files.append("imgui/misc/freetype/imgui_freetype.cpp");
lib.linkLibrary(b.dependency("freetype", .{
.target = target,
.optimize = optimize,
}).artifact("freetype"));
}
lib.addIncludePath(imgui_dep.path("."));
lib.addCSourceFiles(.{
.files = files.items,
.flags = flags.items,
});
b.installArtifact(lib);
// Example
const build_options = b.addOptions();
const app = try mach_core.App.init(b, mach_core_dep.builder, .{
.name = "mach-imgui-example",
.src = "examples/example_mach.zig",
.target = target,
.deps = &[_]std.Build.Module.Import{
.{ .name = "imgui", .module = module },
.{ .name = "build-options", .module = build_options.createModule() },
},
.optimize = optimize,
});
app.compile.linkLibrary(lib);
const run_step = b.step("run", "Run the example");
run_step.dependOn(&app.run.step);
// Generator
const generator_exe = b.addExecutable(.{
.name = "mach-imgui-generator",
.root_source_file = .{ .path = "src/generate.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(generator_exe);
const generate_step = b.step("generate", "Generate the bindings");
generate_step.dependOn(&b.addRunArtifact(generator_exe).step);
}