| 1 | 
greg | 
1.1 | 
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying | 
| 2 | 
  | 
  | 
# file Copyright.txt or https://cmake.org/licensing for details. | 
| 3 | 
  | 
  | 
 | 
| 4 | 
  | 
  | 
#[=======================================================================[.rst: | 
| 5 | 
  | 
  | 
FindOpenGL | 
| 6 | 
  | 
  | 
---------- | 
| 7 | 
  | 
  | 
 | 
| 8 | 
  | 
  | 
FindModule for OpenGL and OpenGL Utility Library (GLU). | 
| 9 | 
  | 
  | 
 | 
| 10 | 
  | 
  | 
.. versionchanged:: 3.2 | 
| 11 | 
  | 
  | 
  X11 is no longer added as a dependency on Unix/Linux systems. | 
| 12 | 
  | 
  | 
 | 
| 13 | 
  | 
  | 
.. versionadded:: 3.10 | 
| 14 | 
  | 
  | 
  GLVND support on Linux.  See the :ref:`Linux Specific` section below. | 
| 15 | 
  | 
  | 
 | 
| 16 | 
  | 
  | 
Optional COMPONENTS | 
| 17 | 
  | 
  | 
^^^^^^^^^^^^^^^^^^^ | 
| 18 | 
  | 
  | 
 | 
| 19 | 
  | 
  | 
.. versionadded:: 3.10 | 
| 20 | 
  | 
  | 
 | 
| 21 | 
  | 
  | 
This module respects several optional COMPONENTS: | 
| 22 | 
  | 
  | 
 | 
| 23 | 
  | 
  | 
``EGL`` | 
| 24 | 
  | 
  | 
  The EGL interface between OpenGL, OpenGL ES and the underlying windowing system. | 
| 25 | 
  | 
  | 
 | 
| 26 | 
  | 
  | 
``GLX`` | 
| 27 | 
  | 
  | 
  An extension to X that interfaces OpenGL, OpenGL ES with X window system. | 
| 28 | 
  | 
  | 
 | 
| 29 | 
  | 
  | 
``OpenGL`` | 
| 30 | 
  | 
  | 
  The cross platform API for 3D graphics. | 
| 31 | 
  | 
  | 
 | 
| 32 | 
  | 
  | 
``GLES2`` | 
| 33 | 
  | 
  | 
  .. versionadded:: 3.27 | 
| 34 | 
  | 
  | 
 | 
| 35 | 
  | 
  | 
  A subset of OpenGL API for embedded systems with limited capabilities. | 
| 36 | 
  | 
  | 
 | 
| 37 | 
  | 
  | 
``GLES3`` | 
| 38 | 
  | 
  | 
  .. versionadded:: 3.27 | 
| 39 | 
  | 
  | 
 | 
| 40 | 
  | 
  | 
  A subset of OpenGL API for embedded systems with more capabilities. | 
| 41 | 
  | 
  | 
 | 
| 42 | 
  | 
  | 
IMPORTED Targets | 
| 43 | 
  | 
  | 
^^^^^^^^^^^^^^^^ | 
| 44 | 
  | 
  | 
 | 
| 45 | 
  | 
  | 
.. versionadded:: 3.8 | 
| 46 | 
  | 
  | 
 | 
| 47 | 
  | 
  | 
This module defines the :prop_tgt:`IMPORTED` targets: | 
| 48 | 
  | 
  | 
 | 
| 49 | 
  | 
  | 
``OpenGL::GL`` | 
| 50 | 
  | 
  | 
  Defined to the platform-specific OpenGL libraries if the system has OpenGL. | 
| 51 | 
  | 
  | 
``OpenGL::GLU`` | 
| 52 | 
  | 
  | 
  Defined if the system has OpenGL Utility Library (GLU). | 
| 53 | 
  | 
  | 
 | 
| 54 | 
  | 
  | 
.. versionadded:: 3.10 | 
| 55 | 
  | 
  | 
  Additionally, the following GLVND-specific library targets are defined: | 
| 56 | 
  | 
  | 
 | 
| 57 | 
  | 
  | 
``OpenGL::OpenGL`` | 
| 58 | 
  | 
  | 
  Defined to libOpenGL if the system is GLVND-based. | 
| 59 | 
  | 
  | 
``OpenGL::GLX`` | 
| 60 | 
  | 
  | 
  Defined if the system has OpenGL Extension to the X Window System (GLX). | 
| 61 | 
  | 
  | 
``OpenGL::EGL`` | 
| 62 | 
  | 
  | 
  Defined if the system has EGL. | 
| 63 | 
  | 
  | 
``OpenGL::GLES2`` | 
| 64 | 
  | 
  | 
  .. versionadded:: 3.27 | 
| 65 | 
  | 
  | 
 | 
| 66 | 
  | 
  | 
  Defined if the system has GLES2. | 
| 67 | 
  | 
  | 
``OpenGL::GLES3`` | 
| 68 | 
  | 
  | 
  .. versionadded:: 3.27 | 
| 69 | 
  | 
  | 
 | 
| 70 | 
  | 
  | 
  Defined if the system has GLES3. | 
| 71 | 
  | 
  | 
 | 
| 72 | 
  | 
  | 
Result Variables | 
| 73 | 
  | 
  | 
^^^^^^^^^^^^^^^^ | 
| 74 | 
  | 
  | 
 | 
| 75 | 
  | 
  | 
This module sets the following variables: | 
| 76 | 
  | 
  | 
 | 
| 77 | 
  | 
  | 
``OPENGL_FOUND`` | 
| 78 | 
  | 
  | 
 True, if the system has OpenGL and all components are found. | 
| 79 | 
  | 
  | 
``OPENGL_XMESA_FOUND`` | 
| 80 | 
  | 
  | 
 True, if the system has XMESA. | 
| 81 | 
  | 
  | 
``OPENGL_GLU_FOUND`` | 
| 82 | 
  | 
  | 
 True, if the system has GLU. | 
| 83 | 
  | 
  | 
``OpenGL_OpenGL_FOUND`` | 
| 84 | 
  | 
  | 
 True, if the system has an OpenGL library. | 
| 85 | 
  | 
  | 
``OpenGL_GLX_FOUND`` | 
| 86 | 
  | 
  | 
 True, if the system has GLX. | 
| 87 | 
  | 
  | 
``OpenGL_EGL_FOUND`` | 
| 88 | 
  | 
  | 
 True, if the system has EGL. | 
| 89 | 
  | 
  | 
``OpenGL::GLES2`` | 
| 90 | 
  | 
  | 
 Defined if the system has GLES2. | 
| 91 | 
  | 
  | 
``OpenGL::GLES3`` | 
| 92 | 
  | 
  | 
 Defined if the system has GLES3. | 
| 93 | 
  | 
  | 
``OPENGL_INCLUDE_DIR`` | 
| 94 | 
  | 
  | 
 Path to the OpenGL include directory. | 
| 95 | 
  | 
  | 
``OPENGL_EGL_INCLUDE_DIRS`` | 
| 96 | 
  | 
  | 
 Path to the EGL include directory. | 
| 97 | 
  | 
  | 
``OPENGL_LIBRARIES`` | 
| 98 | 
  | 
  | 
 Paths to the OpenGL library, windowing system libraries, and GLU libraries. | 
| 99 | 
  | 
  | 
 On Linux, this assumes GLX and is never correct for EGL-based targets. | 
| 100 | 
  | 
  | 
 Clients are encouraged to use the ``OpenGL::*`` import targets instead. | 
| 101 | 
  | 
  | 
 | 
| 102 | 
  | 
  | 
.. versionadded:: 3.10 | 
| 103 | 
  | 
  | 
  Variables for GLVND-specific libraries ``OpenGL``, ``EGL`` and ``GLX``. | 
| 104 | 
  | 
  | 
 | 
| 105 | 
  | 
  | 
Cache variables | 
| 106 | 
  | 
  | 
^^^^^^^^^^^^^^^ | 
| 107 | 
  | 
  | 
 | 
| 108 | 
  | 
  | 
The following cache variables may also be set: | 
| 109 | 
  | 
  | 
 | 
| 110 | 
  | 
  | 
``OPENGL_egl_LIBRARY`` | 
| 111 | 
  | 
  | 
 Path to the EGL library. | 
| 112 | 
  | 
  | 
