From d0004865e5a7a24498c83a01dc8c8eca27136de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Jun 2018 12:30:23 +0200 Subject: [PATCH] modules: properly handle GLVND also in case of context libraries. --- modules/FindMagnum.cmake | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 63c647d2e..f111b2422 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -722,11 +722,22 @@ foreach(_component ${Magnum_FIND_COMPONENTS}) # GLX context dependencies if(_component STREQUAL GlxContext) - find_package(X11) - set_property(TARGET Magnum::${_component} APPEND PROPERTY - INTERFACE_INCLUDE_DIRECTORIES ${X11_INCLUDE_DIR}) - set_property(TARGET Magnum::${_component} APPEND PROPERTY - INTERFACE_LINK_LIBRARIES ${X11_LIBRARIES}) + # With GLVND (since CMake 3.11) we need to explicitly link to + # GLX because libOpenGL doesn't provide it. Also can't use + # OpenGL_OpenGL_FOUND, because that one is set also if GLVND is + # *not* found. If GLVND is not used, link to X11 instead. + set(OpenGL_GL_PREFERENCE GLVND) + find_package(OpenGL) + if(OPENGL_opengl_LIBRARY) + set_property(TARGET Magnum::${_component} APPEND PROPERTY + INTERFACE_LINK_LIBRARIES OpenGL::GLX) + else() + find_package(X11) + set_property(TARGET Magnum::${_component} APPEND PROPERTY + INTERFACE_INCLUDE_DIRECTORIES ${X11_INCLUDE_DIR}) + set_property(TARGET Magnum::${_component} APPEND PROPERTY + INTERFACE_LINK_LIBRARIES ${X11_LIBRARIES}) + endif() # EGL context dependencies elseif(_component STREQUAL EglContext)