-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
134 lines (111 loc) · 3.53 KB
/
build.zig
File metadata and controls
134 lines (111 loc) · 3.53 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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimise = b.standardOptimizeOption(.{});
const enable_asserts = b.option(
bool,
"asserts",
"Enable/disable asserts. Always disabled in release builds (default - true)",
) orelse true;
const enable_profiling = b.option(
bool,
"profiling",
"Enable/disable profiling (default - true)",
) orelse true;
const enable_logging = b.option(
bool,
"logging",
"Enable/disable logging macros (default - true)",
) orelse true;
const target_linkage = b.option(
std.builtin.LinkMode,
"linkage",
"Whether to build a dynamic library instead of static [options: dynamic/static] (default - static)",
) orelse .static;
const build_examples = b.option(
bool,
"examples",
"Whether to build the examples (default - true)",
) orelse true;
const compile_flags = &[_][]const u8{
"-Wall",
"-Werror",
"-std=c++20",
};
const tails_mod = b.addModule("tails", .{
.target = target,
.optimize = optimise,
.link_libcpp = true,
});
const sdl_dep = b.dependency("sdl", .{
.target = target,
.optimize = optimise,
});
tails_mod.linkLibrary(sdl_dep.artifact("SDL3"));
tails_mod.addIncludePath(b.path("include"));
tails_mod.addIncludePath(b.path("src/stb"));
var sources = std.ArrayList([]const u8).empty;
{
const tails_src = "src/Tails";
var dir = try std.fs.openDirAbsolute(
b.pathJoin(&.{
b.build_root.path.?,
tails_src,
}),
.{
.iterate = true,
},
);
var walker = try dir.walk(b.allocator);
defer walker.deinit();
while (try walker.next()) |entry| {
const ext = std.fs.path.extension(entry.basename);
if (std.mem.eql(u8, ext, ".cpp")) {
try sources.append(b.allocator, b.pathJoin(&.{ tails_src, entry.path }));
}
}
}
tails_mod.addCSourceFiles(.{
.files = sources.items,
.flags = compile_flags,
.language = .cpp,
});
if (enable_asserts)
tails_mod.addCMacro("TAILS_ENABLE_ASSERTS", "");
if (enable_profiling)
tails_mod.addCMacro("TAILS_ENABLE_PROFILING", "");
if (enable_logging)
tails_mod.addCMacro("TAILS_ENABLE_LOGGING", "");
const tails_lib = b.addLibrary(.{
.name = "tails",
.linkage = target_linkage,
.root_module = tails_mod,
});
tails_lib.installHeadersDirectory(b.path("include/"), "", .{
.exclude_extensions = &.{"CMakeLists.txt"},
.include_extensions = &.{".hpp"},
});
b.installArtifact(tails_lib);
if (build_examples) {
const example_mod = b.createModule(.{
.target = target,
.optimize = optimise,
.link_libcpp = true,
});
example_mod.linkLibrary(tails_lib);
example_mod.addCSourceFiles(.{
.files = &.{
"example/main.cpp",
"example/Player.cpp",
},
.flags = compile_flags,
.language = .cpp,
});
example_mod.addIncludePath(b.path("include"));
const example_exe = b.addExecutable(.{
.name = "example",
.root_module = example_mod,
});
b.installArtifact(example_exe);
}
}