``OPENGL_glu_LIBRARY`` | 
| 113 | 
  | 
  | 
 Path to the GLU library. | 
| 114 | 
  | 
  | 
``OPENGL_glx_LIBRARY`` | 
| 115 | 
  | 
  | 
 Path to the GLVND 'GLX' library. | 
| 116 | 
  | 
  | 
``OPENGL_opengl_LIBRARY`` | 
| 117 | 
  | 
  | 
 Path to the GLVND 'OpenGL' library | 
| 118 | 
  | 
  | 
``OPENGL_gl_LIBRARY`` | 
| 119 | 
  | 
  | 
 Path to the OpenGL library.  New code should prefer the ``OpenGL::*`` import | 
| 120 | 
  | 
  | 
 targets. | 
| 121 | 
  | 
  | 
``OPENGL_gles2_LIBRARY`` | 
| 122 | 
  | 
  | 
  .. versionadded:: 3.27 | 
| 123 | 
  | 
  | 
 | 
| 124 | 
  | 
  | 
  Path to the OpenGL GLES2 library. | 
| 125 | 
  | 
  | 
``OPENGL_gles3_LIBRARY`` | 
| 126 | 
  | 
  | 
  .. versionadded:: 3.27 | 
| 127 | 
  | 
  | 
 | 
| 128 | 
  | 
  | 
  Path to the OpenGL GLES3 library. | 
| 129 | 
  | 
  | 
 | 
| 130 | 
  | 
  | 
.. versionadded:: 3.10 | 
| 131 | 
  | 
  | 
  Variables for GLVND-specific libraries ``OpenGL``, ``EGL`` and ``GLX``. | 
| 132 | 
  | 
  | 
 | 
| 133 | 
  | 
  | 
.. _`Linux Specific`: | 
| 134 | 
  | 
  | 
 | 
| 135 | 
  | 
  | 
Linux-specific | 
| 136 | 
  | 
  | 
^^^^^^^^^^^^^^ | 
| 137 | 
  | 
  | 
 | 
| 138 | 
  | 
  | 
Some Linux systems utilize GLVND as a new ABI for OpenGL.  GLVND separates | 
| 139 | 
  | 
  | 
context libraries from OpenGL itself; OpenGL lives in "libOpenGL", and | 
| 140 | 
  | 
  | 
contexts are defined in "libGLX" or "libEGL".  GLVND is currently the only way | 
| 141 | 
  | 
  | 
to get OpenGL 3+ functionality via EGL in a manner portable across vendors. | 
| 142 | 
  | 
  | 
Projects may use GLVND explicitly with target ``OpenGL::OpenGL`` and either | 
| 143 | 
  | 
  | 
``OpenGL::GLX`` or ``OpenGL::EGL``. | 
| 144 | 
  | 
  | 
 | 
| 145 | 
  | 
  | 
Projects may use the ``OpenGL::GL`` target (or ``OPENGL_LIBRARIES`` variable) | 
| 146 | 
  | 
  | 
to use legacy GL interfaces.  These will use the legacy GL library located | 
| 147 | 
  | 
  | 
by ``OPENGL_gl_LIBRARY``, if available.  If ``OPENGL_gl_LIBRARY`` is empty or | 
| 148 | 
  | 
  | 
not found and GLVND is available, the ``OpenGL::GL`` target will use GLVND | 
| 149 | 
  | 
  | 
``OpenGL::OpenGL`` and ``OpenGL::GLX`` (and the ``OPENGL_LIBRARIES`` | 
| 150 | 
  | 
  | 
variable will use the corresponding libraries).  Thus, for non-EGL-based | 
| 151 | 
  | 
  | 
Linux targets, the ``OpenGL::GL`` target is most portable. | 
| 152 | 
  | 
  | 
 | 
| 153 | 
  | 
  | 
A ``OpenGL_GL_PREFERENCE`` variable may be set to specify the preferred way | 
| 154 | 
  | 
  | 
to provide legacy GL interfaces in case multiple choices are available. | 
| 155 | 
  | 
  | 
The value may be one of: | 
| 156 | 
  | 
  | 
 | 
| 157 | 
  | 
  | 
``GLVND`` | 
| 158 | 
  | 
  | 
 If the GLVND OpenGL and GLX libraries are available, prefer them. | 
| 159 | 
  | 
  | 
 This forces ``OPENGL_gl_LIBRARY`` to be empty. | 
| 160 | 
  | 
  | 
 | 
| 161 | 
  | 
  | 
 .. versionchanged:: 3.11 | 
| 162 | 
  | 
  | 
  This is the default, unless policy :policy:`CMP0072` is set to ``OLD`` | 
| 163 | 
  | 
  | 
  and no components are requested (since components | 
| 164 | 
  | 
  | 
  correspond to GLVND libraries). | 
| 165 | 
  | 
  | 
 | 
| 166 | 
  | 
  | 
``LEGACY`` | 
| 167 | 
  | 
  | 
 Prefer to use the legacy libGL library, if available. | 
| 168 | 
  | 
  | 
 | 
| 169 | 
  | 
  | 
For EGL targets the client must rely on GLVND support on the user's system. | 
| 170 | 
  | 
  | 
Linking should use the ``OpenGL::OpenGL OpenGL::EGL`` targets.  Using GLES* | 
| 171 | 
  | 
  | 
libraries is theoretically possible in place of ``OpenGL::OpenGL``, but this | 
| 172 | 
  | 
  | 
module does not currently support that; contributions welcome. | 
| 173 | 
  | 
  | 
 | 
| 174 | 
  | 
  | 
``OPENGL_egl_LIBRARY`` and ``OPENGL_EGL_INCLUDE_DIRS`` are defined in the case of | 
| 175 | 
  | 
  | 
GLVND.  For non-GLVND Linux and other systems these are left undefined. | 
| 176 | 
  | 
  | 
 | 
| 177 | 
  | 
  | 
macOS-Specific | 
| 178 | 
  | 
  | 
^^^^^^^^^^^^^^ | 
| 179 | 
  | 
  | 
 | 
| 180 | 
  | 
  | 
On macOS FindOpenGL defaults to using the macOS-native framework | 
| 181 | 
  | 
  | 
version of OpenGL.  To use the X11 version of OpenGL on macOS, you | 
| 182 | 
  | 
  | 
need to disable searching of frameworks and point CMake to the X11 | 
| 183 | 
  | 
  | 
libraries.  Using the XQuartz X11 server, do something like this:: | 
| 184 | 
  | 
  | 
 | 
| 185 | 
  | 
  | 
   if(APPLE AND X11_FOUND) | 
| 186 | 
  | 
  | 
     set(CMAKE_FIND_FRAMEWORK NEVER) | 
| 187 | 
  | 
  | 
     set(OpenGL_ROOT "/opt/X11")   # or whatever your X11 server root is | 
| 188 | 
  | 
  | 
     find_package(OpenGL) | 
| 189 | 
  | 
  | 
     set(CMAKE_FIND_FRAMEWORK "") | 
| 190 | 
  | 
  | 
   else() | 
| 191 | 
  | 
  | 
     find_package(OpenGL) | 
| 192 | 
  | 
  | 
   endif() | 
| 193 | 
  | 
  | 
 | 
| 194 | 
  | 
  | 
You must first use find_package(X11) to ensure that X11 is available. | 
| 195 | 
  | 
  | 
 | 
| 196 | 
  | 
  | 
#]=======================================================================] | 
| 197 | 
  | 
  | 
 | 
| 198 | 
  | 
  | 
set(_OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY) | 
| 199 | 
  | 
  | 
 | 
| 200 | 
  | 
  | 
# Provide OPENGL_USE_<C> variables for each component. | 
| 201 | 
  | 
  | 
foreach(component ${OpenGL_FIND_COMPONENTS}) | 
| 202 | 
  | 
  | 
  string(TOUPPER ${component} _COMPONENT) | 
| 203 | 
  | 
  | 
  set(OPENGL_USE_${_COMPONENT} 1) | 
| 204 | 
  | 
  | 
endforeach() | 
| 205 | 
  | 
  | 
 | 
| 206 | 
  | 
  | 
set(_OpenGL_CACHE_VARS) | 
| 207 | 
  | 
  | 
 | 
| 208 | 
  | 
  | 
if (WIN32) | 
| 209 | 
  | 
  | 
 | 
| 210 | 
  | 
  | 
  if(BORLAND) | 
