-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
127 lines (104 loc) · 4.08 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
const std = @import("std");
const GPA = std.heap.GeneralPurposeAllocator;
var gpa = GPA(.{}){};
pub fn build(b: *std.Build) void {
var allocator = gpa.allocator();
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "ZigNES",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize
});
const imgui = b.addStaticLibrary(.{
.name = "imgui",
.target = target,
.optimize = optimize
});
imgui.linkLibCpp();
imgui.addCSourceFiles(.{
.files = &[_][]const u8{
"libs/cimgui/cimgui.cpp",
"libs/cimgui/imgui/imgui.cpp",
"libs/cimgui/imgui/imgui_demo.cpp",
"libs/cimgui/imgui/imgui_draw.cpp",
"libs/cimgui/imgui/imgui_tables.cpp",
"libs/cimgui/imgui/backends/imgui_impl_sdl2.cpp",
"libs/cimgui/imgui/backends/imgui_impl_opengl3.cpp",
"libs/cimgui/imgui/imgui_widgets.cpp",
},
.flags = &[_][]const u8{
"-std=c++17",
// "-DCIMGUI_DEFINE_ENUMS_AND_STRUCTS",
"-DIMGUI_IMPL_API=extern \"C\" __declspec(dllexport)",
"-DCIMGUI_USE_SDL2",
"-DCIMGUI_USE_OPENGL3"
}
});
const sdl2_path = std.process.getEnvVarOwned(allocator, "SDL2_PATH") catch {
std.debug.print("Build Error: ENV variable 'SDL2_PATH' not found", .{});
return;
};
defer allocator.free(sdl2_path);
const sdl2_include_path = std.process.getEnvVarOwned(allocator, "SDL2_INCLUDE_PATH") catch {
std.debug.print("Build Error: ENV variable 'SDL2_INCLUDE_PATH' not found", .{});
return;
};
defer allocator.free(sdl2_include_path);
const sdl2_dll_path = std.fs.path.join(allocator, &.{sdl2_path, "SDL2.dll"}) catch |err| {
std.debug.print("{s}", .{@errorName(err)});
return;
};
defer allocator.free(sdl2_dll_path);
imgui.addIncludePath(b.path("./libs/cimgui/imgui"));
imgui.addIncludePath(.{.cwd_relative = sdl2_include_path});
imgui.addLibraryPath(.{.cwd_relative = sdl2_path});
imgui.linkSystemLibrary("opengl32");
imgui.linkSystemLibrary("sdl2");
exe.addIncludePath(b.path("./libs/cimgui"));
exe.addIncludePath(b.path("./libs/cimgui/generator/output"));
exe.linkLibrary(imgui);
exe.addIncludePath(.{.cwd_relative = sdl2_include_path});
exe.addLibraryPath(.{.cwd_relative = sdl2_path});
b.getInstallStep().dependOn(&b.addInstallFileWithDir(.{.cwd_relative = sdl2_dll_path}, .bin, "SDL2.dll").step);
// b.installBinFile(sdl2_dll_path, "SDL2.dll");
const glew_path = std.process.getEnvVarOwned(allocator, "GLEW_PATH") catch {
std.debug.print("Build Error: ENV variable 'GLEW_PATH' not found", .{});
return;
};
defer allocator.free(glew_path);
const glew_include_path = std.process.getEnvVarOwned(allocator, "GLEW_INCLUDE_PATH") catch {
std.debug.print("Build Error: ENV variable 'GLEW_INCLUDE_PATH' not found", .{});
return;
};
defer allocator.free(glew_include_path);
exe.addIncludePath(.{.cwd_relative = glew_include_path});
exe.addLibraryPath(.{.cwd_relative = glew_path});
exe.linkSystemLibrary("opengl32");
exe.linkSystemLibrary("sdl2");
exe.linkSystemLibrary("glew32");
exe.linkLibC();
// Only output debug messages in debug build
if (optimize == .Debug) {
exe.subsystem = .Console;
} else {
exe.subsystem = .Windows;
}
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run ZigNES");
run_step.dependOn(&run_cmd.step);
const tests = b.addTest(.{
.root_source_file = b.path("./src/tests.zig"),
.target = target,
.optimize = optimize
});
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_tests.step);
}