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