Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

105 linhas
4.1 KiB

  1. const std = @import("std");
  2. const builtin = @import("builtin");
  3. fn add_module(comptime module: []const u8, b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) !*std.Build.Step {
  4. if (target.getOsTag() == .emscripten) {
  5. @panic("Emscripten building via Zig unsupported");
  6. }
  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(.{
  18. .name = name,
  19. .target = target,
  20. .optimize = optimize,
  21. });
  22. exe.addCSourceFile(path, &[_][]const u8{});
  23. exe.linkLibC();
  24. exe.addObjectFile(switch (target.getOsTag()) {
  25. .windows => "../src/raylib.lib",
  26. .linux => "../src/libraylib.a",
  27. .macos => "../src/libraylib.a",
  28. .emscripten => "../src/libraylib.a",
  29. else => @panic("Unsupported OS"),
  30. });
  31. exe.addIncludePath("../src");
  32. exe.addIncludePath("../src/external");
  33. exe.addIncludePath("../src/external/glfw/include");
  34. switch (target.getOsTag()) {
  35. .windows => {
  36. exe.linkSystemLibrary("winmm");
  37. exe.linkSystemLibrary("gdi32");
  38. exe.linkSystemLibrary("opengl32");
  39. exe.addIncludePath("external/glfw/deps/mingw");
  40. exe.defineCMacro("PLATFORM_DESKTOP", null);
  41. },
  42. .linux => {
  43. exe.linkSystemLibrary("GL");
  44. exe.linkSystemLibrary("rt");
  45. exe.linkSystemLibrary("dl");
  46. exe.linkSystemLibrary("m");
  47. exe.linkSystemLibrary("X11");
  48. exe.defineCMacro("PLATFORM_DESKTOP", null);
  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. exe.defineCMacro("PLATFORM_DESKTOP", null);
  58. },
  59. else => {
  60. @panic("Unsupported OS");
  61. },
  62. }
  63. exe.setOutputDir(module);
  64. var run = exe.run();
  65. run.step.dependOn(&b.addInstallArtifact(exe).step);
  66. run.cwd = module;
  67. b.step(name, name).dependOn(&run.step);
  68. all.dependOn(&exe.step);
  69. }
  70. return all;
  71. }
  72. pub fn build(b: *std.Build) !void {
  73. // Standard target options allows the person running `zig build` to choose
  74. // what target to build for. Here we do not override the defaults, which
  75. // means any target is allowed, and the default is native. Other options
  76. // for restricting supported target set are available.
  77. const target = b.standardTargetOptions(.{});
  78. // Standard optimization options allow the person running `zig build` to select
  79. // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
  80. // set a preferred release mode, allowing the user to decide how to optimize.
  81. const optimize = b.standardOptimizeOption(.{});
  82. const all = b.getInstallStep();
  83. all.dependOn(try add_module("audio", b, target, optimize));
  84. all.dependOn(try add_module("core", b, target, optimize));
  85. all.dependOn(try add_module("models", b, target, optimize));
  86. all.dependOn(try add_module("others", b, target, optimize));
  87. all.dependOn(try add_module("shaders", b, target, optimize));
  88. all.dependOn(try add_module("shapes", b, target, optimize));
  89. all.dependOn(try add_module("text", b, target, optimize));
  90. all.dependOn(try add_module("textures", b, target, optimize));
  91. }