117 lines
4.5 KiB
Zig
117 lines
4.5 KiB
Zig
const std = @import("std");
|
|
|
|
const cimgui = @import("cimgui_zig");
|
|
const Renderer = cimgui.Renderer;
|
|
const Platform = cimgui.Platform;
|
|
|
|
fn addIncludePathsToTranslateC(translate_c: *std.Build.Step.TranslateC, lib: *std.Build.Step.Compile) void {
|
|
for (lib.root_module.include_dirs.items) |*included| {
|
|
switch (included.*) {
|
|
.path => translate_c.addIncludePath(included.path),
|
|
.config_header_step => translate_c.addConfigHeader(included.config_header_step),
|
|
.path_system => translate_c.addSystemIncludePath(included.path_system),
|
|
.other_step => addIncludePathsToTranslateC(translate_c, included.other_step),
|
|
else => unreachable,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const prebuilt = b.option([]const u8, "prebuilt", "Path to prebuilt deps (for nix, can be used outside if you need to)");
|
|
const glfw_lib = b.option([]const u8, "glfw-lib", "Path to glfw lib dir");
|
|
|
|
const cimgui_dep = b.dependency("cimgui_zig", .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.platforms = &[_]Platform{.GLFW},
|
|
.renderers = &[_]Renderer{.OpenGL3},
|
|
// .docking = true, // Default value: false
|
|
// .no_renderer = true, // Default value: false. Comment `renderers` field if you use this one
|
|
// .no_platform = true, // Default value: false. Comment `platforms` field if you use this one
|
|
});
|
|
|
|
const cimgui_artifact = cimgui_dep.artifact("cimgui");
|
|
|
|
// --- cimgui-only step (used by Nix to build the prebuilt derivation) ---
|
|
const cimgui_only_step = b.step("cimgui-only", "Build only the cimgui library");
|
|
const install_cimgui = b.addInstallLibFile(
|
|
cimgui_artifact.getEmittedBin(),
|
|
"libcimgui.a",
|
|
);
|
|
const install_headers = b.addInstallDirectory(.{
|
|
.source_dir = cimgui_artifact.getEmittedIncludeTree(),
|
|
.install_dir = .{ .custom = "include" },
|
|
.install_subdir = "",
|
|
.include_extensions = &.{".h"},
|
|
});
|
|
cimgui_only_step.dependOn(&install_cimgui.step);
|
|
cimgui_only_step.dependOn(&install_headers.step);
|
|
|
|
// --- translate-c-only step (used by Nix to cache the translate-c output) ---
|
|
const translate_c = b.addTranslateC(.{
|
|
.root_source_file = b.path("src/c.h"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
translate_c.linkSystemLibrary("gl", .{ .needed = true, .preferred_link_mode = .static });
|
|
addIncludePathsToTranslateC(translate_c, cimgui_artifact);
|
|
|
|
const translate_c_only_step = b.step("translate-c-only", "Only run translate-c, used by Nix");
|
|
const install_translated = b.addInstallFile(translate_c.getOutput(), "c.zig");
|
|
translate_c_only_step.dependOn(&install_translated.step);
|
|
|
|
// --- c_module and exe ---
|
|
const c_module = if (prebuilt) |p| blk: {
|
|
const mod = b.createModule(.{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.root_source_file = .{ .cwd_relative = b.pathJoin(&.{ p, "c.zig" }) },
|
|
});
|
|
mod.linkSystemLibrary("GL", .{});
|
|
mod.linkSystemLibrary("cimgui", .{});
|
|
break :blk mod;
|
|
} else blk: {
|
|
const mod = translate_c.createModule();
|
|
mod.linkLibrary(cimgui_artifact);
|
|
break :blk mod;
|
|
};
|
|
|
|
const exe = b.addExecutable(.{
|
|
.name = "emu_ui",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("src/main.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.imports = &.{
|
|
.{ .name = "imgui", .module = c_module },
|
|
},
|
|
.link_libc = true,
|
|
}),
|
|
});
|
|
|
|
if (prebuilt) |p| {
|
|
exe.root_module.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ p, "lib" }) });
|
|
exe.root_module.linkSystemLibrary("cimgui", .{});
|
|
exe.root_module.linkSystemLibrary("stdc++", .{});
|
|
if (glfw_lib) |g| {
|
|
exe.root_module.addLibraryPath(.{ .cwd_relative = g });
|
|
}
|
|
exe.root_module.linkSystemLibrary("glfw", .{});
|
|
}
|
|
|
|
b.installArtifact(exe);
|
|
|
|
const steamParser = b.addExecutable(.{
|
|
.name = "steamParser",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("src/steamParser.zig"),
|
|
.optimize = optimize,
|
|
.target = target,
|
|
}),
|
|
});
|
|
const steamParserStep = b.step("steamParser", "build the steam parser");
|
|
steamParserStep.dependOn(&b.addInstallArtifact(steamParser, .{}).step);
|
|
}
|