| 211 | 
  | 
  | 
    set (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32") | 
| 212 | 
  | 
  | 
    set (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32") | 
| 213 | 
  | 
  | 
  else() | 
| 214 | 
  | 
  | 
    set (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32") | 
| 215 | 
  | 
  | 
    set (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32") | 
| 216 | 
  | 
  | 
  endif() | 
| 217 | 
  | 
  | 
 | 
| 218 | 
  | 
  | 
  list(APPEND _OpenGL_CACHE_VARS | 
| 219 | 
  | 
  | 
    OPENGL_gl_LIBRARY | 
| 220 | 
  | 
  | 
    OPENGL_glu_LIBRARY | 
| 221 | 
  | 
  | 
    ) | 
| 222 | 
  | 
  | 
elseif (APPLE) | 
| 223 | 
  | 
  | 
  # The OpenGL.framework provides both gl and glu in OpenGL | 
| 224 | 
  | 
  | 
  # XQuartz provides libgl and libglu | 
| 225 | 
  | 
  | 
  find_library(OPENGL_gl_LIBRARY NAMES OpenGL GL DOC | 
| 226 | 
  | 
  | 
    "OpenGL GL library") | 
| 227 | 
  | 
  | 
  find_library(OPENGL_glu_LIBRARY NAMES OpenGL GLU DOC | 
| 228 | 
  | 
  | 
    "OpenGL GLU library") | 
| 229 | 
  | 
  | 
  find_path(OPENGL_INCLUDE_DIR NAMES OpenGL/gl.h GL/gl.h DOC | 
| 230 | 
  | 
  | 
    "Include for OpenGL") | 
| 231 | 
  | 
  | 
  list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR) | 
| 232 | 
  | 
  | 
 | 
| 233 | 
  | 
  | 
  list(APPEND _OpenGL_CACHE_VARS | 
| 234 | 
  | 
  | 
    OPENGL_INCLUDE_DIR | 
| 235 | 
  | 
  | 
    OPENGL_gl_LIBRARY | 
| 236 | 
  | 
  | 
    OPENGL_glu_LIBRARY | 
| 237 | 
  | 
  | 
    ) | 
| 238 | 
  | 
  | 
else() | 
| 239 | 
  | 
  | 
  if (CMAKE_ANDROID_NDK) | 
| 240 | 
  | 
  | 
    set(_OPENGL_INCLUDE_PATH ${CMAKE_ANDROID_NDK}/sysroot/usr/include) | 
| 241 | 
  | 
  | 
    set(_OPENGL_LIB_PATH ${CMAKE_ANDROID_NDK}/platforms/android-${CMAKE_SYSTEM_VERSION}/arch-${CMAKE_ANDROID_ARCH}/usr/lib) | 
| 242 | 
  | 
  | 
  elseif (CMAKE_SYSTEM_NAME MATCHES "HP-UX") | 
| 243 | 
  | 
  | 
    # Handle HP-UX cases where we only want to find OpenGL in either hpux64 | 
| 244 | 
  | 
  | 
    # or hpux32 depending on if we're doing a 64 bit build. | 
| 245 | 
  | 
  | 
    if(CMAKE_SIZEOF_VOID_P EQUAL 4) | 
| 246 | 
  | 
  | 
      set(_OPENGL_LIB_PATH | 
| 247 | 
  | 
  | 
        /opt/graphics/OpenGL/lib/hpux32/) | 
| 248 | 
  | 
  | 
    else() | 
| 249 | 
  | 
  | 
      set(_OPENGL_LIB_PATH | 
| 250 | 
  | 
  | 
        /opt/graphics/OpenGL/lib/hpux64/ | 
| 251 | 
  | 
  | 
        /opt/graphics/OpenGL/lib/pa20_64) | 
| 252 | 
  | 
  | 
    endif() | 
| 253 | 
  | 
  | 
  elseif(CMAKE_SYSTEM_NAME STREQUAL Haiku) | 
| 254 | 
  | 
  | 
    set(_OPENGL_LIB_PATH | 
| 255 | 
  | 
  | 
      /boot/develop/lib/x86) | 
| 256 | 
  | 
  | 
    set(_OPENGL_INCLUDE_PATH | 
| 257 | 
  | 
  | 
      /boot/develop/headers/os/opengl) | 
| 258 | 
  | 
  | 
  elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") | 
| 259 | 
  | 
  | 
    # CMake doesn't support arbitrary globs in search paths. | 
| 260 | 
  | 
  | 
    file(GLOB _OPENGL_LIB_PATH | 
| 261 | 
  | 
  | 
      # The NVidia driver installation tool on Linux installs libraries to a | 
| 262 | 
  | 
  | 
      # `nvidia-<version>` subdirectory. | 
| 263 | 
  | 
  | 
      "/usr/lib/nvidia-*" | 
| 264 | 
  | 
  | 
      "/usr/lib32/nvidia-*") | 
| 265 | 
  | 
  | 
  endif() | 
| 266 | 
  | 
  | 
 | 
| 267 | 
  | 
  | 
  # The first line below is to make sure that the proper headers | 
| 268 | 
  | 
  | 
  # are used on a Linux machine with the NVidia drivers installed. | 
| 269 | 
  | 
  | 
  # They replace Mesa with NVidia's own library but normally do not | 
| 270 | 
  | 
  | 
  # install headers and that causes the linking to | 
| 271 | 
  | 
  | 
  # fail since the compiler finds the Mesa headers but NVidia's library. | 
| 272 | 
  | 
  | 
  # Make sure the NVIDIA directory comes BEFORE the others. | 
| 273 | 
  | 
  | 
  #  - Atanas Georgiev <[email protected]> | 
| 274 | 
  | 
  | 
  find_path(OPENGL_INCLUDE_DIR GL/gl.h | 
| 275 | 
  | 
  | 
    /usr/share/doc/NVIDIA_GLX-1.0/include | 
| 276 | 
  | 
  | 
    /usr/openwin/share/include | 
| 277 | 
  | 
  | 
    /opt/graphics/OpenGL/include | 
| 278 | 
  | 
  | 
    ${_OPENGL_INCLUDE_PATH} | 
| 279 | 
  | 
  | 
  ) | 
| 280 | 
  | 
  | 
  find_path(OPENGL_GLX_INCLUDE_DIR GL/glx.h ${_OPENGL_INCLUDE_PATH}) | 
| 281 | 
  | 
  | 
  find_path(OPENGL_EGL_INCLUDE_DIR EGL/egl.h ${_OPENGL_INCLUDE_PATH}) | 
| 282 | 
  | 
  | 
  find_path(OPENGL_GLES2_INCLUDE_DIR GLES2/gl2.h ${_OPENGL_INCLUDE_PATH}) | 
| 283 | 
  | 
  | 
  find_path(OPENGL_GLES3_INCLUDE_DIR GLES3/gl3.h ${_OPENGL_INCLUDE_PATH}) | 
| 284 | 
  | 
  | 
  find_path(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h | 
| 285 | 
  | 
  | 
    /usr/share/doc/NVIDIA_GLX-1.0/include | 
| 286 | 
  | 
  | 
    /usr/openwin/share/include | 
| 287 | 
  | 
  | 
    /opt/graphics/OpenGL/include | 
| 288 | 
  | 
  | 
  ) | 
| 289 | 
  | 
  | 
 | 
| 290 | 
  | 
  | 
  list(APPEND _OpenGL_CACHE_VARS | 
| 291 | 
  | 
  | 
    OPENGL_INCLUDE_DIR | 
| 292 | 
  | 
  | 
    OPENGL_GLX_INCLUDE_DIR | 
| 293 | 
  | 
  | 
    OPENGL_EGL_INCLUDE_DIR | 
| 294 | 
  | 
  | 
    OPENGL_GLES2_INCLUDE_DIR | 
| 295 | 
  | 
  | 
    OPENGL_GLES3_INCLUDE_DIR | 
| 296 | 
  | 
  | 
    OPENGL_xmesa_INCLUDE_DIR | 
| 297 | 
  | 
  | 
    ) | 
| 298 | 
  | 
  | 
 | 
| 299 | 
  | 
  | 
  # Search for the GLVND libraries.  We do this regardless of COMPONENTS; we'll | 
| 300 | 
  | 
  | 
  # take into account the COMPONENTS logic later. | 
| 301 | 
  | 
  | 
  find_library(OPENGL_opengl_LIBRARY | 
| 302 | 
  | 
  | 
    NAMES OpenGL | 
| 303 | 
  | 
  | 
    PATHS ${_OPENGL_LIB_PATH} | 
| 304 | 
  | 
  | 
  ) | 
| 305 | 
  | 
  | 
 | 
| 306 | 
  | 
  | 
  find_library(OPENGL_glx_LIBRARY | 
| 307 | 
  | 
  | 
    NAMES GLX | 
| 308 | 
  | 
  | 
    PATHS ${_OPENGL_LIB_PATH} | 
| 309 | 
  | 
  | 
    PATH_SUFFIXES libglvnd | 
| 310 | 
  | 
  | 
  ) | 
| 311 | 
  | 
  | 
 | 
| 312 | 
  | 
  | 
  find_library(OPENGL_egl_LIBRARY | 
| 313 | 
  | 
  | 
    NAMES EGL | 
| 314 | 
  | 
  | 
    PATHS ${_OPENGL_LIB_PATH} | 
| 315 | 
  | 
  | 
    PATH_SUFFIXES libglvnd | 
| 316 | 
  | 
  | 
  ) | 
| 317 | 
  | 
  | 
 | 
| 318 | 
  | 
  | 
  find_library(OPENGL_gles2_LIBRARY | 
| 319 | 
  | 
  | 
    NAMES GLESv2 | 
| 320 | 
  | 
  | 
    PATHS ${_OPENGL_LIB_PATH} | 
| 321 | 
  | 
  | 
  ) | 
| 322 | 
  | 
  | 
 | 
| 323 | 
  | 
  | 
  find_library(OPENGL_gles3_LIBRARY | 
| 324 | 
  | 
  | 
    NAMES GLESv3 | 
| 325 | 
  | 
  | 
          GLESv2 # mesa provides only libGLESv2 | 
| 326 | 
  | 
  | 
    PATHS ${_OPENGL_LIB_PATH} | 
| 327 | 
  | 
  | 
  ) | 
| 328 | 
  | 
  | 
 | 
| 329 | 
  | 
  | 
  find_library(OPENGL_glu_LIBRARY | 
| 330 | 
  | 
  | 
    NAMES GLU MesaGLU | 
| 331 | 
  | 
  | 
    PATHS ${OPENGL_gl_LIBRARY} | 
| 332 | 
  | 
  | 
          /opt/graphics/OpenGL/lib | 
| 333 | 
  | 
  | 
          /usr/openwin/lib | 
| 334 | 
  | 
  | 
          /usr/shlib | 
| 335 | 
  | 
  | 
  ) | 
| 336 | 
  | 
  | 
 | 
| 337 | 
  | 
  | 
  list(APPEND _OpenGL_CACHE_VARS | 
| 338 | 
  | 
  | 
    OPENGL_opengl_LIBRARY | 
| 339 | 
  | 
  | 
    OPENGL_glx_LIBRARY | 
| 340 | 
  | 
  | 
    OPENGL_egl_LIBRARY | 
| 341 | 
  | 
  | 
    OPENGL_gles2_LIBRARY | 
| 342 | 
  | 
  | 
    OPENGL_gles3_LIBRARY | 
| 343 | 
  | 
  | 
    OPENGL_glu_LIBRARY | 
| 344 | 
  | 
  | 
    ) | 
| 345 | 
  | 
  | 
 | 
| 346 | 
  | 
  | 
  set(_OpenGL_GL_POLICY_WARN 0) | 
| 347 | 
  | 
  | 
  if(NOT DEFINED OpenGL_GL_PREFERENCE) | 
| 348 | 
  | 
  | 
    set(OpenGL_GL_PREFERENCE "") | 
| 349 | 
  | 
  | 
  endif() | 
| 350 | 
  | 
  | 
  if(NOT OpenGL_GL_PREFERENCE STREQUAL "") | 
| 351 | 
  | 
  | 
    # A preference has been explicitly specified. | 
| 352 | 
  | 
  | 
    if(NOT OpenGL_GL_PREFERENCE MATCHES "^(GLVND|LEGACY)$") | 
| 353 | 
  | 
  | 
      message(FATAL_ERROR | 
| 354 | 
  | 
  | 
        "OpenGL_GL_PREFERENCE value '${OpenGL_GL_PREFERENCE}' not recognized.  " | 
| 355 | 
  | 
  | 
        "Allowed values are 'GLVND' and 'LEGACY'." | 
| 356 | 
  | 
  | 
        ) | 
| 357 | 
  | 
  | 
    endif() | 
| 358 | 
  | 
  | 
  elseif(OpenGL_FIND_COMPONENTS) | 
| 359 | 
  | 
  | 
    # No preference was explicitly specified, but the caller did request | 
| 360 | 
  | 
  | 
    # at least one GLVND component.  Prefer GLVND for legacy GL. | 
| 361 | 
  | 
  | 
    set(OpenGL_GL_PREFERENCE "GLVND") | 
| 362 | 
  | 
  | 
  else() | 
| 363 | 
  | 
  | 
    # No preference was explicitly specified and no GLVND components were | 
| 364 | 
  | 
  | 
    # requested.  Use a policy to choose the default. | 
| 365 | 
  | 
  | 
    cmake_policy(GET CMP0072 _OpenGL_GL_POLICY) | 
| 366 | 
  | 
  | 
    if("x${_OpenGL_GL_POLICY}x" STREQUAL "xNEWx") | 
| 367 | 
  | 
  | 
      set(OpenGL_GL_PREFERENCE "GLVND") | 
| 368 | 
  | 
  | 
    else() | 
| 369 | 
  | 
  | 
      set(OpenGL_GL_PREFERENCE "LEGACY") | 
| 370 | 
  | 
  | 
      if("x${_OpenGL_GL_POLICY}x" STREQUAL "xx") | 
| 371 | 
  | 
  | 
        set(_OpenGL_GL_POLICY_WARN 1) | 
| 372 | 
  | 
  | 
      endif() | 
| 373 | 
  | 
  | 
    endif() | 
| 374 | 
  | 
  | 
    unset(_OpenGL_GL_POLICY) | 
| 375 | 
  | 
  | 
  endif() | 
| 376 | 
  | 
  | 
 | 
| 377 | 
  | 
  | 
  if("x${OpenGL_GL_PREFERENCE}x" STREQUAL "xGLVNDx" AND OPENGL_opengl_LIBRARY AND OPENGL_glx_LIBRARY) | 
| 378 | 
  | 
  | 
    # We can provide legacy GL using GLVND libraries. | 
| 379 | 
  | 
  | 
    # Do not use any legacy GL library. | 
| 380 | 
  | 
  | 
    set(OPENGL_gl_LIBRARY "") | 
| 381 | 
  | 
  | 
  else() | 
| 382 | 
  | 
  | 
    # We cannot provide legacy GL using GLVND libraries. | 
| 383 | 
  | 
  | 
    # Search for the legacy GL library. | 
| 384 | 
  | 
  | 
    find_library(OPENGL_gl_LIBRARY | 
| 385 | 
  | 
  | 
      NAMES GL MesaGL | 
| 386 | 
  | 
  | 
      PATHS /opt/graphics/OpenGL/lib | 
| 387 | 
  | 
  | 
            /usr/openwin/lib | 
| 388 | 
  | 
  | 
            /usr/shlib | 
| 389 | 
  | 
  | 
            ${_OPENGL_LIB_PATH} | 
| 390 | 
  | 
  | 
      PATH_SUFFIXES libglvnd | 
| 391 | 
  | 
  | 
      ) | 
| 392 | 
  | 
  | 
    list(APPEND _OpenGL_CACHE_VARS OPENGL_gl_LIBRARY) | 
| 393 | 
  | 
  | 
  endif() | 
| 394 | 
  | 
  | 
 | 
| 395 | 
  | 
  | 
  if(_OpenGL_GL_POLICY_WARN AND OPENGL_gl_LIBRARY AND OPENGL_opengl_LIBRARY AND OPENGL_glx_LIBRARY) | 
| 396 | 
  | 
  | 
    cmake_policy(GET_WARNING CMP0072 _cmp0072_warning) | 
| 397 | 
  | 
  | 
    message(AUTHOR_WARNING | 
| 398 | 
  | 
  | 
      "${_cmp0072_warning}\n" | 
| 399 | 
  | 
  | 
      "FindOpenGL found both a legacy GL library:\n" | 
| 400 | 
  | 
  | 
      "  OPENGL_gl_LIBRARY: ${OPENGL_gl_LIBRARY}\n" | 
| 401 | 
  | 
  | 
      "and GLVND libraries for OpenGL and GLX:\n" | 
| 402 | 
  | 
  | 
      "  OPENGL_opengl_LIBRARY: ${OPENGL_opengl_LIBRARY}\n" | 
| 403 | 
  | 
  | 
      "  OPENGL_glx_LIBRARY: ${OPENGL_glx_LIBRARY}\n" | 
| 404 | 
  | 
  | 
      "OpenGL_GL_PREFERENCE has not been set to \"GLVND\" or \"LEGACY\", so for " | 
| 405 | 
  | 
  | 
      "compatibility with CMake 3.10 and below the legacy GL library will be used." | 
| 406 | 
  | 
  | 
      ) | 
| 407 | 
  | 
  | 
  endif() | 
| 408 | 
  | 
  | 
  unset(_OpenGL_GL_POLICY_WARN) | 
| 409 | 
  | 
  | 
 | 
| 410 | 
  | 
  | 
  # FPHSA cannot handle "this OR that is required", so we conditionally set what | 
| 411 | 
  | 
  | 
  # it must look for.  First clear any previous config we might have done: | 
| 412 | 
  | 
  | 
  set(_OpenGL_REQUIRED_VARS) | 
| 413 | 
  | 
  | 
 | 
| 414 | 
  | 
  | 
  # now we append the libraries as appropriate.  The complicated logic | 
| 415 | 
  | 
  | 
  # basically comes down to "use libOpenGL when we can, and add in specific | 
| 416 | 
  | 
  | 
  # context mechanisms when requested, or we need them to preserve the previous | 
| 417 | 
  | 
  | 
  # default where glx is always available." | 
| 418 | 
  | 
  | 
  if((NOT OPENGL_USE_EGL AND | 
| 419 | 
  | 
  | 
      NOT OPENGL_opengl_LIBRARY AND | 
| 420 | 
  | 
  | 
          OPENGL_glx_LIBRARY AND | 
| 421 | 
  | 
  | 
      NOT OPENGL_gl_LIBRARY) OR | 
| 422 | 
  | 
  | 
     (NOT OPENGL_USE_EGL AND | 
| 423 | 
  | 
  | 
      NOT OPENGL_USE_GLES3 AND | 
| 424 | 
  | 
  | 
      NOT OPENGL_USE_GLES2 AND | 
| 425 | 
  | 
  | 
      NOT OPENGL_glx_LIBRARY AND | 
| 426 | 
  | 
  | 
      NOT OPENGL_gl_LIBRARY) OR | 
| 427 | 
  | 
  | 
     (NOT OPENGL_USE_EGL AND | 
| 428 | 
  | 
  | 
          OPENGL_opengl_LIBRARY AND | 
| 429 | 
  | 
  | 
          OPENGL_glx_LIBRARY) OR | 
| 430 | 
  | 
  | 
     (NOT OPENGL_USE_GLES3 AND | 
| 431 | 
  | 
  | 
      NOT OPENGL_USE_GLES2 AND | 
| 432 | 
  | 
  | 
          OPENGL_USE_EGL)) | 
| 433 | 
  | 
  | 
    list(APPEND _OpenGL_REQUIRED_VARS OPENGL_opengl_LIBRARY) | 
| 434 | 
  | 
  | 
  endif() | 
| 435 | 
  | 
  | 
 | 
| 436 | 
  | 
  | 
  # GLVND GLX library.  Preferred when available. | 
| 437 | 
  | 
  | 
  if((NOT OPENGL_USE_OPENGL AND | 
| 438 | 
  | 
  | 
      NOT OPENGL_USE_GLX AND | 
| 439 | 
  | 
  | 
      NOT OPENGL_USE_EGL AND | 
| 440 | 
  | 
  | 
      NOT OPENGL_USE_GLES3 AND | 
| 441 | 
  | 
  | 
      NOT OPENGL_USE_GLES2 AND | 
| 442 | 
  | 
  | 
      NOT OPENGL_glx_LIBRARY AND | 
| 443 | 
  | 
  | 
      NOT OPENGL_gl_LIBRARY) OR | 
| 444 | 
  | 
  | 
     (    OPENGL_USE_GLX AND | 
| 445 | 
  | 
  | 
      NOT OPENGL_USE_EGL AND | 
| 446 | 
  | 
  | 
      NOT OPENGL_USE_GLES3 AND | 
| 447 | 
  | 
  | 
      NOT OPENGL_USE_GLES2 AND | 
| 448 | 
  | 
  | 
      NOT OPENGL_glx_LIBRARY AND | 
| 449 | 
  | 
  | 
      NOT OPENGL_gl_LIBRARY) OR | 
| 450 | 
  | 
  | 
     (NOT OPENGL_USE_EGL AND | 
| 451 | 
  | 
  | 
      NOT OPENGL_USE_GLES3 AND | 
| 452 | 
  | 
  | 
      NOT OPENGL_USE_GLES2 AND | 
| 453 | 
  | 
  | 
          OPENGL_opengl_LIBRARY AND | 
| 454 | 
  | 
  | 
          OPENGL_glx_LIBRARY) OR | 
| 455 | 
  | 
  | 
     (OPENGL_USE_GLX AND OPENGL_USE_EGL)) | 
| 456 | 
  | 
  | 
    list(APPEND _OpenGL_REQUIRED_VARS OPENGL_glx_LIBRARY) | 
| 457 | 
  | 
  | 
  endif() | 
| 458 | 
  | 
  | 
 | 
| 459 | 
  | 
  | 
  # GLVND EGL library. | 
| 460 | 
  | 
  | 
  if(OPENGL_USE_EGL) | 
| 461 | 
  | 
  | 
    list(APPEND _OpenGL_REQUIRED_VARS OPENGL_egl_LIBRARY) | 
| 462 | 
  | 
  | 
  endif() | 
| 463 | 
  | 
  | 
 | 
| 464 | 
  | 
  | 
  # GLVND GLES2 library. | 
| 465 | 
  | 
  | 
  if(OPENGL_USE_GLES2) | 
| 466 | 
  | 
  | 
    list(APPEND _OpenGL_REQUIRED_VARS OPENGL_gles2_LIBRARY) | 
| 467 | 
  | 
  | 
  endif() | 
| 468 | 
  | 
  | 
 | 
| 469 | 
  | 
  | 
  # GLVND GLES3 library. | 
| 470 | 
  | 
  | 
  if(OPENGL_USE_GLES3) | 
| 471 | 
  | 
  | 
    list(APPEND _OpenGL_REQUIRED_VARS OPENGL_gles3_LIBRARY) | 
| 472 | 
  | 
  | 
  endif() | 
| 473 | 
  | 
  | 
 | 
| 474 | 
  | 
  | 
  # Old-style "libGL" library: used as a fallback when GLVND isn't available. | 
| 475 | 
  | 
  | 
  if((NOT OPENGL_USE_EGL AND | 
| 476 | 
  | 
  | 
      NOT OPENGL_opengl_LIBRARY AND | 
| 477 | 
  | 
  | 
          OPENGL_glx_LIBRARY AND | 
| 478 | 
  | 
  | 
          OPENGL_gl_LIBRARY) OR | 
| 479 | 
  | 
  | 
     (NOT OPENGL_USE_EGL AND | 
| 480 | 
  | 
  | 
      NOT OPENGL_glx_LIBRARY AND | 
| 481 | 
  | 
  | 
          OPENGL_gl_LIBRARY)) | 
| 482 | 
  | 
  | 
    list(PREPEND _OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY) | 
| 483 | 
  | 
  | 
  endif() | 
| 484 | 
  | 
  | 
 | 
| 485 | 
  | 
  | 
  # We always need the 'gl.h' include dir. | 
| 486 | 
  | 
  | 
  if(OPENGL_USE_EGL) | 
| 487 | 
  | 
  | 
    list(APPEND _OpenGL_REQUIRED_VARS OPENGL_EGL_INCLUDE_DIR) | 
| 488 | 
  | 
  | 
  else() | 
| 489 | 
  | 
  | 
    list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR) | 
| 490 | 
  | 
  | 
  endif() | 
| 491 | 
  | 
  | 
 | 
| 492 | 
  | 
  | 
  unset(_OPENGL_INCLUDE_PATH) | 
| 493 | 
  | 
  | 
  unset(_OPENGL_LIB_PATH) | 
| 494 | 
  | 
  | 
 | 
| 495 | 
  | 
  | 
  find_library(OPENGL_glu_LIBRARY | 
| 496 | 
  | 
  | 
    NAMES GLU MesaGLU | 
| 497 | 
  | 
  | 
    PATHS ${OPENGL_gl_LIBRARY} | 
| 498 | 
  | 
  | 
          /opt/graphics/OpenGL/lib | 
| 499 | 
  | 
  | 
          /usr/openwin/lib | 
| 500 | 
  | 
  | 
          /usr/shlib | 
| 501 | 
  | 
  | 
  ) | 
| 502 | 
  | 
  | 
endif () | 
| 503 | 
  | 
  | 
 | 
| 504 | 
  | 
  | 
if(OPENGL_xmesa_INCLUDE_DIR) | 
| 505 | 
  | 
  | 
  set( OPENGL_XMESA_FOUND "YES" ) | 
| 506 | 
  | 
  | 
else() | 
| 507 | 
  | 
  | 
  set( OPENGL_XMESA_FOUND "NO" ) | 
| 508 | 
  | 
  | 
endif() | 
| 509 | 
  | 
  | 
 | 
| 510 | 
  | 
  | 
if(OPENGL_glu_LIBRARY) | 
| 511 | 
  | 
  | 
  set( OPENGL_GLU_FOUND "YES" ) | 
| 512 | 
  | 
  | 
else() | 
| 513 | 
  | 
  | 
  set( OPENGL_GLU_FOUND "NO" ) | 
| 514 | 
  | 
  | 
endif() | 
| 515 | 
  | 
  | 
 | 
| 516 | 
  | 
  | 
# OpenGL_OpenGL_FOUND is a bit unique in that it is okay if /either/ libOpenGL | 
| 517 | 
  | 
  | 
# or libGL is found. | 
| 518 | 
  | 
  | 
# Using libGL with libEGL is never okay, though; we handle that case later. | 
| 519 | 
  | 
  | 
if(NOT OPENGL_opengl_LIBRARY AND NOT OPENGL_gl_LIBRARY) | 
| 520 | 
  | 
  | 
  set(OpenGL_OpenGL_FOUND FALSE) | 
| 521 | 
  | 
  | 
else() | 
| 522 | 
  | 
  | 
  set(OpenGL_OpenGL_FOUND TRUE) | 
| 523 | 
  | 
  | 
endif() | 
| 524 | 
  | 
  | 
 | 
| 525 | 
  | 
  | 
if(OPENGL_glx_LIBRARY AND OPENGL_GLX_INCLUDE_DIR) | 
| 526 | 
  | 
  | 
  set(OpenGL_GLX_FOUND TRUE) | 
| 527 | 
  | 
  | 
else() | 
| 528 | 
  | 
  | 
  set(OpenGL_GLX_FOUND FALSE) | 
| 529 | 
  | 
  | 
endif() | 
| 530 | 
  | 
  | 
 | 
| 531 | 
  | 
  | 
if(OPENGL_egl_LIBRARY AND OPENGL_EGL_INCLUDE_DIR) | 
| 532 | 
  | 
  | 
  set(OpenGL_EGL_FOUND TRUE) | 
| 533 | 
  | 
  | 
else() | 
| 534 | 
  | 
  | 
  set(OpenGL_EGL_FOUND FALSE) | 
| 535 | 
  | 
  | 
endif() | 
| 536 | 
  | 
  | 
 | 
| 537 | 
  | 
  | 
if(OPENGL_gles2_LIBRARY AND OPENGL_GLES2_INCLUDE_DIR) | 
| 538 | 
  | 
  | 
  set(OpenGL_GLES2_FOUND TRUE) | 
| 539 | 
  | 
  | 
else() | 
| 540 | 
  | 
  | 
  set(OpenGL_GLES2_FOUND FALSE) | 
| 541 | 
  | 
  | 
endif() | 
| 542 | 
  | 
  | 
 | 
| 543 | 
  | 
  | 
if(OPENGL_gles3_LIBRARY AND OPENGL_GLES3_INCLUDE_DIR) | 
| 544 | 
  | 
  | 
  set(OpenGL_GLES3_FOUND TRUE) | 
| 545 | 
  | 
  | 
else() | 
| 546 | 
  | 
  | 
  set(OpenGL_GLES3_FOUND FALSE) | 
| 547 | 
  | 
  | 
endif() | 
| 548 | 
  | 
  | 
 | 
| 549 | 
  | 
  | 
# User-visible names should be plural. | 
| 550 | 
  | 
  | 
if(OPENGL_EGL_INCLUDE_DIR) | 
| 551 | 
  | 
  | 
  set(OPENGL_EGL_INCLUDE_DIRS ${OPENGL_EGL_INCLUDE_DIR}) | 
| 552 | 
  | 
  | 
endif() | 
| 553 | 
  | 
  | 
 | 
| 554 | 
  | 
  | 
include(FindPackageHandleStandardArgs) | 
| 555 | 
  | 
  | 
if (CMAKE_FIND_PACKAGE_NAME STREQUAL "GLU") | 
| 556 | 
  | 
  | 
  # FindGLU include()'s this module. It's an old pattern, but rather than | 
| 557 | 
  | 
  | 
  # trying to suppress this from outside the module (which is then sensitive to | 
| 558 | 
  | 
  | 
  # the contents, detect the case in this module and suppress it explicitly. | 
| 559 | 
  | 
  | 
  set(FPHSA_NAME_MISMATCHED 1) | 
| 560 | 
  | 
  | 
endif () | 
| 561 | 
  | 
  | 
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS} | 
| 562 | 
  | 
  | 
                                  HANDLE_COMPONENTS) | 
