You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.8 KiB

  1. const std = @import("std");
  2. const builtin = @import("builtin");
  3. fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zig.CrossTarget) !*std.build.Step {
  4. // Standard release options allow the person running `zig build` to select
  5. // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
  6. const mode = b.standardReleaseOptions();
  7. const all = b.step(module, "All " ++ module ++ " examples");
  8. const dir = try std.fs.cwd().openIterableDir(module, .{});
  9. var iter = dir.iterate();
  10. while (try iter.next()) |entry| {
  11. if (entry.kind != .File) continue;
  12. const extension_idx = std.mem.lastIndexOf(u8, entry.name, ".c") orelse continue;
  13. const name = entry.name[0..extension_idx];
  14. const path = try std.fs.path.join(b.allocator, &.{ module, entry.name });
  15. // zig's mingw headers do not include pthread.h
  16. if (std.mem.eql(u8, "core_loading_thread", name) and target.getOsTag() == .windows) continue;
  17. const exe = b.addExecutable(name, null);
  18. exe.addCSourceFile(path, switch (target.getOsTag()) {
  19. .windows => &[_][]const u8{},
  20. .linux => &[_][]const u8{},
  21. .macos => &[_][]const u8{"-DPLATFORM_DESKTOP"},
  22. else => @panic("Unsupported OS"),
  23. });
  24. exe.setTarget(target);
  25. exe.setBuildMode(mode);
  26. exe.linkLibC();
  27. exe.addObjectFile(switch (target.getOsTag()) {
  28. .windows => "../src/raylib.lib",
  29. .linux => "../src/libraylib.a",
  30. .macos => "../src/libraylib.a",
  31. else => @panic("Unsupported OS"),
  32. });
  33. exe.addIncludeDir("../src");
  34. exe.addIncludeDir("../src/external");
  35. exe.addIncludeDir("../src/external/glfw/include");
  36. switch (exe.target.toTarget().os.tag) {
  37. .windows => {
  38. exe.linkSystemLibrary("winmm");
  39. exe.linkSystemLibrary("gdi32");
  40. exe.linkSystemLibrary("opengl32");
  41. exe.addIncludeDir("external/glfw/deps/mingw");
  42. },
  43. .linux => {
  44. exe.linkSystemLibrary("GL");
  45. exe.linkSystemLibrary("rt");
  46. exe.linkSystemLibrary("dl");
  47. exe.linkSystemLibrary("m");
  48. exe.linkSystemLibrary("X11");
  49. },
  50. .macos => {
  51. exe.linkFramework("Foundation");
  52. exe.linkFramework("Cocoa");
  53. exe.linkFramework("OpenGL");
  54. exe.linkFramework("CoreAudio");
  55. exe.linkFramework("CoreVideo");
  56. exe.linkFramework("IOKit");
  57. },
  58. else => {
  59. @panic("Unsupported OS");
  60. },
  61. }
  62. exe.setOutputDir(module);
  63. var run = exe.run();
  64. run.step.dependOn(&b.addInstallArtifact(exe).step);
  65. run.cwd = module;
  66. b.step(name, name).dependOn(&run.step);
  67. all.dependOn(&exe.step);
  68. }
  69. return all;
  70. }
  71. pub fn build(b: *std.build.Builder) !void {
  72. // Standard target options allows the person running `zig build` to choose
  73. // what target to build for. Here we do not override the defaults, which
  74. // means any target is allowed, and the default is native. Other options
  75. // for restricting supported target set are available.
  76. const target = b.standardTargetOptions(.{});
  77. const all = b.getInstallStep();
  78. all.dependOn(try add_module("audio", b, target));
  79. all.dependOn(try add_module("core", b, target));
  80. all.dependOn(try add_module("models", b, target));
  81. all.dependOn(try add_module("others", b, target));
  82. all.dependOn(try add_module("shaders", b, target));
  83. all.dependOn(try add_module("shapes", b, target));
  84. all.dependOn(try add_module("text", b, target));
  85. all.dependOn(try add_module("textures", b, target));
  86. }