Fix "CMake: Fallback to libOpenGL (no-X11 OpenGL)" (#1251)
Build and Test / build-linux (push) Has been cancelled
Build and Test / build-wayland (push) Has been cancelled
Build and Test / build-macos (push) Has been cancelled
Build and Test / build-windows (push) Has been cancelled

This commit is contained in:
ManoloFLTK
2025-11-02 15:05:38 +01:00
parent a128b7c95a
commit f2db90cb77
3 changed files with 43 additions and 14 deletions
+35 -14
View File
@@ -642,25 +642,42 @@ if(FLTK_BUILD_GL)
if(FLTK_USE_WAYLAND)
pkg_check_modules(WLD_EGL IMPORTED_TARGET wayland-egl)
pkg_check_modules(PKG_EGL IMPORTED_TARGET egl)
pkg_check_modules(PKG_GL IMPORTED_TARGET gl)
if(FLTK_BACKEND_X11)
pkg_check_modules(PKG_GL IMPORTED_TARGET gl)
else()
pkg_check_modules(PKG_GL IMPORTED_TARGET opengl)
endif()
pkg_check_modules(PKG_GLU IMPORTED_TARGET glu)
if(NOT (WLD_EGL_FOUND AND PKG_EGL_FOUND AND PKG_GL_FOUND AND PKG_GLU_FOUND))
message(STATUS "Modules 'wayland-egl, egl, gl, and glu' are required to build for the Wayland backend.")
message(STATUS "Modules 'wayland-egl, egl, gl (or opengl), and glu' are required to build for the Wayland backend.")
message(FATAL_ERROR "*** Aborting ***")
endif()
endif(FLTK_USE_WAYLAND)
if(FLTK_BACKEND_X11)
if(FLTK_BACKEND_X11 OR FLTK_USE_WAYLAND)
set(OPENGL_FOUND TRUE)
find_library(OPENGL_LIB GL)
if(FLTK_BACKEND_X11)
find_library(OPENGL_LIB GL)
else()
find_library(OPENGL_LIB OpenGL)
endif(FLTK_BACKEND_X11)
get_filename_component(PATH_TO_GLLIB ${OPENGL_LIB} DIRECTORY)
find_library(GLU_LIB GLU)
get_filename_component(PATH_TO_GLULIB ${GLU_LIB} DIRECTORY)
# FIXME: we should find a better way to resolve this issue:
# with GL, must use XQuartz libX11 else "Insufficient GL support"
set(OPENGL_LIBRARIES -L${PATH_TO_GLULIB} -L${PATH_TO_GLLIB} -lX11 -lGLU -lGL)
set(OPENGL_LIBRARIES -L${PATH_TO_GLULIB} -L${PATH_TO_GLLIB})
if(APPLE)
# FIXME: we should find a better way to resolve this issue:
# with GL, must use XQuartz libX11 else "Insufficient GL support"
set(OPENGL_LIBRARIES ${OPENGL_LIBRARIES} -lX11)
endif(APPLE)
set(OPENGL_LIBRARIES ${OPENGL_LIBRARIES} -lGLU)
if(FLTK_BACKEND_X11)
set(OPENGL_LIBRARIES ${OPENGL_LIBRARIES} -lGL)
else()
set(OPENGL_LIBRARIES ${OPENGL_LIBRARIES} -lOpenGL)
endif(FLTK_BACKEND_X11)
find_path(OPENGL_INCLUDE_DIR NAMES GL/gl.h OpenGL/gl.h HINTS ${X11_INCLUDE_DIR})
unset(HAVE_GL_GLU_H CACHE)
find_file(HAVE_GL_GLU_H GL/glu.h PATHS ${X11_INCLUDE_DIR})
@@ -669,7 +686,7 @@ if(FLTK_BUILD_GL)
if(APPLE)
set(HAVE_GL_GLU_H ${HAVE_OPENGL_GLU_H})
endif(APPLE)
endif(FLTK_BACKEND_X11)
endif(FLTK_BACKEND_X11 OR FLTK_USE_WAYLAND)
else(FLTK_BUILD_GL)
set(OPENGL_FOUND FALSE)
set(HAVE_GL FALSE)
@@ -711,12 +728,16 @@ if(OPENGL_FOUND)
list(APPEND GLLIBS -lGLU -lGL)
endif(WIN32)
# check if function glXGetProcAddressARB exists
set(TEMP_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES ${OPENGL_LIBRARIES})
check_symbol_exists(glXGetProcAddressARB "glx.h" HAVE_GLXGETPROCADDRESSARB)
set(CMAKE_REQUIRED_LIBRARIES ${TEMP_REQUIRED_LIBRARIES})
unset(TEMP_REQUIRED_LIBRARIES)
if (FLTK_BACKEND_X11)
# check if function glXGetProcAddressARB exists
set(TEMP_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES ${OPENGL_LIBRARIES})
check_symbol_exists(glXGetProcAddressARB "glx.h" HAVE_GLXGETPROCADDRESSARB)
set(CMAKE_REQUIRED_LIBRARIES ${TEMP_REQUIRED_LIBRARIES})
unset(TEMP_REQUIRED_LIBRARIES)
else()
unset(HAVE_GLXGETPROCADDRESSARB CACHE)
endif(FLTK_BACKEND_X11)
endif(OPENGL_FOUND)
#######################################################################
@@ -51,6 +51,7 @@ private:
void gl_start() FL_OVERRIDE;
void gl_visual(Fl_Gl_Choice *c) FL_OVERRIDE;
void init();
void* GetProcAddress(const char *procName) FL_OVERRIDE;
public:
static void surface_frame_done(void *data, struct wl_callback *cb, uint32_t time);
//virtual bool need_scissor() { return true; } // CONTROL_LEAKING_SUB_GL_WINDOWS
@@ -22,6 +22,7 @@
#include "Fl_Wayland_Window_Driver.H"
#include "Fl_Wayland_Graphics_Driver.H"
#include "Fl_Wayland_Gl_Window_Driver.H"
#include "../Posix/Fl_Posix_System_Driver.H"
#ifdef FLTK_USE_X11
# include "../X11/Fl_X11_Gl_Window_Driver.H"
#endif
@@ -470,6 +471,12 @@ int Fl_Wayland_Gl_Window_Driver::swap_interval() const {
return swap_interval_;
}
void* Fl_Wayland_Gl_Window_Driver::GetProcAddress(const char *procName) {
return Fl_Posix_System_Driver::dlopen_or_dlsym(NULL, procName);
}
FL_EXPORT EGLContext fl_wl_glcontext(GLContext rc) { return (EGLContext)rc; }
#endif // HAVE_GL