diff options
author | Brad King <brad.king@kitware.com> | 2017-11-15 19:18:03 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-11-17 12:17:28 (GMT) |
commit | 2ea17412a9a40bd66342a1761ac8f067f5d2ab09 (patch) | |
tree | f5f8bb250ff5c251761dae6922f9725f316b68ea /Modules/FindOpenGL.cmake | |
parent | 2392f6ea3e3fc4d541594ea7e86be2bb607ba876 (diff) | |
download | CMake-2ea17412a9a40bd66342a1761ac8f067f5d2ab09.zip CMake-2ea17412a9a40bd66342a1761ac8f067f5d2ab09.tar.gz CMake-2ea17412a9a40bd66342a1761ac8f067f5d2ab09.tar.bz2 |
FindOpenGL: Add policy CMP0072 to prefer GLVND for legacy GL
Fixes: #17449
Diffstat (limited to 'Modules/FindOpenGL.cmake')
-rw-r--r-- | Modules/FindOpenGL.cmake | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/Modules/FindOpenGL.cmake b/Modules/FindOpenGL.cmake index 9063492..91db5af 100644 --- a/Modules/FindOpenGL.cmake +++ b/Modules/FindOpenGL.cmake @@ -99,11 +99,13 @@ # If the GLVND OpenGL and GLX libraries are available, prefer them. # This forces ``OPENGL_gl_LIBRARY`` to be empty. # This is the default if components were requested (since components -# correspond to GLVND libraries). +# correspond to GLVND libraries) or if policy :policy:`CMP0072` is +# set to ``NEW``. # # ``LEGACY`` # Prefer to use the legacy libGL library, if available. -# This is the default if no components were requested. +# This is the default if no components were requested and +# policy :policy:`CMP0072` is not set to ``NEW``. # # For EGL targets the client must rely on GLVND support on the user's system. # Linking should use the ``OpenGL::OpenGL OpenGL::EGL`` targets. Using GLES* @@ -220,6 +222,7 @@ else() /usr/shlib /usr/X11R6/lib ) + set(_OpenGL_GL_POLICY_WARN 0) if(NOT DEFINED OpenGL_GL_PREFERENCE) set(OpenGL_GL_PREFERENCE "") endif() @@ -237,8 +240,17 @@ else() set(OpenGL_GL_PREFERENCE "GLVND") else() # No preference was explicitly specified and no GLVND components were - # requested. Prefer libGL for legacy GL. - set(OpenGL_GL_PREFERENCE "LEGACY") + # requested. Use a policy to choose the default. + cmake_policy(GET CMP0072 _OpenGL_GL_POLICY) + if("x${_OpenGL_GL_POLICY}x" STREQUAL "xNEWx") + set(OpenGL_GL_PREFERENCE "GLVND") + else() + set(OpenGL_GL_PREFERENCE "LEGACY") + if("x${_OpenGL_GL_POLICY}x" STREQUAL "xx") + set(_OpenGL_GL_POLICY_WARN 1) + endif() + endif() + unset(_OpenGL_GL_POLICY) endif() if("x${OpenGL_GL_PREFERENCE}x" STREQUAL "xGLVNDx" AND OPENGL_opengl_LIBRARY AND OPENGL_glx_LIBRARY) @@ -257,6 +269,23 @@ else() ) endif() + if(_OpenGL_GL_POLICY_WARN AND OPENGL_gl_LIBRARY AND OPENGL_opengl_LIBRARY AND OPENGL_glx_LIBRARY) + message(AUTHOR_WARNING + "Policy CMP0072 is not set: FindOpenGL prefers GLVND by default when available. " + "Run \"cmake --help-policy CMP0072\" for policy details. " + "Use the cmake_policy command to set the policy and suppress this warning." + "\n" + "FindOpenGL found both a legacy GL library:\n" + " OPENGL_gl_LIBRARY: ${OPENGL_gl_LIBRARY}\n" + "and GLVND libraries for OpenGL and GLX:\n" + " OPENGL_opengl_LIBRARY: ${OPENGL_opengl_LIBRARY}\n" + " OPENGL_glx_LIBRARY: ${OPENGL_glx_LIBRARY}\n" + "OpenGL_GL_PREFERENCE has not been set to \"GLVND\" or \"LEGACY\", so for " + "compatibility with CMake 3.10 and below the legacy GL library will be used." + ) + endif() + unset(_OpenGL_GL_POLICY_WARN) + # FPHSA cannot handle "this OR that is required", so we conditionally set what # it must look for. First clear any previous config we might have done: set(_OpenGL_REQUIRED_VARS) |