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: 5FindOpenGL 6---------- 7 8FindModule 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 16Optional COMPONENTS 17^^^^^^^^^^^^^^^^^^^ 18 19.. versionadded:: 3.10 20 21This module respects several optional COMPONENTS: ``EGL``, ``GLX``, and 22``OpenGL``. There are corresponding import targets for each of these flags. 23 24IMPORTED Targets 25^^^^^^^^^^^^^^^^ 26 27.. versionadded:: 3.8 28 29This module defines the :prop_tgt:`IMPORTED` targets: 30 31``OpenGL::GL`` 32 Defined to the platform-specific OpenGL libraries if the system has OpenGL. 33``OpenGL::GLU`` 34 Defined if the system has OpenGL Utility Library (GLU). 35 36.. versionadded:: 3.10 37 Additionally, the following GLVND-specific library targets are defined: 38 39``OpenGL::OpenGL`` 40 Defined to libOpenGL if the system is GLVND-based. 41``OpenGL::GLX`` 42 Defined if the system has OpenGL Extension to the X Window System (GLX). 43``OpenGL::EGL`` 44 Defined if the system has EGL. 45 46Result Variables 47^^^^^^^^^^^^^^^^ 48 49This module sets the following variables: 50 51``OPENGL_FOUND`` 52 True, if the system has OpenGL and all components are found. 53``OPENGL_XMESA_FOUND`` 54 True, if the system has XMESA. 55``OPENGL_GLU_FOUND`` 56 True, if the system has GLU. 57``OpenGL_OpenGL_FOUND`` 58 True, if the system has an OpenGL library. 59``OpenGL_GLX_FOUND`` 60 True, if the system has GLX. 61``OpenGL_EGL_FOUND`` 62 True, if the system has EGL. 63``OPENGL_INCLUDE_DIR`` 64 Path to the OpenGL include directory. 65``OPENGL_EGL_INCLUDE_DIRS`` 66 Path to the EGL include directory. 67``OPENGL_LIBRARIES`` 68 Paths to the OpenGL library, windowing system libraries, and GLU libraries. 69 On Linux, this assumes GLX and is never correct for EGL-based targets. 70 Clients are encouraged to use the ``OpenGL::*`` import targets instead. 71 72.. versionadded:: 3.10 73 Variables for GLVND-specific libraries ``OpenGL``, ``EGL`` and ``GLX``. 74 75Cache variables 76^^^^^^^^^^^^^^^ 77 78The following cache variables may also be set: 79 80``OPENGL_egl_LIBRARY`` 81 Path to the EGL library. 82``OPENGL_glu_LIBRARY`` 83 Path to the GLU library. 84``OPENGL_glx_LIBRARY`` 85 Path to the GLVND 'GLX' library. 86``OPENGL_opengl_LIBRARY`` 87 Path to the GLVND 'OpenGL' library 88``OPENGL_gl_LIBRARY`` 89 Path to the OpenGL library. New code should prefer the ``OpenGL::*`` import 90 targets. 91 92.. versionadded:: 3.10 93 Variables for GLVND-specific libraries ``OpenGL``, ``EGL`` and ``GLX``. 94 95.. _`Linux Specific`: 96 97Linux-specific 98^^^^^^^^^^^^^^ 99 100Some Linux systems utilize GLVND as a new ABI for OpenGL. GLVND separates 101context libraries from OpenGL itself; OpenGL lives in "libOpenGL", and 102contexts are defined in "libGLX" or "libEGL". GLVND is currently the only way 103to get OpenGL 3+ functionality via EGL in a manner portable across vendors. 104Projects may use GLVND explicitly with target ``OpenGL::OpenGL`` and either 105``OpenGL::GLX`` or ``OpenGL::EGL``. 106 107Projects may use the ``OpenGL::GL`` target (or ``OPENGL_LIBRARIES`` variable) 108to use legacy GL interfaces. These will use the legacy GL library located 109by ``OPENGL_gl_LIBRARY``, if available. If ``OPENGL_gl_LIBRARY`` is empty or 110not found and GLVND is available, the ``OpenGL::GL`` target will use GLVND 111``OpenGL::OpenGL`` and ``OpenGL::GLX`` (and the ``OPENGL_LIBRARIES`` 112variable will use the corresponding libraries). Thus, for non-EGL-based 113Linux targets, the ``OpenGL::GL`` target is most portable. 114 115A ``OpenGL_GL_PREFERENCE`` variable may be set to specify the preferred way 116to provide legacy GL interfaces in case multiple choices are available. 117The value may be one of: 118 119``GLVND`` 120 If the GLVND OpenGL and GLX libraries are available, prefer them. 121 This forces ``OPENGL_gl_LIBRARY`` to be empty. 122 123 .. versionchanged:: 3.11 124 This is the default, unless policy :policy:`CMP0072` is set to ``OLD`` 125 and no components are requeted (since components 126 correspond to GLVND libraries). 127 128``LEGACY`` 129 Prefer to use the legacy libGL library, if available. 130 131For EGL targets the client must rely on GLVND support on the user's system. 132Linking should use the ``OpenGL::OpenGL OpenGL::EGL`` targets. Using GLES* 133libraries is theoretically possible in place of ``OpenGL::OpenGL``, but this 134module does not currently support that; contributions welcome. 135 136``OPENGL_egl_LIBRARY`` and ``OPENGL_EGL_INCLUDE_DIRS`` are defined in the case of 137GLVND. For non-GLVND Linux and other systems these are left undefined. 138 139macOS-Specific 140^^^^^^^^^^^^^^ 141 142On OSX FindOpenGL defaults to using the framework version of OpenGL. People 143will have to change the cache values of OPENGL_glu_LIBRARY and 144OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX. 145#]=======================================================================] 146 147set(_OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY) 148 149# Provide OPENGL_USE_<C> variables for each component. 150foreach(component ${OpenGL_FIND_COMPONENTS}) 151 string(TOUPPER ${component} _COMPONENT) 152 set(OPENGL_USE_${_COMPONENT} 1) 153endforeach() 154 155set(_OpenGL_CACHE_VARS) 156 157if (WIN32) 158 159 if(BORLAND) 160 set (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32") 161 set (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32") 162 else() 163 set (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32") 164 set (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32") 165 endif() 166 167 list(APPEND _OpenGL_CACHE_VARS 168 OPENGL_gl_LIBRARY 169 OPENGL_glu_LIBRARY 170 ) 171elseif (APPLE) 172 # The OpenGL.framework provides both gl and glu 173 find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL library for OS X") 174 find_library(OPENGL_glu_LIBRARY OpenGL DOC 175 "GLU library for OS X (usually same as OpenGL library)") 176 find_path(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OS X") 177 list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR) 178 179 list(APPEND _OpenGL_CACHE_VARS 180 OPENGL_INCLUDE_DIR 181 OPENGL_gl_LIBRARY 182 OPENGL_glu_LIBRARY 183 ) 184else() 185 if (CMAKE_SYSTEM_NAME MATCHES "HP-UX") 186 # Handle HP-UX cases where we only want to find OpenGL in either hpux64 187 # or hpux32 depending on if we're doing a 64 bit build. 188 if(CMAKE_SIZEOF_VOID_P EQUAL 4) 189 set(_OPENGL_LIB_PATH 190 /opt/graphics/OpenGL/lib/hpux32/) 191 else() 192 set(_OPENGL_LIB_PATH 193 /opt/graphics/OpenGL/lib/hpux64/ 194 /opt/graphics/OpenGL/lib/pa20_64) 195 endif() 196 elseif(CMAKE_SYSTEM_NAME STREQUAL Haiku) 197 set(_OPENGL_LIB_PATH 198 /boot/develop/lib/x86) 199 set(_OPENGL_INCLUDE_PATH 200 /boot/develop/headers/os/opengl) 201 endif() 202 203 # The first line below is to make sure that the proper headers 204 # are used on a Linux machine with the NVidia drivers installed. 205 # They replace Mesa with NVidia's own library but normally do not 206 # install headers and that causes the linking to 207 # fail since the compiler finds the Mesa headers but NVidia's library. 208 # Make sure the NVIDIA directory comes BEFORE the others. 209 # - Atanas Georgiev <[email protected]> 210 find_path(OPENGL_INCLUDE_DIR GL/gl.h 211 /usr/share/doc/NVIDIA_GLX-1.0/include 212 /usr/openwin/share/include 213 /opt/graphics/OpenGL/include 214 ${_OPENGL_INCLUDE_PATH} 215 ) 216 find_path(OPENGL_GLX_INCLUDE_DIR GL/glx.h ${_OPENGL_INCLUDE_PATH}) 217 find_path(OPENGL_EGL_INCLUDE_DIR EGL/egl.h ${_OPENGL_INCLUDE_PATH}) 218 find_path(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h 219 /usr/share/doc/NVIDIA_GLX-1.0/include 220 /usr/openwin/share/include 221 /opt/graphics/OpenGL/include 222 ) 223 list(APPEND _OpenGL_CACHE_VARS 224 OPENGL_INCLUDE_DIR 225 OPENGL_GLX_INCLUDE_DIR 226 OPENGL_EGL_INCLUDE_DIR 227 OPENGL_xmesa_INCLUDE_DIR 228 ) 229 230 # Search for the GLVND libraries. We do this regardless of COMPONENTS; we'll 231 # take into account the COMPONENTS logic later. 232 find_library(OPENGL_opengl_LIBRARY 233 NAMES OpenGL 234 PATHS ${_OPENGL_LIB_PATH} 235 ) 236 237 find_library(OPENGL_glx_LIBRARY 238 NAMES GLX 239 PATHS ${_OPENGL_LIB_PATH} 240 PATH_SUFFIXES libglvnd 241 ) 242 243 find_library(OPENGL_egl_LIBRARY 244 NAMES EGL 245 PATHS ${_OPENGL_LIB_PATH} 246 PATH_SUFFIXES libglvnd 247 ) 248 249 find_library(OPENGL_glu_LIBRARY 250 NAMES GLU MesaGLU 251 PATHS ${OPENGL_gl_LIBRARY} 252 /opt/graphics/OpenGL/lib 253 /usr/openwin/lib 254 /usr/shlib 255 ) 256 257 list(APPEND _OpenGL_CACHE_VARS 258 OPENGL_opengl_LIBRARY 259 OPENGL_glx_LIBRARY 260 OPENGL_egl_LIBRARY 261 OPENGL_glu_LIBRARY 262 ) 263 264 set(_OpenGL_GL_POLICY_WARN 0) 265 if(NOT DEFINED OpenGL_GL_PREFERENCE) 266 set(OpenGL_GL_PREFERENCE "") 267 endif() 268 if(NOT OpenGL_GL_PREFERENCE STREQUAL "") 269 # A preference has been explicitly specified. 270 if(NOT OpenGL_GL_PREFERENCE MATCHES "^(GLVND|LEGACY)$") 271 message(FATAL_ERROR 272 "OpenGL_GL_PREFERENCE value '${OpenGL_GL_PREFERENCE}' not recognized. " 273 "Allowed values are 'GLVND' and 'LEGACY'." 274 ) 275 endif() 276 elseif(OpenGL_FIND_COMPONENTS) 277 # No preference was explicitly specified, but the caller did request 278 # at least one GLVND component. Prefer GLVND for legacy GL. 279 set(OpenGL_GL_PREFERENCE "GLVND") 280 else() 281 # No preference was explicitly specified and no GLVND components were 282 # requested. Use a policy to choose the default. 283 cmake_policy(GET CMP0072 _OpenGL_GL_POLICY) 284 if("x${_OpenGL_GL_POLICY}x" STREQUAL "xNEWx") 285 set(OpenGL_GL_PREFERENCE "GLVND") 286 else() 287 set(OpenGL_GL_PREFERENCE "LEGACY") 288 if("x${_OpenGL_GL_POLICY}x" STREQUAL "xx") 289 set(_OpenGL_GL_POLICY_WARN 1) 290 endif() 291 endif() 292 unset(_OpenGL_GL_POLICY) 293 endif() 294 295 if("x${OpenGL_GL_PREFERENCE}x" STREQUAL "xGLVNDx" AND OPENGL_opengl_LIBRARY AND OPENGL_glx_LIBRARY) 296 # We can provide legacy GL using GLVND libraries. 297 # Do not use any legacy GL library. 298 set(OPENGL_gl_LIBRARY "") 299 else() 300 # We cannot provide legacy GL using GLVND libraries. 301 # Search for the legacy GL library. 302 find_library(OPENGL_gl_LIBRARY 303 NAMES GL MesaGL 304 PATHS /opt/graphics/OpenGL/lib 305 /usr/openwin/lib 306 /usr/shlib 307 ${_OPENGL_LIB_PATH} 308 PATH_SUFFIXES libglvnd 309 ) 310 list(APPEND _OpenGL_CACHE_VARS OPENGL_gl_LIBRARY) 311 endif() 312 313 if(_OpenGL_GL_POLICY_WARN AND OPENGL_gl_LIBRARY AND OPENGL_opengl_LIBRARY AND OPENGL_glx_LIBRARY) 314 cmake_policy(GET_WARNING CMP0072 _cmp0072_warning) 315 message(AUTHOR_WARNING 316 "${_cmp0072_warning}\n" 317 "FindOpenGL found both a legacy GL library:\n" 318 " OPENGL_gl_LIBRARY: ${OPENGL_gl_LIBRARY}\n" 319 "and GLVND libraries for OpenGL and GLX:\n" 320 " OPENGL_opengl_LIBRARY: ${OPENGL_opengl_LIBRARY}\n" 321 " OPENGL_glx_LIBRARY: ${OPENGL_glx_LIBRARY}\n" 322 "OpenGL_GL_PREFERENCE has not been set to \"GLVND\" or \"LEGACY\", so for " 323 "compatibility with CMake 3.10 and below the legacy GL library will be used." 324 ) 325 endif() 326 unset(_OpenGL_GL_POLICY_WARN) 327 328 # FPHSA cannot handle "this OR that is required", so we conditionally set what 329 # it must look for. First clear any previous config we might have done: 330 set(_OpenGL_REQUIRED_VARS) 331 332 # now we append the libraries as appropriate. The complicated logic 333 # basically comes down to "use libOpenGL when we can, and add in specific 334 # context mechanisms when requested, or we need them to preserve the previous 335 # default where glx is always available." 336 if((NOT OPENGL_USE_EGL AND 337 NOT OPENGL_opengl_LIBRARY AND 338 OPENGL_glx_LIBRARY AND 339 NOT OPENGL_gl_LIBRARY) OR 340 (NOT OPENGL_USE_EGL AND 341 NOT OPENGL_glx_LIBRARY AND 342 NOT OPENGL_gl_LIBRARY) OR 343 (NOT OPENGL_USE_EGL AND 344 OPENGL_opengl_LIBRARY AND 345 OPENGL_glx_LIBRARY) OR 346 ( OPENGL_USE_EGL)) 347 list(APPEND _OpenGL_REQUIRED_VARS OPENGL_opengl_LIBRARY) 348 endif() 349 350 # GLVND GLX library. Preferred when available. 351 if((NOT OPENGL_USE_OPENGL AND 352 NOT OPENGL_USE_GLX AND 353 NOT OPENGL_USE_EGL AND 354 NOT OPENGL_glx_LIBRARY AND 355 NOT OPENGL_gl_LIBRARY) OR 356 ( OPENGL_USE_GLX AND 357 NOT OPENGL_USE_EGL AND 358 NOT OPENGL_glx_LIBRARY AND 359 NOT OPENGL_gl_LIBRARY) OR 360 (NOT OPENGL_USE_EGL AND 361 OPENGL_opengl_LIBRARY AND 362 OPENGL_glx_LIBRARY) OR 363 (OPENGL_USE_GLX AND OPENGL_USE_EGL)) 364 list(APPEND _OpenGL_REQUIRED_VARS OPENGL_glx_LIBRARY) 365 endif() 366 367 # GLVND EGL library. 368 if(OPENGL_USE_EGL) 369 list(APPEND _OpenGL_REQUIRED_VARS OPENGL_egl_LIBRARY) 370 endif() 371 372 # Old-style "libGL" library: used as a fallback when GLVND isn't available. 373 if((NOT OPENGL_USE_EGL AND 374 NOT OPENGL_opengl_LIBRARY AND 375 OPENGL_glx_LIBRARY AND 376 OPENGL_gl_LIBRARY) OR 377 (NOT OPENGL_USE_EGL AND 378 NOT OPENGL_glx_LIBRARY AND 379 OPENGL_gl_LIBRARY)) 380 list(APPEND _OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY) 381 endif() 382 383 # We always need the 'gl.h' include dir. 384 list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR) 385 386 unset(_OPENGL_INCLUDE_PATH) 387 unset(_OPENGL_LIB_PATH) 388 389 find_library(OPENGL_glu_LIBRARY 390 NAMES GLU MesaGLU 391 PATHS ${OPENGL_gl_LIBRARY} 392 /opt/graphics/OpenGL/lib 393 /usr/openwin/lib 394 /usr/shlib 395 ) 396endif () 397 398if(OPENGL_xmesa_INCLUDE_DIR) 399 set( OPENGL_XMESA_FOUND "YES" ) 400else() 401 set( OPENGL_XMESA_FOUND "NO" ) 402endif() 403 404if(OPENGL_glu_LIBRARY) 405 set( OPENGL_GLU_FOUND "YES" ) 406else() 407 set( OPENGL_GLU_FOUND "NO" ) 408endif() 409 410# OpenGL_OpenGL_FOUND is a bit unique in that it is okay if /either/ libOpenGL 411# or libGL is found. 412# Using libGL with libEGL is never okay, though; we handle that case later. 413if(NOT OPENGL_opengl_LIBRARY AND NOT OPENGL_gl_LIBRARY) 414 set(OpenGL_OpenGL_FOUND FALSE) 415else() 416 set(OpenGL_OpenGL_FOUND TRUE) 417endif() 418 419if(OPENGL_glx_LIBRARY AND OPENGL_GLX_INCLUDE_DIR) 420 set(OpenGL_GLX_FOUND TRUE) 421else() 422 set(OpenGL_GLX_FOUND FALSE) 423endif() 424 425if(OPENGL_egl_LIBRARY AND OPENGL_EGL_INCLUDE_DIR) 426 set(OpenGL_EGL_FOUND TRUE) 427else() 428 set(OpenGL_EGL_FOUND FALSE) 429endif() 430 431# User-visible names should be plural. 432if(OPENGL_EGL_INCLUDE_DIR) 433 set(OPENGL_EGL_INCLUDE_DIRS ${OPENGL_EGL_INCLUDE_DIR}) 434endif() 435 436include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) 437if (CMAKE_FIND_PACKAGE_NAME STREQUAL "GLU") 438 # FindGLU include()'s this module. It's an old pattern, but rather than 439 # trying to suppress this from outside the module (which is then sensitive to 440 # the contents, detect the case in this module and suppress it explicitly. 441 set(FPHSA_NAME_MISMATCHED 1) 442endif () 443FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS} 444 HANDLE_COMPONENTS) 445unset(FPHSA_NAME_MISMATCHED) 446unset(_OpenGL_REQUIRED_VARS) 447 448# OpenGL:: targets 449if(OPENGL_FOUND) 450 # ::OpenGL is a GLVND library, and thus Linux-only: we don't bother checking 451 # for a framework version of this library. 452 if(OPENGL_opengl_LIBRARY AND NOT TARGET OpenGL::OpenGL) 453 if(IS_ABSOLUTE "${OPENGL_opengl_LIBRARY}") 454 add_library(OpenGL::OpenGL UNKNOWN IMPORTED) 455 set_target_properties(OpenGL::OpenGL PROPERTIES IMPORTED_LOCATION 456 "${OPENGL_opengl_LIBRARY}") 457 else() 458 add_library(OpenGL::OpenGL INTERFACE IMPORTED) 459 set_target_properties(OpenGL::OpenGL PROPERTIES IMPORTED_LIBNAME 460 "${OPENGL_opengl_LIBRARY}") 461 endif() 462 set_target_properties(OpenGL::OpenGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES 463 "${OPENGL_INCLUDE_DIR}") 464 endif() 465 466 # ::GLX is a GLVND library, and thus Linux-only: we don't bother checking 467 # for a framework version of this library. 468 if(OpenGL_GLX_FOUND AND NOT TARGET OpenGL::GLX AND TARGET OpenGL::OpenGL) 469 if(IS_ABSOLUTE "${OPENGL_glx_LIBRARY}") 470 add_library(OpenGL::GLX UNKNOWN IMPORTED) 471 set_target_properties(OpenGL::GLX PROPERTIES IMPORTED_LOCATION 472 "${OPENGL_glx_LIBRARY}") 473 else() 474 add_library(OpenGL::GLX INTERFACE IMPORTED) 475 set_target_properties(OpenGL::GLX PROPERTIES IMPORTED_LIBNAME 476 "${OPENGL_glx_LIBRARY}") 477 endif() 478 set_target_properties(OpenGL::GLX PROPERTIES INTERFACE_LINK_LIBRARIES 479 OpenGL::OpenGL) 480 set_target_properties(OpenGL::GLX PROPERTIES INTERFACE_INCLUDE_DIRECTORIES 481 "${OPENGL_GLX_INCLUDE_DIR}") 482 endif() 483 484 if(OPENGL_gl_LIBRARY AND NOT TARGET OpenGL::GL) 485 # A legacy GL library is available, so use it for the legacy GL target. 486 if(IS_ABSOLUTE "${OPENGL_gl_LIBRARY}") 487 add_library(OpenGL::GL UNKNOWN IMPORTED) 488 if(OPENGL_gl_LIBRARY MATCHES "/([^/]+)\\.framework$") 489 set(_gl_fw "${OPENGL_gl_LIBRARY}/${CMAKE_MATCH_1}") 490 if(EXISTS "${_gl_fw}.tbd") 491 string(APPEND _gl_fw ".tbd") 492 endif() 493 set_target_properties(OpenGL::GL PROPERTIES 494 IMPORTED_LOCATION "${_gl_fw}") 495 else() 496 set_target_properties(OpenGL::GL PROPERTIES 497 IMPORTED_LOCATION "${OPENGL_gl_LIBRARY}") 498 endif() 499 else() 500 add_library(OpenGL::GL INTERFACE IMPORTED) 501 set_target_properties(OpenGL::GL PROPERTIES 502 IMPORTED_LIBNAME "${OPENGL_gl_LIBRARY}") 503 endif() 504 set_target_properties(OpenGL::GL PROPERTIES 505 INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}") 506 elseif(NOT TARGET OpenGL::GL AND TARGET OpenGL::OpenGL AND TARGET OpenGL::GLX) 507 # A legacy GL library is not available, but we can provide the legacy GL 508 # target using GLVND OpenGL+GLX. 509 add_library(OpenGL::GL INTERFACE IMPORTED) 510 set_target_properties(OpenGL::GL PROPERTIES INTERFACE_LINK_LIBRARIES 511 OpenGL::OpenGL) 512 set_property(TARGET OpenGL::GL APPEND PROPERTY INTERFACE_LINK_LIBRARIES 513 OpenGL::GLX) 514 set_target_properties(OpenGL::GL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES 515 "${OPENGL_INCLUDE_DIR}") 516 endif() 517 518 # ::EGL is a GLVND library, and thus Linux-only: we don't bother checking 519 # for a framework version of this library. 520 # Note we test for OpenGL::OpenGL as a target. When this module is updated to 521 # support GLES, we would additionally want to check for the hypothetical GLES 522 # target and enable EGL if either ::GLES or ::OpenGL is created. 523 if(TARGET OpenGL::OpenGL AND OpenGL_EGL_FOUND AND NOT TARGET OpenGL::EGL) 524 if(IS_ABSOLUTE "${OPENGL_egl_LIBRARY}") 525 add_library(OpenGL::EGL UNKNOWN IMPORTED) 526 set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LOCATION 527 "${OPENGL_egl_LIBRARY}") 528 else() 529 add_library(OpenGL::EGL INTERFACE IMPORTED) 530 set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LIBNAME 531 "${OPENGL_egl_LIBRARY}") 532 endif() 533 set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_LINK_LIBRARIES 534 OpenGL::OpenGL) 535 # Note that EGL's include directory is different from OpenGL/GLX's! 536 set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES 537 "${OPENGL_EGL_INCLUDE_DIR}") 538 endif() 539 540 if(OPENGL_GLU_FOUND AND NOT TARGET OpenGL::GLU) 541 if(IS_ABSOLUTE "${OPENGL_glu_LIBRARY}") 542 add_library(OpenGL::GLU UNKNOWN IMPORTED) 543 if(OPENGL_glu_LIBRARY MATCHES "/([^/]+)\\.framework$") 544 set(_glu_fw "${OPENGL_glu_LIBRARY}/${CMAKE_MATCH_1}") 545 if(EXISTS "${_glu_fw}.tbd") 546 string(APPEND _glu_fw ".tbd") 547 endif() 548 set_target_properties(OpenGL::GLU PROPERTIES 549 IMPORTED_LOCATION "${_glu_fw}") 550 else() 551 set_target_properties(OpenGL::GLU PROPERTIES 552 IMPORTED_LOCATION "${OPENGL_glu_LIBRARY}") 553 endif() 554 else() 555 add_library(OpenGL::GLU INTERFACE IMPORTED) 556 set_target_properties(OpenGL::GLU PROPERTIES 557 IMPORTED_LIBNAME "${OPENGL_glu_LIBRARY}") 558 endif() 559 set_target_properties(OpenGL::GLU PROPERTIES 560 INTERFACE_LINK_LIBRARIES OpenGL::GL) 561 endif() 562 563 # OPENGL_LIBRARIES mirrors OpenGL::GL's logic ... 564 if(OPENGL_gl_LIBRARY) 565 set(OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY}) 566 elseif(TARGET OpenGL::OpenGL AND TARGET OpenGL::GLX) 567 set(OPENGL_LIBRARIES ${OPENGL_opengl_LIBRARY} ${OPENGL_glx_LIBRARY}) 568 else() 569 set(OPENGL_LIBRARIES "") 570 endif() 571 # ... and also includes GLU, if available. 572 if(TARGET OpenGL::GLU) 573 list(APPEND OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY}) 574 endif() 575endif() 576 577# This deprecated setting is for backward compatibility with CMake1.4 578set(OPENGL_LIBRARY ${OPENGL_LIBRARIES}) 579# This deprecated setting is for backward compatibility with CMake1.4 580set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR}) 581 582mark_as_advanced(${_OpenGL_CACHE_VARS}) 583unset(_OpenGL_CACHE_VARS) 584