-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.zig
More file actions
117 lines (103 loc) · 4.92 KB
/
Copy pathbuild.zig
File metadata and controls
117 lines (103 loc) · 4.92 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const upstream = b.dependency("nativefiledialog-extended", .{});
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode") orelse .static;
const strip = b.option(bool, "strip", "Omit debug information");
const pic = b.option(bool, "pie", "Produce Position Independent Code");
const portal = b.option(bool, "portal", "Use xdg-desktop-portal instead of GTK") orelse false;
const append_extension = b.option(bool, "append-extension", "Automatically append file extension to an extensionless selection in SaveDialog()") orelse false;
const override_recent_with_default = b.option(bool, "override-recent-with-default", "Use defaultPath instead of recent folder on Windows") orelse false;
const flags: []const []const u8 = &.{
"-nostdlib",
"-fno-exceptions",
"-fno-rtti",
};
const nfd = b.addLibrary(.{
.linkage = linkage,
.name = "nfd",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.pic = pic,
.strip = strip,
}),
});
b.installArtifact(nfd);
nfd.root_module.addIncludePath(upstream.path("src/include"));
nfd.installHeadersDirectory(upstream.path("src/include"), "", .{ .include_extensions = &.{ ".h", ".hpp" } });
if (target.result.os.tag == .windows) {
nfd.root_module.link_libcpp = true;
nfd.root_module.addCSourceFile(.{ .file = upstream.path("src/nfd_win.cpp"), .flags = flags });
nfd.root_module.linkSystemLibrary("ole32", .{});
nfd.root_module.linkSystemLibrary("uuid", .{});
nfd.root_module.linkSystemLibrary("shell32", .{});
if (override_recent_with_default) nfd.root_module.addCMacro("NFD_OVERRIDE_RECENT_WITH_DEFAULT", "1");
} else if (target.result.os.tag.isDarwin()) {
// Whether this is correct is completely untested since I don't use macOS.
nfd.root_module.addCSourceFile(.{ .file = upstream.path("src/nfd_cocoa.m"), .flags = flags });
nfd.root_module.linkFramework("AppKit", .{});
// Zig has dropped support for MacOS 12
// https://github.com/ziglang/zig/commit/21f0fce28bcceb5ee227f456401f250d9c62b31b
nfd.root_module.addCMacro("NFD_MACOS_ALLOWEDCONTENTTYPES", "1");
nfd.root_module.linkFramework("UniformTypeIdentifiers", .{});
} else {
nfd.root_module.link_libcpp = true;
if (append_extension) nfd.root_module.addCMacro("NFD_APPEND_EXTENSION", "1");
if (portal) {
nfd.root_module.addCSourceFile(.{ .file = upstream.path("src/nfd_portal.cpp"), .flags = flags });
nfd.root_module.linkSystemLibrary("dbus-1", .{});
nfd.root_module.addCMacro("NFD_PORTAL", "1");
} else {
nfd.root_module.addCSourceFile(.{ .file = upstream.path("src/nfd_gtk.cpp"), .flags = flags });
nfd.root_module.linkSystemLibrary("gtk+-3.0", .{});
}
}
const install_tests_step = b.step("install-tests", "Install all test executables");
for (test_sources) |sub_path| {
const name = b.allocator.dupe(u8, std.Io.Dir.path.stem(sub_path)) catch @panic("OOM");
std.mem.replaceScalar(u8, name, '.', '-');
std.mem.replaceScalar(u8, name, '_', '-');
const test_exe = b.addExecutable(.{
.name = name,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.pic = pic,
.strip = strip,
.link_libc = true,
.link_libcpp = std.mem.eql(u8, std.Io.Dir.path.extension(sub_path), ".cpp"),
}),
});
test_exe.root_module.addCSourceFile(.{ .file = upstream.path(b.fmt("test/{s}", .{sub_path})), .flags = flags });
test_exe.root_module.linkLibrary(nfd);
install_tests_step.dependOn(&b.addInstallArtifact(test_exe, .{}).step);
const run_test_exe = b.addRunArtifact(test_exe);
const test_step = b.step(name, b.fmt("Run {s}", .{sub_path}));
test_step.dependOn(&run_test_exe.step);
}
}
const test_sources: []const []const u8 = &.{
"test_opendialog.c",
"test_opendialog_cpp.cpp",
"test_opendialog_native.c",
"test_opendialog_with.c",
"test_opendialog_native_with.c",
"test_opendialogmultiple.c",
"test_opendialogmultiple_cpp.cpp",
"test_opendialogmultiple_native.c",
"test_opendialogmultiple_enum.c",
"test_opendialogmultiple_enum_native.c",
"test_pickfolder.c",
"test_pickfolder_cpp.cpp",
"test_pickfolder_native.c",
"test_pickfolder_with.c",
"test_pickfolder_native_with.c",
"test_pickfoldermultiple.c",
"test_pickfoldermultiple_native.c",
"test_savedialog.c",
"test_savedialog_native.c",
"test_savedialog_with.c",
"test_savedialog_native_with.c",
};