FindOpenGL.cmake 19 KB

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