2022-09-08 07:19:36 -07:00
|
|
|
const builtin = @import("builtin");
|
2021-07-06 20:53:10 -07:00
|
|
|
const std = @import("std");
|
2023-02-07 19:19:47 +01:00
|
|
|
const Build = std.Build;
|
2021-10-30 21:24:15 -07:00
|
|
|
|
2023-02-07 19:19:47 +01:00
|
|
|
pub fn build(b: *Build) !void {
|
|
|
|
const optimize = b.standardOptimizeOption(.{});
|
2022-07-23 16:52:34 +04:30
|
|
|
const target = b.standardTargetOptions(.{});
|
|
|
|
|
2024-01-12 14:18:38 -07:00
|
|
|
const module = b.addModule("mach-glfw", .{
|
|
|
|
.root_source_file = .{ .path = "src/main.zig" },
|
2023-07-07 20:59:09 -07:00
|
|
|
});
|
2024-01-12 14:18:38 -07:00
|
|
|
module.addIncludePath(b.dependency("glfw", .{}).path("include"));
|
2023-07-06 23:45:18 -07:00
|
|
|
|
2023-09-17 13:44:52 -07:00
|
|
|
const lib = b.addStaticLibrary(.{
|
|
|
|
.name = "mach-glfw",
|
2023-10-16 21:36:18 -07:00
|
|
|
.root_source_file = b.addWriteFiles().add("empty.c", ""),
|
2023-09-17 13:44:52 -07:00
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
|
|
|
link(b, lib);
|
|
|
|
b.installArtifact(lib);
|
|
|
|
|
|
|
|
const test_step = b.step("test", "Run library tests");
|
|
|
|
const main_tests = b.addTest(.{
|
|
|
|
.name = "glfw-tests",
|
|
|
|
.root_source_file = .{ .path = "src/main.zig" },
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
2023-07-07 20:59:09 -07:00
|
|
|
|
2023-09-17 13:44:52 -07:00
|
|
|
main_tests.linkLibrary(lib);
|
|
|
|
link(b, main_tests);
|
|
|
|
b.installArtifact(main_tests);
|
2023-08-08 19:12:40 -07:00
|
|
|
|
2023-09-17 13:44:52 -07:00
|
|
|
test_step.dependOn(&b.addRunArtifact(main_tests).step);
|
2023-07-06 22:30:29 -07:00
|
|
|
}
|
2023-08-04 12:35:30 -07:00
|
|
|
|
2024-01-12 14:18:38 -07:00
|
|
|
pub fn link(b: *std.Build, step: *std.Build.Step.Compile) void {
|
|
|
|
const target_triple: []const u8 = step.rootModuleTarget().zigTriple(b.allocator) catch @panic("OOM");
|
|
|
|
const cpu_opts: []const u8 = step.root_module.resolved_target.?.query.serializeCpuAlloc(b.allocator) catch @panic("OOM");
|
2023-10-16 21:36:18 -07:00
|
|
|
const glfw_dep = b.dependency("glfw", .{
|
2024-01-12 14:18:38 -07:00
|
|
|
.target = target_triple,
|
|
|
|
.cpu = cpu_opts,
|
|
|
|
.optimize = step.root_module.optimize.?,
|
2023-10-16 21:36:18 -07:00
|
|
|
});
|
|
|
|
@import("glfw").link(glfw_dep.builder, step);
|
|
|
|
step.linkLibrary(glfw_dep.artifact("glfw"));
|
2023-08-04 12:35:30 -07:00
|
|
|
}
|