-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.zig
133 lines (114 loc) · 3.59 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
128
129
130
131
132
133
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const mode = b.standardOptimizeOption(.{});
// Module
_ = b.addModule("Qt", .{
.root_source_file = b.path("src/Qt.zig"),
});
// Note: If it is not necessary to compile DOtherSide library, please comment on this line.
const cmake = cmakeBuild(b);
const cmake_step = b.step("cmake", "Run cmake build");
cmake_step.dependOn(&cmake.step);
// Original examples
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/animated.zig",
});
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/hello.zig",
});
// More examples
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/button.zig",
});
// Copypasta from the Go QML eamples https://github.com/go-qml/qml/tree/v1/examples
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/particle.zig",
});
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/layouts.zig",
});
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/splitview.zig",
});
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/tableview.zig",
});
// Cloned simple examples from the Qml doco
try makeExample(b, .{
.optimize = mode,
.target = target,
.path = "examples/cells.zig",
});
}
fn makeExample(b: *std.Build, src: BuildInfo) !void {
const example = b.addExecutable(.{
.name = src.filename(),
.root_source_file = b.path(src.path),
.optimize = src.optimize,
.target = src.target,
});
//Strip file
if (src.optimize != .Debug) {
example.root_module.strip = true;
}
example.root_module.addImport("Qt", b.modules.get("Qt").?);
example.addLibraryPath(b.path(".zig-cache/lib"));
if (example.rootModuleTarget().os.tag == .windows) {
example.want_lto = false;
example.linkSystemLibrary2("DOtherSide.dll", .{ .use_pkg_config = .no });
} else example.linkSystemLibrary("DOtherSide");
example.linkLibC();
b.installArtifact(example);
const run_cmd = b.addRunArtifact(example);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const descr = b.fmt("Run the {s} example", .{src.filename()});
const run_step = b.step(src.filename(), descr);
run_step.dependOn(&run_cmd.step);
}
pub fn cmakeBuild(b: *std.Build) *std.Build.Step.Run {
const dotherside = b.dependency("dotherside", .{}).path("").getPath(b);
// CMake builds - DOtherSide build
const DOtherSide_configure = b.addSystemCommand(&[_][]const u8{
"cmake",
"-B",
".zig-cache",
"-S",
dotherside,
"-DCMAKE_BUILD_TYPE=RelMinSize",
});
const DOtherSide_build = b.addSystemCommand(&[_][]const u8{
"cmake",
"--build",
".zig-cache",
"--parallel",
});
DOtherSide_build.step.dependOn(&DOtherSide_configure.step);
return DOtherSide_build;
}
const BuildInfo = struct {
path: []const u8,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
fn filename(self: BuildInfo) []const u8 {
var split = std.mem.splitSequence(u8, std.fs.path.basename(self.path), ".");
return split.first();
}
};