From 929d9a4ca5c9eb0a590479182471d0bbc81589aa Mon Sep 17 00:00:00 2001 From: Yaroslav Isakov Date: Sat, 8 Jul 2023 22:09:40 +0200 Subject: [PATCH] Allow OpenGL to be found on X11-less Linux systems (using libOpenGL) Cmake supports finding OpenGL, even if there is no GLX (for glvnd) or old-style libGL. This change keeps old behavior, but in case, if X11-related OpenGL libraries cannot be found on Linux, it adds logic to check for (and link with) libOpenGL, if it is present. [ChangeLog][QtGui] Allow OpenGL to be found on X11-less Linux systems (using libOpenGL) Change-Id: Iccfeba83292a14081544c64ea8ce24fb52d1ee2f Reviewed-by: Alexandru Croitor --- cmake/FindWrapOpenGL.cmake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmake/FindWrapOpenGL.cmake b/cmake/FindWrapOpenGL.cmake index c4e0fe5d3e..3e6abaf4dd 100644 --- a/cmake/FindWrapOpenGL.cmake +++ b/cmake/FindWrapOpenGL.cmake @@ -46,6 +46,16 @@ if (OpenGL_FOUND) else() target_link_libraries(WrapOpenGL::WrapOpenGL INTERFACE OpenGL::GL) endif() +elseif(UNIX AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "Integrity") + # Requesting only the OpenGL component ensures CMake does not mark the package as + # not found if neither GLX nor libGL are available. This allows finding OpenGL + # on an X11-less Linux system. + find_package(OpenGL ${WrapOpenGL_FIND_VERSION} COMPONENTS OpenGL) + if (OpenGL_FOUND) + set(WrapOpenGL_FOUND ON) + add_library(WrapOpenGL::WrapOpenGL INTERFACE IMPORTED) + target_link_libraries(WrapOpenGL::WrapOpenGL INTERFACE OpenGL::OpenGL) + endif() endif() include(FindPackageHandleStandardArgs)