Fix build for non-glvnd

This commit is contained in:
Gyusun Yeom 2021-11-14 15:48:44 +09:00
parent 6940c54fc1
commit 442d56d47d

View File

@ -53,12 +53,24 @@ else()
set(USE_NAMESPACED_LIB NO) set(USE_NAMESPACED_LIB NO)
endif() endif()
if(POLICY CMP0028)
cmake_policy(SET CMP0028 NEW)
endif()
if(POLICY CMP0042) if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW) cmake_policy(SET CMP0042 NEW)
endif() endif()
if(POLICY CMP0072) if(POLICY CMP0072)
set(OpenGL_GL_PREFERENCE GLVND) 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() endif()
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
@ -83,9 +95,17 @@ endif()
list(APPEND pc_requires gl) list(APPEND pc_requires gl)
if(USE_NAMESPACED_LIB) 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() 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() endif()
# OS Specific dependencies # OS Specific dependencies
@ -99,14 +119,16 @@ elseif(NOT WIN32)
list(APPEND DEFINITIONS -DGLEW_OSMESA) list(APPEND DEFINITIONS -DGLEW_OSMESA)
list(APPEND pc_requires osmesa) list(APPEND pc_requires osmesa)
else() else()
if(NOT OpenGL_GLX_FOUND) if(USE_GLVND)
message(FATAL_ERROR "GLX is not found. Try with PREFER_GLVND=NO") if(NOT OpenGL_GLX_FOUND)
endif() message(FATAL_ERROR "GLX is not found. Try with PREFER_GLVND=NO")
endif()
if(USE_NAMESPACED_LIB) if(USE_NAMESPACED_LIB)
list(APPEND LIBRARIES OpenGL::GLX) list(APPEND LIBRARIES OpenGL::GLX)
else() else()
list(APPEND LIBRARIES ${OPENGL_glx_LIBRARY}) list(APPEND LIBRARIES ${OPENGL_glx_LIBRARY})
endif()
endif() endif()
find_package(X11 REQUIRED) find_package(X11 REQUIRED)