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); var targets = std.ArrayList(*std.Build.Step.Compile){}; const mod = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true, }); mod.addIncludePath(b.path("./src/")); { 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 = &.{} }); } } } 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(".")); { const imgui_mod = b.createModule(.{ .target = target, .optimize = optimize, .link_libcpp = true, }); const imgui = b.dependency("imgui", .{}); imgui_mod.addCSourceFiles(.{ .root = imgui.path("."), .files = &.{ "imgui.cpp", "imgui_demo.cpp", "imgui_draw.cpp", "imgui_tables.cpp", "imgui_widgets.cpp", }, .flags = &.{ "-fno-sanitize=undefined", "-std=c++11", "-Wno-deprecated-declarations", "-DNO_FONT_AWESOME", }, }); imgui_mod.addIncludePath(imgui.path(".")); const imgui_lib = b.addLibrary(.{ .name = "imgui", .root_module = imgui_mod }); imgui_lib.installHeadersDirectory(imgui.path("."), "imgui", .{}); imgui_lib.installHeadersDirectory(imgui.path("."), ".", .{}); mod.linkLibrary(imgui_lib); } const cimgui = b.dependency("cimgui", .{}); mod.addCSourceFile(.{ .file = cimgui.path("cimgui.cpp"), .flags = &.{ "-fno-exceptions", "-fno-rtti", "-std=c++11" }, }); mod.addIncludePath(cimgui.path(".")); const rlimgui = b.dependency("rlimgui", .{ .target = target, .optimize = optimize, }); mod.addCSourceFile(.{ .file = rlimgui.path("rlImGui.cpp"), .flags = &.{}, }); mod.addIncludePath(rlimgui.path(".")); 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)); }