134 lines
4.2 KiB
Zig
134 lines
4.2 KiB
Zig
const std = @import("std");
|
|
|
|
const CFLAGS: []const []const u8 = &.{
|
|
"-std=c99",
|
|
"-Wall",
|
|
};
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const vm_dep = b.dependency("vecmath", .{ .target = target });
|
|
const vm_mod = vm_dep.module("vecmath");
|
|
|
|
const mod = b.addModule("glfw", .{
|
|
.root_source_file = b.path("src/root.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
.imports = &.{
|
|
.{ .name = "vecmath", .module = vm_mod },
|
|
},
|
|
});
|
|
|
|
// Add includes
|
|
|
|
mod.addIncludePath(b.path("vendor/include"));
|
|
switch (target.result.os.tag) {
|
|
.windows => {},
|
|
.linux => {
|
|
mod.addIncludePath(b.path("vendor/wayland"));
|
|
if (b.lazyDependency("system_sdk", .{})) |system_sdk| {
|
|
mod.addSystemIncludePath(system_sdk.path("linux/include"));
|
|
mod.addSystemIncludePath(system_sdk.path("linux/include/wayland"));
|
|
}
|
|
},
|
|
else => unreachable,
|
|
}
|
|
|
|
// Add source files
|
|
|
|
mod.addCSourceFiles(.{
|
|
.files = &.{
|
|
"vendor/src/context.c",
|
|
"vendor/src/egl_context.c",
|
|
"vendor/src/init.c",
|
|
"vendor/src/input.c",
|
|
"vendor/src/monitor.c",
|
|
"vendor/src/null_init.c",
|
|
"vendor/src/null_joystick.c",
|
|
"vendor/src/null_monitor.c",
|
|
"vendor/src/null_window.c",
|
|
"vendor/src/osmesa_context.c",
|
|
"vendor/src/platform.c",
|
|
"vendor/src/vulkan.c",
|
|
"vendor/src/window.c",
|
|
},
|
|
.flags = CFLAGS,
|
|
});
|
|
|
|
switch (target.result.os.tag) {
|
|
.windows => {
|
|
mod.addCMacro("UNICODE", "");
|
|
mod.addCMacro("_UNICODE", "");
|
|
mod.addCMacro("_GLFW_WIN32", "");
|
|
mod.addCSourceFiles(.{
|
|
.files = &.{
|
|
"vendor/src/wgl_context.c",
|
|
"vendor/src/win32_init.c",
|
|
"vendor/src/win32_joystick.c",
|
|
"vendor/src/win32_module.c",
|
|
"vendor/src/win32_monitor.c",
|
|
"vendor/src/win32_thread.c",
|
|
"vendor/src/win32_time.c",
|
|
"vendor/src/win32_window.c",
|
|
},
|
|
.flags = CFLAGS,
|
|
});
|
|
},
|
|
.linux => {
|
|
mod.addCMacro("_DEFAULT_SOURCE", "");
|
|
mod.addCMacro("_GLFW_X11", "");
|
|
mod.addCMacro("_GLFW_WAYLAND", "");
|
|
mod.addCSourceFiles(.{
|
|
.files = &.{
|
|
"vendor/src/glx_context.c",
|
|
"vendor/src/linux_joystick.c",
|
|
"vendor/src/posix_module.c",
|
|
"vendor/src/posix_poll.c",
|
|
"vendor/src/posix_thread.c",
|
|
"vendor/src/posix_time.c",
|
|
"vendor/src/wl_init.c",
|
|
"vendor/src/wl_monitor.c",
|
|
"vendor/src/wl_window.c",
|
|
"vendor/src/x11_init.c",
|
|
"vendor/src/x11_monitor.c",
|
|
"vendor/src/x11_window.c",
|
|
"vendor/src/xkb_unicode.c",
|
|
},
|
|
.flags = CFLAGS,
|
|
});
|
|
},
|
|
else => unreachable,
|
|
}
|
|
|
|
// Link system libraries
|
|
|
|
switch (target.result.os.tag) {
|
|
.windows => {
|
|
mod.linkSystemLibrary("gdi32", .{});
|
|
},
|
|
.linux => {
|
|
if (b.lazyDependency("system_sdk", .{})) |system_sdk| {
|
|
if (target.result.cpu.arch.isX86()) {
|
|
mod.addLibraryPath(system_sdk.path("linux/lib/x86_64-linux-gnu"));
|
|
} else if (target.result.cpu.arch.isAarch64()) {
|
|
mod.addLibraryPath(system_sdk.path("linux/lib/aarch64-linux-gnu"));
|
|
}
|
|
}
|
|
mod.linkSystemLibrary("X11", .{});
|
|
},
|
|
else => unreachable,
|
|
}
|
|
|
|
const mod_tests = b.addTest(.{
|
|
.root_module = mod,
|
|
});
|
|
|
|
const run_mod_tests = b.addRunArtifact(mod_tests);
|
|
|
|
const test_step = b.step("test", "Run tests");
|
|
test_step.dependOn(&run_mod_tests.step);
|
|
}
|