Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/raysan5/raylib
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Mar 7, 2024
2 parents 68b553c + c7b362d commit 1904873
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
run: |
sudo apt-get update -qq
sudo apt-get install gcc-multilib
sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev
sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev libwayland-dev libwayland-bin libxkbcommon-dev
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
run: |
sudo apt-get update -qq
sudo apt-get install gcc-multilib
sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev
sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev libwayland-bin
mkdir build
cd build
mkdir ${{ env.RELEASE_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup Environment
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev
sudo apt-get install -y --no-install-recommends libglfw3 libglfw3-dev libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libxext-dev libxfixes-dev libwayland-bin
- name: Build Library
run: |
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ include(CMakeOptions.txt)
# Enforces a few environment and compiler configurations
include(BuildOptions)

if (UNIX AND NOT APPLE)
if (NOT GLFW_BUILD_WAYLAND AND NOT GLFW_BUILD_X11)
MESSAGE(FATAL_ERROR "Cannot disable both Wayland and X11")
endif()
endif()

# Main sources directory (the second parameter sets the output directory name to raylib)
add_subdirectory(src raylib)

Expand Down
7 changes: 4 additions & 3 deletions CMakeOptions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ option(MACOS_FATLIB "Build fat library for both i386 and x86_64 on macOS" OFF)
cmake_dependent_option(USE_AUDIO "Build raylib with audio module" ON CUSTOMIZE_BUILD ON)

enum_option(USE_EXTERNAL_GLFW "OFF;IF_POSSIBLE;ON" "Link raylib against system GLFW instead of embedded one")
if(UNIX AND NOT APPLE)
option(USE_WAYLAND "Use Wayland for window creation" OFF)
endif()

# GLFW build options
option(GLFW_BUILD_WAYLAND "Build the bundled GLFW with Wayland support" ON)
option(GLFW_BUILD_X11 "Build the bundled GLFW with X11 support" ON)

option(INCLUDE_EVERYTHING "Include everything disabled by default (for CI usage" OFF)
set(OFF ${INCLUDE_EVERYTHING} CACHE INTERNAL "Replace any OFF by default with \${OFF} to have it covered by this option")
Expand Down
5 changes: 2 additions & 3 deletions cmake/GlfwImport.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

if(USE_EXTERNAL_GLFW STREQUAL "ON")
find_package(glfw3 3.3.3 REQUIRED)
find_package(glfw3 3.4 REQUIRED)
elseif(USE_EXTERNAL_GLFW STREQUAL "IF_POSSIBLE")
find_package(glfw3 3.3.3 QUIET)
find_package(glfw3 3.4 QUIET)
endif()
if (glfw3_FOUND)
set(LIBS_PRIVATE ${LIBS_PRIVATE} glfw)
Expand All @@ -16,7 +16,6 @@ if(NOT glfw3_FOUND AND NOT USE_EXTERNAL_GLFW STREQUAL "ON" AND "${PLATFORM}" MAT
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_WAYLAND ${USE_WAYLAND} CACHE BOOL "" FORCE)
set(GLFW_LIBRARY_TYPE "OBJECT" CACHE STRING "" FORCE)


Expand Down
53 changes: 32 additions & 21 deletions src/build.zig
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const std = @import("std");
const builtin = @import("builtin");

// This has been tested to work with zig 0.11.0, zig 0.12.0-dev.2075+f5978181e and 0.12.0-dev.2990+31763d28c
// This has been tested with zig version(s):
// 0.11.0
// 0.12.0-dev.2075+f5978181e
// 0.12.0-dev.2990+31763d28c
//
// anytype is used here to preserve compatibility, in 0.12.0dev the std.zig.CrossTarget type
// Anytype is used here to preserve compatibility, in 0.12.0dev the std.zig.CrossTarget type
// was reworked into std.Target.Query and std.Build.ResolvedTarget. Using anytype allows
// us to accept both CrossTarget and ResolvedTarget and act accordingly in getOsTagVersioned.
pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
const gpa = general_purpose_allocator.allocator();
// get the relative source path, because it is needed for addCSourceFilesVersioned
const relative = srcdir[b.build_root.path.?.len..];

if (comptime builtin.zig_version.minor >= 12 and @TypeOf(target) != std.Build.ResolvedTarget) {
@compileError("Expected 'std.Build.ResolvedTarget' for argument 2 'target' in 'addRaylib', found '" ++ @typeName(@TypeOf(target)) ++ "'");
} else if (comptime builtin.zig_version.minor == 11 and @TypeOf(target) != std.zig.CrossTarget) {
Expand Down Expand Up @@ -53,33 +55,33 @@ pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeM
}

addCSourceFilesVersioned(raylib, &.{
try join2(gpa, relative, "rcore.c"),
try join2(gpa, relative, "utils.c"),
try join2(gpa, srcdir, "rcore.c"),
try join2(gpa, srcdir, "utils.c"),
}, raylib_flags_arr.items);

if (options.raudio) {
addCSourceFilesVersioned(raylib, &.{
try join2(gpa, relative, "raudio.c"),
try join2(gpa, srcdir, "raudio.c"),
}, raylib_flags_arr.items);
}
if (options.rmodels) {
addCSourceFilesVersioned(raylib, &.{
try join2(gpa, relative, "rmodels.c"),
try join2(gpa, srcdir, "rmodels.c"),
}, raylib_flags_arr.items);
}
if (options.rshapes) {
addCSourceFilesVersioned(raylib, &.{
try join2(gpa, relative, "rshapes.c"),
try join2(gpa, srcdir, "rshapes.c"),
}, raylib_flags_arr.items);
}
if (options.rtext) {
addCSourceFilesVersioned(raylib, &.{
try join2(gpa, relative, "rtext.c"),
try join2(gpa, srcdir, "rtext.c"),
}, raylib_flags_arr.items);
}
if (options.rtextures) {
addCSourceFilesVersioned(raylib, &.{
try join2(gpa, relative, "rtextures.c"),
try join2(gpa, srcdir, "rtextures.c"),
}, raylib_flags_arr.items);
}

Expand All @@ -96,7 +98,7 @@ pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeM
switch (getOsTagVersioned(target)) {
.windows => {
addCSourceFilesVersioned(raylib, &.{
try join2(gpa, relative, "rglfw.c"),
try join2(gpa, srcdir, "rglfw.c"),
}, raylib_flags_arr.items);
raylib.linkSystemLibrary("winmm");
raylib.linkSystemLibrary("gdi32");
Expand All @@ -107,7 +109,7 @@ pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeM
.linux => {
if (!options.platform_drm) {
addCSourceFilesVersioned(raylib, &.{
try join2(gpa, relative, "rglfw.c"),
try join2(gpa, srcdir, "rglfw.c"),
}, raylib_flags_arr.items);
raylib.linkSystemLibrary("GL");
raylib.linkSystemLibrary("rt");
Expand Down Expand Up @@ -137,7 +139,7 @@ pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeM
},
.freebsd, .openbsd, .netbsd, .dragonfly => {
addCSourceFilesVersioned(raylib, &.{
try join2(gpa, relative, "rglfw.c"),
try join2(gpa, srcdir, "rglfw.c"),
}, raylib_flags_arr.items);
raylib.linkSystemLibrary("GL");
raylib.linkSystemLibrary("rt");
Expand All @@ -156,7 +158,7 @@ pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeM
// On macos rglfw.c include Objective-C files.
try raylib_flags_arr.append("-ObjC");
addCSourceFilesVersioned(raylib, &.{
try join2(gpa, relative, "rglfw.c"),
try join2(gpa, srcdir, "rglfw.c"),
}, raylib_flags_arr.items);
raylib.linkFramework("Foundation");
raylib.linkFramework("CoreServices");
Expand Down Expand Up @@ -251,14 +253,23 @@ fn getOsTagVersioned(target: anytype) std.Target.Os.Tag {
}
}

fn addCSourceFilesVersioned(exe: *std.Build.Step.Compile, files: []const []const u8, flags: []const []const u8) void {
fn addCSourceFilesVersioned(
exe: *std.Build.Step.Compile,
files: []const []const u8,
flags: []const []const u8,
) void {
//- HACK(cabarger): I hate this so much!!!
if (comptime builtin.zig_version.minor >= 12) {
exe.addCSourceFiles(.{
.files = files,
.flags = flags,
});
} else {
for (files) |file| {
exe.addCSourceFile(.{
.file = .{ .path = file },
.flags = flags,
});
}
} else if (comptime builtin.zig_version.minor == 11) {
exe.addCSourceFiles(files, flags);
} else {
@compileError("Expected zig version 11 or 12");
}
}

Expand Down
9 changes: 0 additions & 9 deletions src/platforms/rcore_desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,6 @@
#include "GLFW/glfw3native.h" // Required for: glfwGetCocoaWindow()
#endif

//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
// TODO: HACK: Added flag if not provided by GLFW when using external library
// Latest GLFW release (GLFW 3.3.8) does not implement this flag, it was added for 3.4.0-dev
#if !defined(GLFW_MOUSE_PASSTHROUGH)
#define GLFW_MOUSE_PASSTHROUGH 0x0002000D
#endif

//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
Expand Down

0 comments on commit 1904873

Please sign in to comment.