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 Aug 2, 2024
1 parent 2732f00 commit e2b6f62
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
29 changes: 28 additions & 1 deletion lib/libimhex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,33 @@ 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_INCLUDES ${GLFW_INCLUDE_DIRS})
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 Expand Up @@ -152,4 +179,4 @@ add_dependencies(imhex_all libimhex)

install(FILES "$<TARGET_FILE:libimhex>" DESTINATION "${CMAKE_INSTALL_LIBDIR}" PERMISSIONS ${LIBRARY_PERMISSIONS})
set_target_properties(libimhex PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set_target_properties(libimhex PROPERTIES PREFIX "")
set_target_properties(libimhex PROPERTIES PREFIX "")
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 e2b6f62

Please sign in to comment.