From 6940c54fc1ed75531d7fffc2639feaaa607f04a8 Mon Sep 17 00:00:00 2001 From: Gyusun Yeom Date: Sun, 22 Aug 2021 21:24:41 +0900 Subject: [PATCH 1/2] Support off-screen mode --- CMakeLists.txt | 55 ++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b8f367..87e8072 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ include("GeneratePkgConfig.cmake") option(glew-cmake_BUILD_SHARED "Build the shared glew library" ON) option(glew-cmake_BUILD_STATIC "Build the static glew library" ON) option(USE_GLU "Use GLU" OFF) +option(GLEW_OSMESA "Off-screen Mesa mode" OFF) option(PKG_CONFIG_REPRESENTATIVE_TARGET "Generate pc file for specified target as glew. libglew_static|libglew_shared" OFF) option(ONLY_LIBS "Do not build executables" OFF) @@ -81,39 +82,41 @@ else() endif() list(APPEND pc_requires gl) -if(POLICY CMP0072) - # GLVND - if(USE_NAMESPACED_LIB) - list(APPEND LIBRARIES OpenGL::GL) - if(NOT (WIN32 OR APPLE)) - list(APPEND LIBRARIES OpenGL::GLX) - endif() - else() - list(APPEND LIBRARIES ${OPENGL_opengl_LIBRARY}) - if(NOT (WIN32 OR APPLE)) - list(APPEND LIBRARIES ${OPENGL_glx_LIBRARY}) - endif() - endif() +if(USE_NAMESPACED_LIB) + list(APPEND LIBRARIES OpenGL::GL) else() - # Non GLVND - if(USE_NAMESPACED_LIB) - list(APPEND LIBRARIES OpenGL::OpenGL) - else() - list(APPEND LIBRARIES ${OPENGL_gl_LIBRARY}) - endif() + list(APPEND LIBRARIES ${OPENGL_opengl_LIBRARY}) endif() +# OS Specific dependencies if(APPLE) - find_library(AGL_LIBRARY AGL) + find_library(AGL_LIBRARY AGL REQUIRED) list(APPEND LIBRARIES ${AGL_LIBRARY}) elseif(NOT WIN32) - find_package(X11 REQUIRED) - - list(APPEND pc_requires x11 xext) - if(USE_NAMESPACED_LIB) - list(APPEND LIBRARIES X11::X11 X11::Xext) + if(GLEW_OSMESA) + find_library(OSMESA_LIBRARY OSMesa REQUIRED) + list(APPEND LIBRARIES ${OSMESA_LIBRARY}) + list(APPEND DEFINITIONS -DGLEW_OSMESA) + list(APPEND pc_requires osmesa) else() - list(APPEND LIBRARIES ${X11_X11_LIB} ${X11_Xext_LIB}) + if(NOT OpenGL_GLX_FOUND) + message(FATAL_ERROR "GLX is not found. Try with PREFER_GLVND=NO") + endif() + + if(USE_NAMESPACED_LIB) + list(APPEND LIBRARIES OpenGL::GLX) + else() + list(APPEND LIBRARIES ${OPENGL_glx_LIBRARY}) + endif() + + find_package(X11 REQUIRED) + + list(APPEND pc_requires x11 xext) + if(USE_NAMESPACED_LIB) + list(APPEND LIBRARIES X11::X11 X11::Xext) + else() + list(APPEND LIBRARIES ${X11_X11_LIB} ${X11_Xext_LIB}) + endif() endif() endif() From 442d56d47d8d80f73f8d861dd0448bc032f8e3a5 Mon Sep 17 00:00:00 2001 From: Gyusun Yeom Date: Sun, 14 Nov 2021 15:48:44 +0900 Subject: [PATCH 2/2] Fix build for non-glvnd --- CMakeLists.txt | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87e8072..0d9d6fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,12 +53,24 @@ else() set(USE_NAMESPACED_LIB NO) endif() +if(POLICY CMP0028) + cmake_policy(SET CMP0028 NEW) +endif() + if(POLICY CMP0042) cmake_policy(SET CMP0042 NEW) endif() if(POLICY CMP0072) set(OpenGL_GL_PREFERENCE GLVND) + if(NOT (WIN32 OR APPLE)) + set(USE_GLVND YES) + else() + # GLVND is not supported + set(USE_GLVND NO) + endif() +else() + set(USE_GLVND NO) endif() find_package(OpenGL REQUIRED) @@ -83,9 +95,17 @@ endif() list(APPEND pc_requires gl) if(USE_NAMESPACED_LIB) - list(APPEND LIBRARIES OpenGL::GL) + if(USE_GLVND) + list(APPEND LIBRARIES OpenGL::OpenGL) + else() + list(APPEND LIBRARIES OpenGL::GL) + endif() else() - list(APPEND LIBRARIES ${OPENGL_opengl_LIBRARY}) + if(USE_GLVND) + list(APPEND LIBRARIES ${OPENGL_opengl_LIBRARY}) + else() + list(APPEND LIBRARIES ${OPENGL_gl_LIBRARY}) + endif() endif() # OS Specific dependencies @@ -99,14 +119,16 @@ elseif(NOT WIN32) list(APPEND DEFINITIONS -DGLEW_OSMESA) list(APPEND pc_requires osmesa) else() - if(NOT OpenGL_GLX_FOUND) - message(FATAL_ERROR "GLX is not found. Try with PREFER_GLVND=NO") - endif() + if(USE_GLVND) + if(NOT OpenGL_GLX_FOUND) + message(FATAL_ERROR "GLX is not found. Try with PREFER_GLVND=NO") + endif() - if(USE_NAMESPACED_LIB) - list(APPEND LIBRARIES OpenGL::GLX) - else() - list(APPEND LIBRARIES ${OPENGL_glx_LIBRARY}) + if(USE_NAMESPACED_LIB) + list(APPEND LIBRARIES OpenGL::GLX) + else() + list(APPEND LIBRARIES ${OPENGL_glx_LIBRARY}) + endif() endif() find_package(X11 REQUIRED)