| 563 | 
  | 
  | 
unset(FPHSA_NAME_MISMATCHED) | 
| 564 | 
  | 
  | 
unset(_OpenGL_REQUIRED_VARS) | 
| 565 | 
  | 
  | 
 | 
| 566 | 
  | 
  | 
# OpenGL:: targets | 
| 567 | 
  | 
  | 
if(OPENGL_FOUND) | 
| 568 | 
  | 
  | 
  # ::OpenGL is a GLVND library, and thus Linux-only: we don't bother checking | 
| 569 | 
  | 
  | 
  # for a framework version of this library. | 
| 570 | 
  | 
  | 
  if(OPENGL_opengl_LIBRARY AND NOT TARGET OpenGL::OpenGL) | 
| 571 | 
  | 
  | 
    if(IS_ABSOLUTE "${OPENGL_opengl_LIBRARY}") | 
| 572 | 
  | 
  | 
      add_library(OpenGL::OpenGL UNKNOWN IMPORTED) | 
| 573 | 
  | 
  | 
      set_target_properties(OpenGL::OpenGL PROPERTIES IMPORTED_LOCATION | 
| 574 | 
  | 
  | 
                            "${OPENGL_opengl_LIBRARY}") | 
| 575 | 
  | 
  | 
    else() | 
| 576 | 
  | 
  | 
      add_library(OpenGL::OpenGL INTERFACE IMPORTED) | 
