glfw: attempt to build, wrap all fns
This commit is contained in:
@@ -1,32 +1,130 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const CFLAGS: []const []const u8 = &.{
|
||||
"-std=c99",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
};
|
||||
|
||||
const vm_dep = b.dependency("vecmath", .{
|
||||
.target = target,
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{
|
||||
.whitelist = &.{
|
||||
std.Target.Query.parse(.{ .arch_os_abi = "x86_64-windows" }) catch unreachable,
|
||||
std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux" }) catch unreachable,
|
||||
},
|
||||
});
|
||||
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 },
|
||||
},
|
||||
});
|
||||
|
||||
mod.addCSourceFiles(.{
|
||||
.files = &.{},
|
||||
.flags = &.{
|
||||
"-std=c99",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
// 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"));
|
||||
}
|
||||
},
|
||||
.language = .c,
|
||||
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("_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("_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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user