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