FindOpenGL.cmake 18 KB

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