mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 12:07:27 +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 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| {
|
for (examples) |ex| {
|
||||||
const exe = b.addExecutable(ex.name, ex.path);
|
const exe = b.addExecutable(ex.name, ex.path);
|
||||||
|
|
||||||
exe.setBuildMode(mode);
|
exe.setBuildMode(mode);
|
||||||
exe.setTarget(target);
|
exe.setTarget(target);
|
||||||
|
|
||||||
raylib.link(exe);
|
raylib.link(exe, system_lib);
|
||||||
raylib.addAsPackage("raylib", exe);
|
raylib.addAsPackage("raylib", exe);
|
||||||
raylib.math.addAsPackage("raylib-math", exe);
|
raylib.math.addAsPackage("raylib-math", exe);
|
||||||
|
|
||||||
@ -73,4 +75,4 @@ pub fn build(b: *Builder) void {
|
|||||||
run_step.dependOn(&run_cmd.step);
|
run_step.dependOn(&run_cmd.step);
|
||||||
examples_step.dependOn(&exe.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 {
|
pub fn Pkg(pkgdir: comptime []const u8) type {
|
||||||
return struct {
|
return struct {
|
||||||
pub fn link(exe: *LibExeObjStep) void {
|
pub fn link(exe: *LibExeObjStep, system_lib: bool) void {
|
||||||
const raylibFlags = &[_][]const u8{
|
const raylibFlags = &[_][]const u8{
|
||||||
"-std=c99",
|
"-std=c99",
|
||||||
"-DPLATFORM_DESKTOP",
|
"-DPLATFORM_DESKTOP",
|
||||||
"-D_POSIX_C_SOURCE",
|
"-D_POSIX_C_SOURCE",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (exe.target.toTarget().os.tag == .windows) {
|
if (exe.target.toTarget().os.tag == .windows) {
|
||||||
exe.linkSystemLibrary("winmm");
|
exe.linkSystemLibrary("winmm");
|
||||||
exe.linkSystemLibrary("gdi32");
|
exe.linkSystemLibrary("gdi32");
|
||||||
@ -19,6 +20,11 @@ pub fn Pkg(pkgdir: comptime []const u8) type {
|
|||||||
}
|
}
|
||||||
exe.linkLibC();
|
exe.linkLibC();
|
||||||
|
|
||||||
|
if (system_lib) {
|
||||||
|
exe.linkSystemLibrary("raylib");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
exe.addSystemIncludeDir(pkgdir ++ "/raylib/src");
|
exe.addSystemIncludeDir(pkgdir ++ "/raylib/src");
|
||||||
exe.addSystemIncludeDir(pkgdir ++ "/raylib/src/external/glfw/include");
|
exe.addSystemIncludeDir(pkgdir ++ "/raylib/src/external/glfw/include");
|
||||||
exe.addCSourceFile(pkgdir ++ "/raylib/src/core.c", raylibFlags);
|
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/textures.c", raylibFlags);
|
||||||
exe.addCSourceFile(pkgdir ++ "/raylib/src/utils.c", raylibFlags);
|
exe.addCSourceFile(pkgdir ++ "/raylib/src/utils.c", raylibFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addAsPackage(name: comptime []const u8, to: *LibExeObjStep) void {
|
pub fn addAsPackage(name: comptime []const u8, to: *LibExeObjStep) void {
|
||||||
to.addPackagePath(name, pkgdir ++ "/lib/raylib-zig.zig");
|
to.addPackagePath(name, pkgdir ++ "/lib/raylib-zig.zig");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user