diff options
| author | Dante Catalfamo <[email protected]> | 2023-06-18 05:48:50 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-06-18 11:48:50 +0200 |
| commit | 3a90acf08ee97ba42bc21decfc52b41c7ef4d68d (patch) | |
| tree | c70b6a1c0b92064a3f7db441cdbdf53643cfc216 /src/build.zig | |
| parent | 830e328df09bd597d9a0dbb974f5e7b54c6219f1 (diff) | |
| download | raylib-3a90acf08ee97ba42bc21decfc52b41c7ef4d68d.tar.gz raylib-3a90acf08ee97ba42bc21decfc52b41c7ef4d68d.zip | |
Add options to zig compile (#3115)
* Add options to zig compile options
Support for compiling with raygui, raymath, and physac.
Also outputs the required headers.
Raygui should be located `../raygui` relative to the repo root
Physac should be located `../physac` relative to the repo root
This behavior matches options in the Makefile
* Move Options struct
* Remove physac, explicit raymath, always copy rlgl.h and raymath.h
* Remove unused options from build.zig
* Add srcdir as include path for raygui.h
Diffstat (limited to 'src/build.zig')
| -rw-r--r-- | src/build.zig | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/build.zig b/src/build.zig index 59d8241e..8485322d 100644 --- a/src/build.zig +++ b/src/build.zig @@ -1,7 +1,7 @@ const std = @import("std"); // This has been tested to work with zig master branch as of commit 87de821 or May 14 2023 -pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) *std.Build.CompileStep { +pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, options: Options) *std.Build.CompileStep { const raylib_flags = &[_][]const u8{ "-std=gnu99", "-D_GNU_SOURCE", @@ -28,6 +28,16 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built srcdir ++ "/utils.c", }, raylib_flags); + var gen_step = std.build.Step.WriteFile.create(b); + raylib.step.dependOn(&gen_step.step); + + if (options.raygui) { + _ = gen_step.add(srcdir ++ "/raygui.c", "#define RAYGUI_IMPLEMENTATION\n#include \"raygui.h\"\n"); + raylib.addCSourceFile(srcdir ++ "/raygui.c", raylib_flags); + raylib.addIncludePath(srcdir); + raylib.addIncludePath(srcdir ++ "/../../raygui/src"); + } + switch (target.getOsTag()) { .windows => { raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags); @@ -105,6 +115,10 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built return raylib; } +const Options = struct { + raygui: bool = false, +}; + pub fn build(b: *std.Build) 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 @@ -116,8 +130,20 @@ pub fn build(b: *std.Build) void { // set a preferred release mode, allowing the user to decide how to optimize. const optimize = b.standardOptimizeOption(.{}); - const lib = addRaylib(b, target, optimize); + const raygui = b.option(bool, "raygui", "Compile with raygui support"); + + const lib = addRaylib(b, target, optimize, .{ + .raygui = raygui orelse false, + }); + lib.installHeader("src/raylib.h", "raylib.h"); + lib.installHeader("src/raymath.h", "raymath.h"); + lib.installHeader("src/rlgl.h", "rlgl.h"); + + if (raygui orelse false) { + lib.installHeader("../raygui/src/raygui.h", "raygui.h"); + } + b.installArtifact(lib); } |
