165 lines
4.8 KiB
Zig
165 lines
4.8 KiB
Zig
const std = @import("std");
|
|
const zcc = @import("compile_commands");
|
|
|
|
pub fn build(b: *std.Build) !void {
|
|
const target = b.standardTargetOptions(.{ });
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const tracy_enabled = b.option(bool, "tracy", "Enable tracy profiling") orelse (optimize == .Debug);
|
|
const imgui_enabled = b.option(bool, "imgui", "Enable ImGui integration") orelse (optimize == .Debug);
|
|
|
|
var targets: std.ArrayList(*std.Build.Step.Compile) = .empty;
|
|
|
|
const mod = b.createModule(.{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
});
|
|
mod.addIncludePath(b.path("./src/"));
|
|
|
|
var cflags: std.ArrayList([]const u8) = .empty;
|
|
|
|
const raylib_dep = b.dependency("raylib", .{
|
|
.target = target,
|
|
.optimize = optimize
|
|
});
|
|
mod.linkLibrary(raylib_dep.artifact("raylib"));
|
|
|
|
const tracy_dep = b.dependency("tracy", .{
|
|
.tracy_enable = tracy_enabled,
|
|
});
|
|
mod.linkLibrary(tracy_dep.artifact("tracy"));
|
|
|
|
const incbin_dep = b.dependency("incbin", .{});
|
|
mod.addIncludePath(incbin_dep.path("."));
|
|
|
|
if (imgui_enabled) {
|
|
if (try buildImGui(b, .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.raylib = raylib_dep.artifact("raylib")
|
|
})) |imgui| {
|
|
mod.linkLibrary(imgui);
|
|
try targets.append(b.allocator, imgui);
|
|
}
|
|
|
|
try cflags.append(b.allocator, "-DIMGUI_ENABLED");
|
|
}
|
|
|
|
{
|
|
var src_dir = try std.fs.cwd().openDir("src", .{ .iterate = true });
|
|
defer src_dir.close();
|
|
|
|
var iter = src_dir.iterate();
|
|
while (try iter.next()) |entry| {
|
|
if (entry.kind == .file and std.mem.endsWith(u8, entry.name, ".c")) {
|
|
mod.addCSourceFile(.{
|
|
.file = b.path(b.pathJoin(&.{ "src", entry.name })),
|
|
.flags = cflags.items
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
const exe = b.addExecutable(.{
|
|
.name = "gaem",
|
|
.root_module = mod
|
|
});
|
|
try targets.append(b.allocator, exe);
|
|
|
|
if (target.result.os.tag == .windows) {
|
|
const show_console = b.option(bool, "console", "Show windows console") orelse (optimize == .Debug);
|
|
exe.subsystem = if (show_console) .Console else .Windows;
|
|
}
|
|
|
|
b.installArtifact(exe);
|
|
|
|
{
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
|
|
if (b.args) |args| {
|
|
run_cmd.addArgs(args);
|
|
}
|
|
|
|
const run_step = b.step("run", "Run the program");
|
|
run_step.dependOn(&run_cmd.step);
|
|
}
|
|
|
|
_ = zcc.createStep(b, "cdb", try targets.toOwnedSlice(b.allocator));
|
|
}
|
|
|
|
const ImGuiOptions = struct {
|
|
target: std.Build.ResolvedTarget,
|
|
optimize: std.builtin.OptimizeMode,
|
|
raylib: *std.Build.Step.Compile
|
|
};
|
|
|
|
fn buildImGui(b: *std.Build, opts: ImGuiOptions) !?*std.Build.Step.Compile {
|
|
const imgui = b.lazyDependency("imgui", .{}) orelse return null;
|
|
const cimgui = b.lazyDependency("cimgui", .{}) orelse return null;
|
|
const rlimgui = b.lazyDependency("rlimgui", .{}) orelse return null;
|
|
|
|
const cpp_flags = .{
|
|
"-fno-exceptions",
|
|
"-fno-rtti",
|
|
"-std=c++11",
|
|
"-DNO_FONT_AWESOME"
|
|
};
|
|
|
|
const imgui_lib = b.addLibrary(.{
|
|
.name = "imgui",
|
|
.root_module = b.createModule(.{
|
|
.target = opts.target,
|
|
.optimize = opts.optimize,
|
|
.link_libcpp = true,
|
|
})
|
|
});
|
|
|
|
imgui_lib.root_module.addCSourceFiles(.{
|
|
.root = imgui.path("."),
|
|
.files = &.{
|
|
"imgui.cpp",
|
|
"imgui_demo.cpp",
|
|
"imgui_draw.cpp",
|
|
"imgui_tables.cpp",
|
|
"imgui_widgets.cpp",
|
|
},
|
|
.flags = &cpp_flags
|
|
});
|
|
imgui_lib.root_module.addIncludePath(imgui.path("."));
|
|
|
|
// Needed for cimgui
|
|
imgui_lib.installHeadersDirectory(imgui.path("."), "imgui", .{});
|
|
// Needed for rlimgui
|
|
imgui_lib.installHeadersDirectory(imgui.path("."), ".", .{});
|
|
|
|
const lib = b.addLibrary(.{
|
|
.name = "imgui_raylib_cimgui",
|
|
.root_module = b.createModule(.{
|
|
.target = opts.target,
|
|
.optimize = opts.optimize,
|
|
.link_libcpp = true,
|
|
})
|
|
});
|
|
lib.root_module.linkLibrary(imgui_lib);
|
|
|
|
lib.root_module.addCSourceFile(.{
|
|
.file = cimgui.path("cimgui.cpp"),
|
|
.flags = &cpp_flags
|
|
});
|
|
lib.root_module.addIncludePath(cimgui.path("."));
|
|
|
|
lib.root_module.addCSourceFile(.{
|
|
.file = rlimgui.path("rlImGui.cpp"),
|
|
.flags = &cpp_flags,
|
|
});
|
|
lib.root_module.addIncludePath(rlimgui.path("."));
|
|
lib.root_module.linkLibrary(opts.raylib);
|
|
|
|
lib.installHeader(rlimgui.path("rlImGui.h"), "rlImGui.h");
|
|
lib.installHeader(cimgui.path("cimgui.h"), "cimgui.h");
|
|
|
|
return lib;
|
|
}
|