-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
126 lines (112 loc) · 3.46 KB
/
build.zig
File metadata and controls
126 lines (112 loc) · 3.46 KB
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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Build SDL3 via cmake as a static library
const cmake_configure = b.addSystemCommand(&.{
"cmake",
"-S", "vendor/SDL3",
"-B", "vendor/SDL3/build",
"-G", "Ninja",
"-DCMAKE_BUILD_TYPE=Release",
"-DCMAKE_C_COMPILER=zig",
"-DCMAKE_C_COMPILER_ARG1=cc",
"-DCMAKE_CXX_COMPILER=zig",
"-DCMAKE_CXX_COMPILER_ARG1=c++",
"-DSDL_SHARED=OFF",
"-DSDL_STATIC=ON",
"-DSDL_TESTS=OFF",
"-DSDL_EXAMPLES=OFF",
});
const cmake_build = b.addSystemCommand(&.{
"cmake",
"--build", "vendor/SDL3/build",
"--config", "Release",
});
cmake_build.step.dependOn(&cmake_configure.step);
// Create module for C compilation
const mod = b.createModule(.{
.root_source_file = null,
.target = target,
.optimize = optimize,
.link_libc = true,
});
mod.addIncludePath(b.path("vendor/SDL3/include"));
mod.addIncludePath(b.path("src"));
// C source files
const c_flags = &.{
"-std=c99",
"-DWOLF3D_SDL3",
"-gcodeview",
"-O0",
"-Wno-pointer-sign",
"-Wno-implicit-function-declaration",
"-Wno-incompatible-function-pointer-types",
"-Wno-deprecated-non-prototype",
"-Wno-nonportable-include-path",
"-Wno-int-conversion",
"-Wno-enum-conversion",
};
const sources = [_][]const u8{
"src/sdl3_main.c",
"src/sdl3_vid.c",
"src/sdl3_in.c",
"src/sdl3_sd.c",
"src/mcp.c",
"src/id_ca.c",
"src/id_in.c",
"src/id_mm.c",
"src/id_pm.c",
"src/id_sd.c",
"src/id_us_1.c",
"src/id_vh.c",
"src/id_vl.c",
"src/wl_act1.c",
"src/wl_act2.c",
"src/wl_agent.c",
"src/wl_debug.c",
"src/wl_draw.c",
"src/wl_game.c",
"src/wl_inter.c",
"src/wl_main.c",
"src/wl_menu.c",
"src/wl_play.c",
"src/wl_scale.c",
"src/wl_state.c",
"src/wl_text.c",
};
inline for (sources) |source| {
mod.addCSourceFile(.{ .file = b.path(source), .flags = c_flags });
}
// Link SDL3 static library
mod.addLibraryPath(b.path("vendor/SDL3/build"));
mod.linkSystemLibrary("SDL3", .{});
// Windows system libraries required by SDL3
if (target.result.os.tag == .windows) {
mod.linkSystemLibrary("user32", .{});
mod.linkSystemLibrary("gdi32", .{});
mod.linkSystemLibrary("winmm", .{});
mod.linkSystemLibrary("imm32", .{});
mod.linkSystemLibrary("ole32", .{});
mod.linkSystemLibrary("oleaut32", .{});
mod.linkSystemLibrary("shell32", .{});
mod.linkSystemLibrary("version", .{});
mod.linkSystemLibrary("setupapi", .{});
mod.linkSystemLibrary("dbghelp", .{});
}
// Wolf3D executable
const exe = b.addExecutable(.{
.name = "wolf3d",
.root_module = mod,
});
exe.step.dependOn(&cmake_build.step);
b.installArtifact(exe);
// Add 'zig build run' step
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 the game");
run_step.dependOn(&run_cmd.step);
}