-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
146 lines (129 loc) · 4.86 KB
/
Copy pathbuild.zig
File metadata and controls
146 lines (129 loc) · 4.86 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
// We wrap cmake in sh -c so we can prepend $PWD to PATH, letting cmake find
// the zig-cc / zig-c++ wrapper scripts that live in the project root.
const osx_arch = switch (target.result.cpu.arch) {
.aarch64 => "arm64",
.x86_64 => "x86_64",
else => null,
};
const cmake_shell_cmd = if (target.result.os.tag == .macos and osx_arch != null)
b.fmt("PATH=\"$PWD:$PATH\" cmake -S vendor/SDL3 -B vendor/SDL3/build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=zig-cc -DCMAKE_CXX_COMPILER=zig-c++ -DCMAKE_OBJC_COMPILER=zig-cc -DSDL_SHARED=OFF -DSDL_STATIC=ON -DSDL_TESTS=OFF -DSDL_EXAMPLES=OFF -DCMAKE_OSX_ARCHITECTURES={s}", .{osx_arch.?})
else
"PATH=\"$PWD:$PATH\" cmake -S vendor/SDL3 -B vendor/SDL3/build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=zig-cc -DCMAKE_CXX_COMPILER=zig-c++ -DCMAKE_OBJC_COMPILER=zig-cc -DSDL_SHARED=OFF -DSDL_STATIC=ON -DSDL_TESTS=OFF -DSDL_EXAMPLES=OFF";
const cmake_configure = b.addSystemCommand(&.{
"sh", "-c", cmake_shell_cmd,
});
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("vendor/nuked-opl3"));
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_sd.c",
"vendor/nuked-opl3/opl3.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_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", .{});
}
// macOS frameworks required by SDL3
if (target.result.os.tag == .macos) {
mod.linkSystemLibrary("objc", .{});
mod.linkFramework("Cocoa", .{});
mod.linkFramework("CoreFoundation", .{});
mod.linkFramework("CoreAudio", .{});
mod.linkFramework("AudioToolbox", .{});
mod.linkFramework("CoreVideo", .{});
mod.linkFramework("CoreMedia", .{});
mod.linkFramework("AVFoundation", .{});
mod.linkFramework("IOKit", .{});
mod.linkFramework("Metal", .{});
mod.linkFramework("QuartzCore", .{});
mod.linkFramework("GameController", .{});
mod.linkFramework("ForceFeedback", .{});
mod.linkFramework("UniformTypeIdentifiers", .{});
mod.linkFramework("CoreHaptics", .{});
mod.linkFramework("Carbon", .{});
}
// 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);
}