Skip to content

Commit

Permalink
fix: Properly fix GLFW Linux backend detection
Browse files Browse the repository at this point in the history
  • Loading branch information
btzy committed Jul 30, 2024
1 parent 2732f00 commit 0038e69
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
26 changes: 26 additions & 0 deletions lib/libimhex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@ else()
target_compile_definitions(libimhex PRIVATE IMHEX_PROJECT_NAME="${PROJECT_NAME}")
endif()

if (UNIX AND NOT APPLE)
# For Linux, we need to figure out whether our GLFW is built for X11, Wayland, or both
INCLUDE(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_LIBRARIES ${GLFW_LIBRARIES})
check_cxx_source_compiles("
#define GLFW_EXPOSE_NATIVE_X11
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
Window test(GLFWwindow* w) { return glfwGetX11Window(w); }
int main() {}
" GLFW_HAS_X11)
check_cxx_source_compiles("
#define GLFW_EXPOSE_NATIVE_WAYLAND
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
wl_surface* test(GLFWwindow* w) { return glfwGetWaylandWindow(w); }
int main() {}
" GLFW_HAS_WAYLAND)
if (GLFW_HAS_X11)
target_compile_definitions(libimhex PRIVATE GLFW_BACKEND_X11)
endif()
if (GLFW_HAS_WAYLAND)
target_compile_definitions(libimhex PRIVATE GLFW_BACKEND_WAYLAND)
endif()
endif()


if (DEFINED IMHEX_COMMIT_HASH_LONG AND DEFINED IMHEX_COMMIT_BRANCH)
set(GIT_COMMIT_HASH_LONG "${IMHEX_COMMIT_HASH_LONG}")
Expand Down
8 changes: 4 additions & 4 deletions lib/libimhex/source/helpers/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
typedef void NSWindow;
#define GLFW_EXPOSE_NATIVE_COCOA
#endif
#if defined(OS_LINUX)
#if defined(OS_LINUX) && defined(GLFW_BACKEND_X11)
#define GLFW_EXPOSE_NATIVE_X11
#endif
#if defined(OS_LINUX) && defined(GLFW_WAYLAND_APP_ID)
#if defined(OS_LINUX) && defined(GLFW_BACKEND_WAYLAND)
#define GLFW_EXPOSE_NATIVE_WAYLAND
#endif
#include <nfd_glfw3.h>
#if defined(OS_LINUX) && defined(GLFW_WAYLAND_APP_ID)
#if defined(OS_LINUX) && defined(GLFW_BACKEND_WAYLAND)
#undef GLFW_EXPOSE_NATIVE_WAYLAND
#endif
#if defined(OS_LINUX)
#if defined(OS_LINUX) && defined(GLFW_BACKEND_X11)
#undef GLFW_EXPOSE_NATIVE_X11
#endif
#if defined(OS_MACOS)
Expand Down

0 comments on commit 0038e69

Please sign in to comment.