| 577 | 
  | 
  | 
      set_target_properties(OpenGL::OpenGL PROPERTIES IMPORTED_LIBNAME | 
| 578 | 
  | 
  | 
                            "${OPENGL_opengl_LIBRARY}") | 
| 579 | 
  | 
  | 
    endif() | 
| 580 | 
  | 
  | 
    set_target_properties(OpenGL::OpenGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES | 
| 581 | 
  | 
  | 
                          "${OPENGL_INCLUDE_DIR}") | 
| 582 | 
  | 
  | 
    set(_OpenGL_EGL_IMPL OpenGL::OpenGL) | 
| 583 | 
  | 
  | 
  endif() | 
| 584 | 
  | 
  | 
 | 
| 585 | 
  | 
  | 
  # ::GLX is a GLVND library, and thus Linux-only: we don't bother checking | 
| 586 | 
  | 
  | 
  # for a framework version of this library. | 
| 587 | 
  | 
  | 
  if(OpenGL_GLX_FOUND AND NOT TARGET OpenGL::GLX AND TARGET OpenGL::OpenGL) | 
| 588 | 
  | 
  | 
    if(IS_ABSOLUTE "${OPENGL_glx_LIBRARY}") | 
| 589 | 
  | 
  | 
      add_library(OpenGL::GLX UNKNOWN IMPORTED) | 
