const std = @import("std"); pub fn link(dep: *std.Build.Dependency, compile: *std.Build.Step.Compile) void { compile.step.dependOn(dep.builder.getInstallStep()); compile.linkLibC(); compile.root_module.addLibraryPath(.{ .cwd_relative = dep.builder.getInstallPath(.lib, "") }); compile.root_module.addIncludePath(.{ .cwd_relative = dep.builder.getInstallPath(.header, "") }); compile.root_module.addRPathSpecial("$ORIGIN/../lib"); compile.root_module.linkSystemLibrary("glfw", .{}); compile.root_module.linkSystemLibrary("rt", .{}); compile.root_module.linkSystemLibrary("m", .{}); compile.root_module.linkSystemLibrary("dl", .{}); } pub fn install(dep: *std.Build.Dependency, owner: *std.Build) void { const install_libs = owner.addInstallDirectory(.{ .include_extensions = &.{ ".so", ".dll" }, .install_subdir = "", .install_dir = .lib, .source_dir = .{ .cwd_relative = dep.builder.getInstallPath(.lib, ""), }, }); install_libs.step.dependOn(dep.builder.getInstallStep()); owner.getInstallStep().dependOn(&install_libs.step); } pub fn build(b: *std.Build) void { // todo target into toolchain file // const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const cmake = b.findProgram(&.{"cmake"}, &.{}) catch @panic("missing cmake"); const cmake_build_type = switch (optimize) { .ReleaseFast => "Release", .ReleaseSafe => "RelWithDebInfo", .ReleaseSmall => "MinSizeRel", .Debug => "Debug", }; const config_step = b.addSystemCommand(&.{ cmake, "-DBUILD_SHARED_LIBS=ON", b.fmt("-DCMAKE_BUILD_TYPE={s}", .{cmake_build_type}), b.fmt("-DCMAKE_INSTALL_PREFIX={s}", .{b.getInstallPath(.prefix, "")}), "-DGLFW_BUILD_DOCS=OFF", "-DGLFW_BUILD_EXAMPLES=OFF", "-DGLFW_BUILD_TESTS=OFF", "-DGLFW_BUILD_X11=ON", // todo arg "-DGLFW_BUILD_WAYLAND=OFF", // todo arg "-DGLFW_INSTALL=ON", }); // config_step.setEnvironmentVariable("CC", b.fmt("{s} cc", .{b.graph.zig_exe})); // config_step.setEnvironmentVariable("CXX", b.fmt("{s} c++", .{b.graph.zig_exe})); config_step.addArg("-S"); config_step.addDirectoryArg(b.dependency("glfw_real", .{}).path("")); config_step.addArg("-B"); const build_dir = config_step.addOutputDirectoryArg("glfw_build"); _ = config_step.captureStdOut(); config_step.has_side_effects = true; const build_step = b.addSystemCommand(&.{cmake}); build_step.step.dependOn(&config_step.step); build_step.addArg("--build"); build_step.addDirectoryArg(build_dir); _ = build_step.captureStdOut(); build_step.has_side_effects = true; const install_step = b.addSystemCommand(&.{cmake}); install_step.step.dependOn(&build_step.step); install_step.addArg("--install"); install_step.addDirectoryArg(build_dir); _ = install_step.captureStdOut(); install_step.has_side_effects = true; b.getInstallStep().dependOn(&install_step.step); }