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.

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