| 590 | 
  | 
  | 
      set_target_properties(OpenGL::GLX PROPERTIES IMPORTED_LOCATION | 
| 591 | 
  | 
  | 
                            "${OPENGL_glx_LIBRARY}") | 
| 592 | 
  | 
  | 
    else() | 
| 593 | 
  | 
  | 
      add_library(OpenGL::GLX INTERFACE IMPORTED) | 
| 594 | 
  | 
  | 
      set_target_properties(OpenGL::GLX PROPERTIES IMPORTED_LIBNAME | 
| 595 | 
  | 
  | 
                            "${OPENGL_glx_LIBRARY}") | 
| 596 | 
  | 
  | 
    endif() | 
| 597 | 
  | 
  | 
    set_target_properties(OpenGL::GLX PROPERTIES INTERFACE_LINK_LIBRARIES | 
| 598 | 
  | 
  | 
                          OpenGL::OpenGL) | 
| 599 | 
  | 
  | 
    set_target_properties(OpenGL::GLX PROPERTIES INTERFACE_INCLUDE_DIRECTORIES | 
| 600 | 
  | 
  | 
                          "${OPENGL_GLX_INCLUDE_DIR}") | 
| 601 | 
  | 
  | 
  endif() | 
| 602 | 
  | 
  | 
 | 
