From eb8a343e313967a51cb302ac9bb1206a05727d13 Mon Sep 17 00:00:00 2001 From: Bruno Cabral Date: Tue, 25 Feb 2025 22:48:59 -0800 Subject: [PATCH 1/2] [cmake] Use STATIC lib ON by default (#4799) * search raylib in custom directory * avoid loading dynamic library when both are installed * raylib_USE_STATIC_LIBS as option ON --- cmake/raylib-config.cmake | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cmake/raylib-config.cmake b/cmake/raylib-config.cmake index 700965c95..b2ef6bfd6 100644 --- a/cmake/raylib-config.cmake +++ b/cmake/raylib-config.cmake @@ -1,6 +1,6 @@ # - Try to find raylib # Options: -# raylib_USE_STATIC_LIBS - OFF by default +# raylib_USE_STATIC_LIBS - ON by default # raylib_VERBOSE - OFF by default # Once done, this defines a raylib target that can be passed to # target_link_libraries as well as following variables: @@ -11,6 +11,9 @@ # raylib_LDFLAGS - The linker flags needed with raylib # raylib_DEFINITIONS - Compiler switches required for using raylib +option(raylib_USE_STATIC_LIBS "Use static libs" ON) +option(raylib_VERBOSE "Use static libs" OFF) + if (NOT TARGET raylib) set(XPREFIX PC_RAYLIB) @@ -25,23 +28,22 @@ if (NOT TARGET raylib) find_path(raylib_INCLUDE_DIR NAMES raylib.h - HINTS ${${XPREFIX}_INCLUDE_DIRS} + HINTS ${${XPREFIX}_INCLUDE_DIRS} ${raylib_DIR}/../../../include/ ) - set(RAYLIB_NAMES raylib) if (raylib_USE_STATIC_LIBS) - set(RAYLIB_NAMES libraylib.a raylib.lib ${RAYLIB_NAMES}) - endif() + set(RAYLIB_NAMES libraylib.a raylib.lib) + else () + set(RAYLIB_NAMES raylib) + endif () find_library(raylib_LIBRARY NAMES ${RAYLIB_NAMES} - HINTS ${${XPREFIX}_LIBRARY_DIRS} + HINTS ${${XPREFIX}_LIBRARY_DIRS} ${raylib_DIR}/../../ ) set(raylib_LIBRARIES ${raylib_LIBRARY}) - set(raylib_LIBRARY_DIRS ${${XPREFIX}_LIBRARY_DIRS}) - set(raylib_LIBRARY_DIR ${raylib_LIBRARY_DIRS}) set(raylib_INCLUDE_DIRS ${raylib_INCLUDE_DIR}) set(raylib_LDFLAGS ${${XPREFIX}_LDFLAGS}) From a20d9dedf3755c5c221b1fa332ffcc3730c35cef Mon Sep 17 00:00:00 2001 From: sleeptightAnsiC <91839286+sleeptightAnsiC@users.noreply.github.com> Date: Sat, 1 Mar 2025 23:42:07 +0100 Subject: [PATCH 2/2] [desktop_glfw] fix InitPlatform crash caused by glfwCreateWindow... (#4804) ...returning NULL. This was causing a crash few lines later. Refs: https://github.com/raysan5/raylib/issues/4801#issuecomment-2691201072 Partially-fixes: https://github.com/raysan5/raylib/issues/4801 --- src/platforms/rcore_desktop_glfw.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 90b725ddb..f79276549 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1521,6 +1521,12 @@ int InitPlatform(void) SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height); platform.handle = glfwCreateWindow(CORE.Window.display.width, CORE.Window.display.height, (CORE.Window.title != 0)? CORE.Window.title : " ", monitor, NULL); + if (!platform.handle) + { + glfwTerminate(); + TRACELOG(LOG_WARNING, "GLFW: Failed to initialize Window"); + return -1; + } // NOTE: Full-screen change, not working properly... //glfwSetWindowMonitor(platform.handle, glfwGetPrimaryMonitor(), 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE); @@ -1535,6 +1541,12 @@ int InitPlatform(void) int creationHeight = CORE.Window.screen.height != 0 ? CORE.Window.screen.height : 1; platform.handle = glfwCreateWindow(creationWidth, creationHeight, (CORE.Window.title != 0)? CORE.Window.title : " ", NULL, NULL); + if (!platform.handle) + { + glfwTerminate(); + TRACELOG(LOG_WARNING, "GLFW: Failed to initialize Window"); + return -1; + } // After the window was created, determine the monitor that the window manager assigned. // Derive display sizes, and, if possible, window size in case it was zero at beginning. @@ -1558,18 +1570,8 @@ int InitPlatform(void) return -1; } - if (platform.handle) - { - CORE.Window.render.width = CORE.Window.screen.width; - CORE.Window.render.height = CORE.Window.screen.height; - } - } - - if (!platform.handle) - { - glfwTerminate(); - TRACELOG(LOG_WARNING, "GLFW: Failed to initialize Window"); - return -1; + CORE.Window.render.width = CORE.Window.screen.width; + CORE.Window.render.height = CORE.Window.screen.height; } glfwMakeContextCurrent(platform.handle);