-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
68 lines (56 loc) · 2.11 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
const std = @import("std");
const libnoise = @import("3rdparty/libnoise/build.zig");
const Builder = std.build.Builder;
const LibExeObjStep = std.build.LibExeObjStep;
const NoCArgs: *const [0][]const u8 = &[_][]const u8{};
const CxxArgs = &[_][]const u8{"-std=c++17"};
pub fn build(b: *std.build.Builder) !void {
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const exe = b.addExecutable(.{
.name = "planner-demo",
.optimize = mode,
.target = target,
});
// Add this app's sources
try addSourceFilesFrom(b, exe, "src/");
// Add dependencies
try addSourceFilesFrom(b, exe, "./3rdparty/yaml-cpp/src/");
try libnoise.addLibnoise(b, exe);
// Add includes
exe.addIncludePath("include");
exe.addIncludePath("3rdparty/yaml-cpp/include");
exe.addIncludePath("3rdparty/generated");
// Configure options
exe.defineCMacro("ENABLE_LIBNOISE", "1");
exe.defineCMacro("OpenGL_GL_PREFERENCE", "LEGACY");
// Link system libraries
exe.linkLibC();
exe.linkLibCpp();
exe.linkSystemLibrary("X11");
exe.linkSystemLibrary("GL");
exe.linkSystemLibrary("pthread");
exe.linkSystemLibrary("png");
b.installArtifact(exe);
// Run the application
const run = b.step("run", "Run the application");
const runner = b.addRunArtifact(exe);
run.dependOn(&runner.step);
}
// Add all .cpp files from the given path
fn addSourceFilesFrom(b: *Builder, step: *LibExeObjStep, path: []const u8) !void {
var dir = std.fs.cwd().openIterableDir(path, .{}) catch {
std.debug.print("Unable to open path '{s}'!", .{path});
return;
};
var it = dir.iterate();
while (try it.next()) |file| {
if (file.kind != .File or !std.mem.endsWith(u8, file.name, ".cpp")) {
continue;
}
const name = try std.fmt.allocPrint(b.allocator, "{s}/{s}", .{ path, file.name });
step.addCSourceFile(name, CxxArgs);
}
}