| 603 | 
  | 
  | 
  # ::GLES2 is a GLVND library, and thus Linux-only: we don't bother checking | 
| 604 | 
  | 
  | 
  # for a framework version of this library. | 
| 605 | 
  | 
  | 
  if(OpenGL_GLES2_FOUND AND NOT TARGET OpenGL::GLES2) | 
| 606 | 
  | 
  | 
 | 
| 607 | 
  | 
  | 
    # Initialize target | 
| 608 | 
  | 
  | 
    if(NOT OPENGL_gles2_LIBRARY) | 
| 609 | 
  | 
  | 
      add_library(OpenGL::GLES2 INTERFACE IMPORTED) | 
| 610 | 
  | 
  | 
    else() | 
| 611 | 
  | 
  | 
      if(IS_ABSOLUTE "${OPENGL_gles2_LIBRARY}") | 
| 612 | 
  | 
  | 
        add_library(OpenGL::GLES2 UNKNOWN IMPORTED) | 
| 613 | 
  | 
  | 
        set_target_properties(OpenGL::GLES2 PROPERTIES | 
| 614 | 
  | 
  | 
          IMPORTED_LOCATION "${OPENGL_gles2_LIBRARY}" | 
| 615 | 
  | 
  | 
        ) | 
| 616 | 
  | 
  | 
      else() | 
| 617 | 
  | 
  | 
        add_library(OpenGL::GLES2 INTERFACE IMPORTED) | 
| 618 | 
  | 
  | 
        set_target_properties(OpenGL::GLES2 PROPERTIES | 
| 619 | 
  | 
  | 
          IMPORTED_LIBNAME "${OPENGL_gles2_LIBRARY}" | 
| 620 | 
  | 
  | 
        ) | 
| 621 | 
  | 
  | 
      endif() | 
| 622 | 
  | 
  | 
    endif() | 
| 623 | 
  | 
  | 
 | 
| 624 | 
  | 
  | 
    # Attach target properties | 
| 625 | 
  | 
  | 
    set_target_properties(OpenGL::GLES2 | 
| 626 | 
  | 
  | 
      PROPERTIES | 
| 627 | 
  | 
  | 
        INTERFACE_INCLUDE_DIRECTORIES | 
| 628 | 
  | 
  | 
          "${OPENGL_GLES2_INCLUDE_DIR}" | 
| 629 | 
  | 
  | 
    ) | 
| 630 | 
  | 
  | 
 | 
| 631 | 
  | 
  | 
    if (OPENGL_USE_GLES2) | 
| 632 | 
  | 
  | 
      set(_OpenGL_EGL_IMPL OpenGL::GLES2) | 
| 633 | 
  | 
  | 
    endif () | 
| 634 | 
  | 
  | 
 | 
| 635 | 
  | 
  | 
  endif() | 
| 636 | 
  | 
  | 
 | 
| 637 | 
  | 
  | 
  # ::GLES3 is a GLVND library, and thus Linux-only: we don't bother checking | 
| 638 | 
  | 
  | 
  # for a framework version of this library. | 
| 639 | 
  | 
  | 
  if(OpenGL_GLES3_FOUND AND NOT TARGET OpenGL::GLES3) | 
| 640 | 
  | 
  | 
 | 
| 641 | 
  | 
  | 
    # Initialize target | 
| 642 | 
  | 
  | 
    if(NOT OPENGL_gles3_LIBRARY) | 
| 643 | 
  | 
  | 
      add_library(OpenGL::GLES3 INTERFACE IMPORTED) | 
| 644 | 
  | 
  | 
    else() | 
| 645 | 
  | 
  | 
      if(IS_ABSOLUTE "${OPENGL_gles3_LIBRARY}") | 
| 646 | 
  | 
  | 
        add_library(OpenGL::GLES3 UNKNOWN IMPORTED) | 
| 647 | 
  | 
  | 
        set_target_properties(OpenGL::GLES3 PROPERTIES | 
| 648 | 
  | 
  | 
          IMPORTED_LOCATION "${OPENGL_gles3_LIBRARY}" | 
| 649 | 
  | 
  | 
        ) | 
| 650 | 
  | 
  | 
      else() | 
| 651 | 
  | 
  | 
        add_library(OpenGL::GLES3 INTERFACE IMPORTED) | 
| 652 | 
  | 
  | 
        set_target_properties(OpenGL::GLES3 PROPERTIES | 
| 653 | 
  | 
  | 
          IMPORTED_LIBNAME "${OPENGL_gles3_LIBRARY}" | 
| 654 | 
  | 
  | 
        ) | 
| 655 | 
  | 
  | 
      endif() | 
| 656 | 
  | 
  | 
    endif() | 
| 657 | 
  | 
  | 
 | 
| 658 | 
  | 
  | 
    # Attach target properties | 
| 659 | 
  | 
  | 
    set_target_properties(OpenGL::GLES3 PROPERTIES | 
| 660 | 
  | 
  | 
      INTERFACE_INCLUDE_DIRECTORIES | 
| 661 | 
  | 
  | 
        "${OPENGL_GLES3_INCLUDE_DIR}" | 
| 662 | 
  | 
  | 
    ) | 
| 663 | 
  | 
  | 
 | 
| 664 | 
  | 
  | 
    if (OPENGL_USE_GLES3) | 
| 665 | 
  | 
  | 
      set(_OpenGL_EGL_IMPL OpenGL::GLES3) | 
| 666 | 
  | 
  | 
    endif () | 
| 667 | 
  | 
  | 
 | 
| 668 | 
  | 
  | 
  endif() | 
| 669 | 
  | 
  | 
 | 
| 670 | 
  | 
  | 
  if(OPENGL_gl_LIBRARY AND NOT TARGET OpenGL::GL) | 
| 671 | 
  | 
  | 
    # A legacy GL library is available, so use it for the legacy GL target. | 
| 672 | 
  | 
  | 
    if(IS_ABSOLUTE "${OPENGL_gl_LIBRARY}") | 
| 673 | 
  | 
  | 
      add_library(OpenGL::GL UNKNOWN IMPORTED) | 
| 674 | 
  | 
  | 
      if(OPENGL_gl_LIBRARY MATCHES "/([^/]+)\\.framework$") | 
| 675 | 
  | 
  | 
        set(_gl_fw "${OPENGL_gl_LIBRARY}/${CMAKE_MATCH_1}") | 
| 676 | 
  | 
  | 
        if(EXISTS "${_gl_fw}.tbd") | 
| 677 | 
  | 
  | 
          string(APPEND _gl_fw ".tbd") | 
| 678 | 
  | 
  | 
        endif() | 
| 679 | 
  | 
  | 
        set_target_properties(OpenGL::GL PROPERTIES | 
| 680 | 
  | 
  | 
          IMPORTED_LOCATION "${_gl_fw}") | 
