|
| 1 | +const std = @import("std"); |
| 2 | + |
| 3 | +pub fn build(b: *std.Build) void { |
| 4 | + const zwindows = b.dependency("zwindows", .{ |
| 5 | + .zxaudio2_debug_layer = b.option( |
| 6 | + bool, |
| 7 | + "zxaudio2_debug_layer", |
| 8 | + "Enable XAudio2 debug layer", |
| 9 | + ) orelse false, |
| 10 | + .zd3d12_debug_layer = b.option( |
| 11 | + bool, |
| 12 | + "zd3d12_debug_layer", |
| 13 | + "Enable DirectX 12 debug layer", |
| 14 | + ) orelse false, |
| 15 | + .zd3d12_gbv = b.option( |
| 16 | + bool, |
| 17 | + "zd3d12_gbv", |
| 18 | + "Enable DirectX 12 GPU-Based Validation (GBV)", |
| 19 | + ) orelse false, |
| 20 | + }); |
| 21 | + _ = b.addModule("root", .{ |
| 22 | + .root_source_file = b.path("src/openvr.zig"), |
| 23 | + .imports = &.{ |
| 24 | + .{ .name = "zwindows", .module = zwindows.module("zwindows") }, |
| 25 | + }, |
| 26 | + }); |
| 27 | +} |
| 28 | + |
| 29 | +pub fn addLibraryPathsTo(zopenvr: *std.Build.Dependency, compile_step: *std.Build.Step.Compile) void { |
| 30 | + const target = compile_step.rootModuleTarget(); |
| 31 | + switch (target.os.tag) { |
| 32 | + .windows => { |
| 33 | + if (target.cpu.arch.isX86()) { |
| 34 | + compile_step.addLibraryPath(.{ .dependency = .{ |
| 35 | + .dependency = zopenvr, |
| 36 | + .sub_path = "libs/openvr/lib/win64", |
| 37 | + } }); |
| 38 | + } |
| 39 | + }, |
| 40 | + .linux => { |
| 41 | + if (target.cpu.arch.isX86()) { |
| 42 | + compile_step.addLibraryPath(.{ .dependency = .{ |
| 43 | + .dependency = zopenvr, |
| 44 | + .sub_path = "libs/openvr/lib/linux64", |
| 45 | + } }); |
| 46 | + } |
| 47 | + }, |
| 48 | + else => {}, |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +pub fn addRPathsTo(zopenvr: *std.Build.Dependency, compile_step: *std.Build.Step.Compile) void { |
| 53 | + const target = compile_step.rootModuleTarget(); |
| 54 | + switch (target.os.tag) { |
| 55 | + .windows => { |
| 56 | + if (target.cpu.arch.isX86()) { |
| 57 | + compile_step.addRPath(.{ .dependency = .{ |
| 58 | + .dependency = zopenvr, |
| 59 | + .sub_path = "libs/openvr/bin/win64", |
| 60 | + } }); |
| 61 | + } |
| 62 | + }, |
| 63 | + .linux => { |
| 64 | + if (target.cpu.arch.isX86()) { |
| 65 | + compile_step.addRPath(.{ .dependency = .{ |
| 66 | + .dependency = zopenvr, |
| 67 | + .sub_path = "libs/openvr/bin/linux64", |
| 68 | + } }); |
| 69 | + } |
| 70 | + }, |
| 71 | + else => {}, |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +pub fn linkOpenVR(compile_step: *std.Build.Step.Compile) void { |
| 76 | + switch (compile_step.rootModuleTarget().os.tag) { |
| 77 | + .windows, .linux => { |
| 78 | + compile_step.linkSystemLibrary("openvr_api"); |
| 79 | + }, |
| 80 | + else => {}, |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +pub fn installOpenVR( |
| 85 | + zopenvr: *std.Build.Dependency, |
| 86 | + step: *std.Build.Step, |
| 87 | + target: std.Target, |
| 88 | + install_dir: std.Build.InstallDir, |
| 89 | +) void { |
| 90 | + const b = step.owner; |
| 91 | + switch (target.os.tag) { |
| 92 | + .windows => { |
| 93 | + if (target.cpu.arch.isX86()) { |
| 94 | + step.dependOn( |
| 95 | + &b.addInstallFileWithDir( |
| 96 | + .{ .dependency = .{ |
| 97 | + .dependency = zopenvr, |
| 98 | + .sub_path = "libs/openvr/bin/win64/openvr_api.dll", |
| 99 | + } }, |
| 100 | + install_dir, |
| 101 | + "openvr_api.dll", |
| 102 | + ).step, |
| 103 | + ); |
| 104 | + } |
| 105 | + }, |
| 106 | + .linux => { |
| 107 | + if (target.cpu.arch.isX86()) { |
| 108 | + step.dependOn( |
| 109 | + &b.addInstallFileWithDir( |
| 110 | + .{ .dependency = .{ |
| 111 | + .dependency = zopenvr, |
| 112 | + .sub_path = "libs/openvr/bin/linux64/libopenvr_api.so", |
| 113 | + } }, |
| 114 | + install_dir, |
| 115 | + "libopenvr_api.so.0", |
| 116 | + ).step, |
| 117 | + ); |
| 118 | + } |
| 119 | + }, |
| 120 | + else => {}, |
| 121 | + } |
| 122 | +} |
0 commit comments