-
Notifications
You must be signed in to change notification settings - Fork 23
/
build.zig
66 lines (55 loc) · 2.04 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
const std = @import("std");
const builtin = @import("builtin");
const path = std.fs.path;
const Builder = std.build.Builder;
const LibExeObjStep = std.build.LibExeObjStep;
const imgui_build = @import("zig-imgui/imgui_build.zig");
const glslc_command = if (builtin.os.tag == .windows) "tools/win/glslc.exe" else "glslc";
pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const target = b.standardTargetOptions(.{});
imgui_build.addTestStep(b, "test", mode, target);
{
const exe = exampleExe(b, "example_glfw_vulkan", mode, target);
linkGlfw(exe, target);
linkVulkan(exe, target);
}
{
const exe = exampleExe(b, "example_glfw_opengl3", mode, target);
linkGlfw(exe, target);
linkGlad(exe, target);
}
}
fn exampleExe(b: *Builder, comptime name: []const u8, mode: std.builtin.Mode, target: std.zig.CrossTarget) *LibExeObjStep {
const exe = b.addExecutable(name, "examples/" ++ name ++ ".zig");
exe.setBuildMode(mode);
exe.setTarget(target);
imgui_build.link(exe);
exe.install();
const run_step = b.step(name, "Run " ++ name);
const run_cmd = exe.run();
run_step.dependOn(&run_cmd.step);
return exe;
}
fn linkGlad(exe: *LibExeObjStep, target: std.zig.CrossTarget) void {
_ = target;
exe.addIncludeDir("examples/include/c_include");
exe.addCSourceFile("examples/c_src/glad.c", &[_][]const u8{"-std=c99"});
//exe.linkSystemLibrary("opengl");
}
fn linkGlfw(exe: *LibExeObjStep, target: std.zig.CrossTarget) void {
if (target.isWindows()) {
exe.addObjectFile(if (target.getAbi() == .msvc) "examples/lib/win/glfw3.lib" else "examples/lib/win/libglfw3.a");
exe.linkSystemLibrary("gdi32");
exe.linkSystemLibrary("shell32");
} else {
exe.linkSystemLibrary("glfw");
}
}
fn linkVulkan(exe: *LibExeObjStep, target: std.zig.CrossTarget) void {
if (target.isWindows()) {
exe.addObjectFile("examples/lib/win/vulkan-1.lib");
} else {
exe.linkSystemLibrary("vulkan");
}
}