mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 03:57:29 +00:00
add argument to Pkg().link to enable linking to system raylib
This commit is contained in:
parent
c6222a0913
commit
6ece4e99f0
@ -58,13 +58,15 @@ pub fn build(b: *Builder) void {
|
||||
};
|
||||
|
||||
const examples_step = b.step("examples", "Builds all the examples");
|
||||
const system_lib = b.option(bool, "system-raylib", "link to preinstalled raylib libraries") orelse false;
|
||||
|
||||
for (examples) |ex| {
|
||||
const exe = b.addExecutable(ex.name, ex.path);
|
||||
|
||||
exe.setBuildMode(mode);
|
||||
exe.setTarget(target);
|
||||
|
||||
raylib.link(exe);
|
||||
raylib.link(exe, system_lib);
|
||||
raylib.addAsPackage("raylib", exe);
|
||||
raylib.math.addAsPackage("raylib-math", exe);
|
||||
|
||||
@ -73,4 +75,4 @@ pub fn build(b: *Builder) void {
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
examples_step.dependOn(&exe.step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
lib.zig
9
lib.zig
@ -4,12 +4,13 @@ const LibExeObjStep = std.build.LibExeObjStep;
|
||||
|
||||
pub fn Pkg(pkgdir: comptime []const u8) type {
|
||||
return struct {
|
||||
pub fn link(exe: *LibExeObjStep) void {
|
||||
pub fn link(exe: *LibExeObjStep, system_lib: bool) void {
|
||||
const raylibFlags = &[_][]const u8{
|
||||
"-std=c99",
|
||||
"-DPLATFORM_DESKTOP",
|
||||
"-D_POSIX_C_SOURCE",
|
||||
};
|
||||
|
||||
if (exe.target.toTarget().os.tag == .windows) {
|
||||
exe.linkSystemLibrary("winmm");
|
||||
exe.linkSystemLibrary("gdi32");
|
||||
@ -19,6 +20,11 @@ pub fn Pkg(pkgdir: comptime []const u8) type {
|
||||
}
|
||||
exe.linkLibC();
|
||||
|
||||
if (system_lib) {
|
||||
exe.linkSystemLibrary("raylib");
|
||||
return;
|
||||
}
|
||||
|
||||
exe.addSystemIncludeDir(pkgdir ++ "/raylib/src");
|
||||
exe.addSystemIncludeDir(pkgdir ++ "/raylib/src/external/glfw/include");
|
||||
exe.addCSourceFile(pkgdir ++ "/raylib/src/core.c", raylibFlags);
|
||||
@ -30,6 +36,7 @@ pub fn Pkg(pkgdir: comptime []const u8) type {
|
||||
exe.addCSourceFile(pkgdir ++ "/raylib/src/textures.c", raylibFlags);
|
||||
exe.addCSourceFile(pkgdir ++ "/raylib/src/utils.c", raylibFlags);
|
||||
}
|
||||
|
||||
pub fn addAsPackage(name: comptime []const u8, to: *LibExeObjStep) void {
|
||||
to.addPackagePath(name, pkgdir ++ "/lib/raylib-zig.zig");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user