github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/tests/raylib/build.zig (about) 1 const std = @import("std"); 2 3 pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.LibExeObjStep { 4 const raylib_flags = &[_][]const u8{ 5 "-std=gnu99", 6 "-DPLATFORM_DESKTOP", 7 "-D_GNU_SOURCE", 8 "-DGL_SILENCE_DEPRECATION=199309L", 9 "-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891 10 }; 11 12 const raylib = b.addStaticLibrary("raylib", null); 13 raylib.setTarget(target); 14 raylib.linkLibC(); 15 16 raylib.addIncludePath(srcdir ++ "/external/glfw/include"); 17 18 raylib.addCSourceFiles(&.{ 19 srcdir ++ "/raudio.c", 20 srcdir ++ "/rcore.c", 21 srcdir ++ "/rmodels.c", 22 srcdir ++ "/rshapes.c", 23 srcdir ++ "/rtext.c", 24 srcdir ++ "/rtextures.c", 25 srcdir ++ "/utils.c", 26 }, raylib_flags); 27 28 switch (raylib.target.toTarget().os.tag) { 29 .windows => { 30 raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags); 31 raylib.linkSystemLibrary("winmm"); 32 raylib.linkSystemLibrary("gdi32"); 33 raylib.linkSystemLibrary("opengl32"); 34 raylib.addIncludePath("external/glfw/deps/mingw"); 35 }, 36 .linux => { 37 raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags); 38 raylib.linkSystemLibrary("GL"); 39 raylib.linkSystemLibrary("rt"); 40 raylib.linkSystemLibrary("dl"); 41 raylib.linkSystemLibrary("m"); 42 raylib.linkSystemLibrary("X11"); 43 }, 44 .freebsd, .openbsd, .netbsd, .dragonfly => { 45 raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags); 46 raylib.linkSystemLibrary("GL"); 47 raylib.linkSystemLibrary("rt"); 48 raylib.linkSystemLibrary("dl"); 49 raylib.linkSystemLibrary("m"); 50 raylib.linkSystemLibrary("X11"); 51 raylib.linkSystemLibrary("Xrandr"); 52 raylib.linkSystemLibrary("Xinerama"); 53 raylib.linkSystemLibrary("Xi"); 54 raylib.linkSystemLibrary("Xxf86vm"); 55 raylib.linkSystemLibrary("Xcursor"); 56 }, 57 .macos => { 58 // On macos rglfw.c include Objective-C files. 59 const raylib_flags_extra_macos = &[_][]const u8{ 60 "-ObjC", 61 }; 62 raylib.addCSourceFiles( 63 &.{srcdir ++ "/rglfw.c"}, 64 raylib_flags ++ raylib_flags_extra_macos, 65 ); 66 raylib.linkFramework("Foundation"); 67 raylib.linkFramework("CoreServices"); 68 raylib.linkFramework("CoreGraphics"); 69 raylib.linkFramework("AppKit"); 70 raylib.linkFramework("IOKit"); 71 }, 72 else => { 73 @panic("Unsupported OS"); 74 }, 75 } 76 77 return raylib; 78 } 79 80 pub fn build(b: *std.build.Builder) void { 81 // Standard target options allows the person running `zig build` to choose 82 // what target to build for. Here we do not override the defaults, which 83 // means any target is allowed, and the default is native. Other options 84 // for restricting supported target set are available. 85 const target = b.standardTargetOptions(.{}); 86 87 const lib = addRaylib(b, target); 88 lib.setOutputDir(srcdir); 89 lib.install(); 90 } 91 92 const srcdir = struct{ 93 fn getSrcDir() []const u8 { 94 return std.fs.path.dirname(@src().file).?; 95 } 96 }.getSrcDir();