Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build.zig: Support for building with PLAFORM_DRM #3191

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions src/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built
});
raylib.linkLibC();

raylib.addIncludePath(srcdir ++ "/external/glfw/include");
// No GLFW required on PLATFORM_DRM
if (!options.platform_drm) {
raylib.addIncludePath(srcdir ++ "/external/glfw/include");
}

raylib.addCSourceFiles(&.{
srcdir ++ "/raudio.c",
Expand Down Expand Up @@ -49,15 +52,32 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built
raylib.defineCMacro("PLATFORM_DESKTOP", null);
},
.linux => {
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
raylib.linkSystemLibrary("GL");
raylib.linkSystemLibrary("rt");
raylib.linkSystemLibrary("dl");
raylib.linkSystemLibrary("m");
raylib.linkSystemLibrary("X11");
raylib.addIncludePath("/usr/include");

raylib.defineCMacro("PLATFORM_DESKTOP", null);
if (!options.platform_drm) {
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
raylib.linkSystemLibrary("GL");
raylib.linkSystemLibrary("rt");
raylib.linkSystemLibrary("dl");
raylib.linkSystemLibrary("m");
raylib.linkSystemLibrary("X11");
raylib.addIncludePath("/usr/include");

raylib.defineCMacro("PLATFORM_DESKTOP", null);
} else {
raylib.linkSystemLibrary("GLESv2");
raylib.linkSystemLibrary("EGL");
raylib.linkSystemLibrary("drm");
raylib.linkSystemLibrary("gbm");
raylib.linkSystemLibrary("pthread");
raylib.linkSystemLibrary("rt");
raylib.linkSystemLibrary("m");
raylib.linkSystemLibrary("dl");
raylib.addIncludePath("/usr/include/libdrm");

raylib.defineCMacro("PLATFORM_DRM", null);
raylib.defineCMacro("GRAPHICS_API_OPENGL_ES2", null);
raylib.defineCMacro("EGL_NO_X11", null);
raylib.defineCMacro("DEFAULT_BATCH_BUFFER_ELEMENT", "2048");
}
},
.freebsd, .openbsd, .netbsd, .dragonfly => {
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
Expand Down Expand Up @@ -115,8 +135,9 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built
return raylib;
}

const Options = struct {
pub const Options = struct {
raygui: bool = false,
platform_drm: bool = false,
};

pub fn build(b: *std.Build) void {
Expand All @@ -131,9 +152,11 @@ pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});

const raygui = b.option(bool, "raygui", "Compile with raygui support");
const platform_drm = b.option(bool, "platform_drm", "Compile raylib in native mode (no X11)");

const lib = addRaylib(b, target, optimize, .{
.raygui = raygui orelse false,
.platform_drm = platform_drm orelse false,
});

lib.installHeader("src/raylib.h", "raylib.h");
Expand Down