| 681 | 
  | 
  | 
      else() | 
| 682 | 
  | 
  | 
        set_target_properties(OpenGL::GL PROPERTIES | 
| 683 | 
  | 
  | 
          IMPORTED_LOCATION "${OPENGL_gl_LIBRARY}") | 
| 684 | 
  | 
  | 
      endif() | 
| 685 | 
  | 
  | 
    else() | 
| 686 | 
  | 
  | 
      add_library(OpenGL::GL INTERFACE IMPORTED) | 
| 687 | 
  | 
  | 
      set_target_properties(OpenGL::GL PROPERTIES | 
| 688 | 
  | 
  | 
        IMPORTED_LIBNAME "${OPENGL_gl_LIBRARY}") | 
| 689 | 
  | 
  | 
    endif() | 
| 690 | 
  | 
  | 
    set_target_properties(OpenGL::GL PROPERTIES | 
| 691 | 
  | 
  | 
      INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}") | 
| 692 | 
  | 
  | 
  elseif(NOT TARGET OpenGL::GL AND TARGET OpenGL::OpenGL AND TARGET OpenGL::GLX) | 
| 693 | 
  | 
  | 
    # A legacy GL library is not available, but we can provide the legacy GL | 
| 694 | 
  | 
  | 
    # target using GLVND OpenGL+GLX. | 
| 695 | 
  | 
  | 
    add_library(OpenGL::GL INTERFACE IMPORTED) | 
| 696 | 
  | 
  | 
    set_target_properties(OpenGL::GL PROPERTIES INTERFACE_LINK_LIBRARIES | 
| 697 | 
  | 
  | 
                          OpenGL::OpenGL) | 
| 698 | 
  | 
  | 
    set_property(TARGET OpenGL::GL APPEND PROPERTY INTERFACE_LINK_LIBRARIES | 
| 699 | 
  | 
  | 
                 OpenGL::GLX) | 
| 700 | 
  | 
  | 
    set_target_properties(OpenGL::GL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES | 
| 701 | 
  | 
  | 
                          "${OPENGL_INCLUDE_DIR}") | 
| 702 | 
  | 
  | 
  endif() | 
| 703 | 
  | 
  | 
 | 
| 704 | 
  | 
  | 
  # ::EGL is a GLVND library, and thus Linux-only: we don't bother checking | 
| 705 | 
  | 
  | 
  # for a framework version of this library. | 
| 706 | 
  | 
  | 
  # Note we test whether _OpenGL_EGL_IMPL is set. Based on the OpenGL implementation, | 
| 707 | 
  | 
  | 
  # _OpenGL_EGL_IMPL will be one of OpenGL::OpenGL, OpenGL::GLES2, OpenGL::GLES3 | 
| 708 | 
  | 
  | 
  if(_OpenGL_EGL_IMPL AND OpenGL_EGL_FOUND AND NOT TARGET OpenGL::EGL) | 
| 709 | 
  | 
  | 
    if(IS_ABSOLUTE "${OPENGL_egl_LIBRARY}") | 
| 710 | 
  | 
  | 
      add_library(OpenGL::EGL UNKNOWN IMPORTED) | 
| 711 | 
  | 
  | 
      set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LOCATION | 
| 712 | 
  | 
  | 
                            "${OPENGL_egl_LIBRARY}") | 
| 713 | 
  | 
  | 
    else() | 
| 714 | 
  | 
  | 
      add_library(OpenGL::EGL INTERFACE IMPORTED) | 
| 715 | 
  | 
  | 
      set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LIBNAME | 
| 716 | 
  | 
  | 
                            "${OPENGL_egl_LIBRARY}") | 
| 717 | 
  | 
  | 
    endif() | 
| 718 | 
  | 
  | 
    set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_LINK_LIBRARIES | 
| 719 | 
  | 
  | 
                          "${_OpenGL_EGL_IMPL}") | 
| 720 | 
  | 
  | 
    # Note that EGL's include directory is different from OpenGL/GLX's! | 
| 721 | 
  | 
  | 
    set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES | 
| 722 | 
  | 
  | 
                          "${OPENGL_EGL_INCLUDE_DIR}") | 
| 723 | 
  | 
  | 
  endif() | 
| 724 | 
  | 
  | 
 | 
| 725 | 
  | 
  | 
  if(OPENGL_GLU_FOUND AND NOT TARGET OpenGL::GLU) | 
| 726 | 
  | 
  | 
    if(IS_ABSOLUTE "${OPENGL_glu_LIBRARY}") | 
| 727 | 
  | 
  | 
      add_library(OpenGL::GLU UNKNOWN IMPORTED) | 
| 728 | 
  | 
  | 
      if(OPENGL_glu_LIBRARY MATCHES "/([^/]+)\\.framework$") | 
| 729 | 
  | 
  | 
        set(_glu_fw "${OPENGL_glu_LIBRARY}/${CMAKE_MATCH_1}") | 
| 730 | 
  | 
  | 
        if(EXISTS "${_glu_fw}.tbd") | 
| 731 | 
  | 
  | 
          string(APPEND _glu_fw ".tbd") | 
| 732 | 
  | 
  | 
        endif() | 
| 733 | 
  | 
  | 
        set_target_properties(OpenGL::GLU PROPERTIES | 
| 734 | 
  | 
  | 
          IMPORTED_LOCATION "${_glu_fw}") | 
| 735 | 
  | 
  | 
      else() | 
| 736 | 
  | 
  | 
        set_target_properties(OpenGL::GLU PROPERTIES | 
| 737 | 
  | 
  | 
          IMPORTED_LOCATION "${OPENGL_glu_LIBRARY}") | 
| 738 | 
  | 
  | 
      endif() | 
| 739 | 
  | 
  | 
    else() | 
| 740 | 
  | 
  | 
      add_library(OpenGL::GLU INTERFACE IMPORTED) | 
| 741 | 
  | 
  | 
      set_target_properties(OpenGL::GLU PROPERTIES | 
| 742 | 
  | 
  | 
        IMPORTED_LIBNAME "${OPENGL_glu_LIBRARY}") | 
| 743 | 
  | 
  | 
    endif() | 
| 744 | 
  | 
  | 
    set_target_properties(OpenGL::GLU PROPERTIES | 
| 745 | 
  | 
  | 
      INTERFACE_LINK_LIBRARIES OpenGL::GL) | 
| 746 | 
  | 
  | 
  endif() | 
| 747 | 
  | 
  | 
 | 
| 748 | 
  | 
  | 
  # OPENGL_LIBRARIES mirrors OpenGL::GL's logic ... | 
| 749 | 
  | 
  | 
  if(OPENGL_gl_LIBRARY) | 
| 750 | 
  | 
  | 
    set(OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY}) | 
| 751 | 
  | 
  | 
  elseif(TARGET OpenGL::OpenGL AND TARGET OpenGL::GLX) | 
| 752 | 
  | 
  | 
    set(OPENGL_LIBRARIES ${OPENGL_opengl_LIBRARY} ${OPENGL_glx_LIBRARY}) | 
| 753 | 
  | 
  | 
  else() | 
| 754 | 
  | 
  | 
    set(OPENGL_LIBRARIES "") | 
| 755 | 
  | 
  | 
  endif() | 
| 756 | 
  | 
  | 
  # ... and also includes GLU, if available. | 
| 757 | 
  | 
  | 
  if(TARGET OpenGL::GLU) | 
| 758 | 
  | 
  | 
    list(APPEND OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY}) | 
| 759 | 
  | 
  | 
  endif() | 
| 760 | 
  | 
  | 
endif() | 
| 761 | 
  | 
  | 
 | 
| 762 | 
  | 
  | 
# This deprecated setting is for backward compatibility with CMake1.4 | 
| 763 | 
  | 
  | 
set(OPENGL_LIBRARY ${OPENGL_LIBRARIES}) | 
| 764 | 
  | 
  | 
# This deprecated setting is for backward compatibility with CMake1.4 | 
| 765 | 
  | 
  | 
set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR}) | 
| 766 | 
  | 
  | 
 | 
| 767 | 
  | 
  | 
mark_as_advanced(${_OpenGL_CACHE_VARS}) | 
| 768 | 
  | 
  | 
unset(_OpenGL_CACHE_VARS) |