FindOpenGL.cmake 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #.rst:
  2. # FindOpenGL
  3. # ----------
  4. #
  5. # FindModule for OpenGL and GLU.
  6. #
  7. # IMPORTED Targets
  8. # ^^^^^^^^^^^^^^^^
  9. #
  10. # This module defines the :prop_tgt:`IMPORTED` targets:
  11. #
  12. # ``OpenGL::GL``
  13. # Defined if the system has OpenGL.
  14. # ``OpenGL::GLU``
  15. # Defined if the system has GLU.
  16. #
  17. # Result Variables
  18. # ^^^^^^^^^^^^^^^^
  19. #
  20. # This module sets the following variables:
  21. #
  22. # ``OPENGL_FOUND``
  23. # True, if the system has OpenGL.
  24. # ``OPENGL_XMESA_FOUND``
  25. # True, if the system has XMESA.
  26. # ``OPENGL_GLU_FOUND``
  27. # True, if the system has GLU.
  28. # ``OPENGL_INCLUDE_DIR``
  29. # Path to the OpenGL include directory.
  30. # ``OPENGL_LIBRARIES``
  31. # Paths to the OpenGL and GLU libraries.
  32. #
  33. # If you want to use just GL you can use these values:
  34. #
  35. # ``OPENGL_gl_LIBRARY``
  36. # Path to the OpenGL library.
  37. # ``OPENGL_glu_LIBRARY``
  38. # Path to the GLU library.
  39. #
  40. # OSX Specific
  41. # ^^^^^^^^^^^^
  42. #
  43. # On OSX default to using the framework version of OpenGL. People will
  44. # have to change the cache values of OPENGL_glu_LIBRARY and
  45. # OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX.
  46. #=============================================================================
  47. # Copyright 2001-2009 Kitware, Inc.
  48. #
  49. # Distributed under the OSI-approved BSD License (the "License");
  50. # see accompanying file Copyright.txt for details.
  51. #
  52. # This software is distributed WITHOUT ANY WARRANTY; without even the
  53. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  54. # See the License for more information.
  55. #=============================================================================
  56. # (To distribute this file outside of CMake, substitute the full
  57. # License text for the above reference.)
  58. set(_OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY)
  59. if (CYGWIN)
  60. find_path(OPENGL_INCLUDE_DIR GL/gl.h )
  61. list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
  62. find_library(OPENGL_gl_LIBRARY opengl32 )
  63. find_library(OPENGL_glu_LIBRARY glu32 )
  64. elseif (WIN32)
  65. if(BORLAND)
  66. set (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
  67. set (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32")
  68. else()
  69. set (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32")
  70. set (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32")
  71. endif()
  72. elseif (APPLE)
  73. find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL lib for OSX")
  74. find_library(OPENGL_glu_LIBRARY AGL DOC "AGL lib for OSX")
  75. find_path(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OSX")
  76. list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
  77. else()
  78. if (CMAKE_SYSTEM_NAME MATCHES "HP-UX")
  79. # Handle HP-UX cases where we only want to find OpenGL in either hpux64
  80. # or hpux32 depending on if we're doing a 64 bit build.
  81. if(CMAKE_SIZEOF_VOID_P EQUAL 4)
  82. set(_OPENGL_LIB_PATH
  83. /opt/graphics/OpenGL/lib/hpux32/)
  84. else()
  85. set(_OPENGL_LIB_PATH
  86. /opt/graphics/OpenGL/lib/hpux64/
  87. /opt/graphics/OpenGL/lib/pa20_64)
  88. endif()
  89. elseif(CMAKE_SYSTEM_NAME STREQUAL Haiku)
  90. set(_OPENGL_LIB_PATH
  91. /boot/develop/lib/x86)
  92. set(_OPENGL_INCLUDE_PATH
  93. /boot/develop/headers/os/opengl)
  94. endif()
  95. # The first line below is to make sure that the proper headers
  96. # are used on a Linux machine with the NVidia drivers installed.
  97. # They replace Mesa with NVidia's own library but normally do not
  98. # install headers and that causes the linking to
  99. # fail since the compiler finds the Mesa headers but NVidia's library.
  100. # Make sure the NVIDIA directory comes BEFORE the others.
  101. # - Atanas Georgiev <[email protected]>
  102. find_path(OPENGL_INCLUDE_DIR GL/gl.h
  103. /usr/share/doc/NVIDIA_GLX-1.0/include
  104. /usr/openwin/share/include
  105. /opt/graphics/OpenGL/include /usr/X11R6/include
  106. ${_OPENGL_INCLUDE_PATH}
  107. )
  108. list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
  109. find_path(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
  110. /usr/share/doc/NVIDIA_GLX-1.0/include
  111. /usr/openwin/share/include
  112. /opt/graphics/OpenGL/include /usr/X11R6/include
  113. )
  114. find_library(OPENGL_gl_LIBRARY
  115. NAMES GL MesaGL
  116. PATHS /opt/graphics/OpenGL/lib
  117. /usr/openwin/lib
  118. /usr/shlib /usr/X11R6/lib
  119. ${_OPENGL_LIB_PATH}
  120. )
  121. unset(_OPENGL_INCLUDE_PATH)
  122. unset(_OPENGL_LIB_PATH)
  123. find_library(OPENGL_glu_LIBRARY
  124. NAMES GLU MesaGLU
  125. PATHS ${OPENGL_gl_LIBRARY}
  126. /opt/graphics/OpenGL/lib
  127. /usr/openwin/lib
  128. /usr/shlib /usr/X11R6/lib
  129. )
  130. endif ()
  131. if(OPENGL_gl_LIBRARY)
  132. if(OPENGL_xmesa_INCLUDE_DIR)
  133. set( OPENGL_XMESA_FOUND "YES" )
  134. else()
  135. set( OPENGL_XMESA_FOUND "NO" )
  136. endif()
  137. set( OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES})
  138. if(OPENGL_glu_LIBRARY)
  139. set( OPENGL_GLU_FOUND "YES" )
  140. set( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
  141. else()
  142. set( OPENGL_GLU_FOUND "NO" )
  143. endif()
  144. # This deprecated setting is for backward compatibility with CMake1.4
  145. set (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
  146. endif()
  147. # This deprecated setting is for backward compatibility with CMake1.4
  148. set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
  149. # handle the QUIETLY and REQUIRED arguments and set OPENGL_FOUND to TRUE if
  150. # all listed variables are TRUE
  151. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  152. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS})
  153. unset(_OpenGL_REQUIRED_VARS)
  154. # OpenGL:: targets
  155. if(OPENGL_FOUND)
  156. if(NOT TARGET OpenGL::GL)
  157. add_library(OpenGL::GL UNKNOWN IMPORTED)
  158. set_target_properties(OpenGL::GL PROPERTIES
  159. INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}")
  160. if(OPENGL_gl_LIBRARY MATCHES "/([^/]+)\\.framework$")
  161. set_target_properties(OpenGL::GL PROPERTIES
  162. IMPORTED_LOCATION "${OPENGL_gl_LIBRARY}/${CMAKE_MATCH_1}")
  163. else()
  164. set_target_properties(OpenGL::GL PROPERTIES
  165. IMPORTED_LOCATION "${OPENGL_gl_LIBRARY}")
  166. endif()
  167. endif()
  168. if(OPENGL_GLU_FOUND AND NOT TARGET OpenGL::GLU)
  169. add_library(OpenGL::GLU UNKNOWN IMPORTED)
  170. set_target_properties(OpenGL::GLU PROPERTIES
  171. INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}"
  172. INTERFACE_LINK_LIBRARIES OpenGL::GL)
  173. if(OPENGL_glu_LIBRARY MATCHES "/([^/]+)\\.framework$")
  174. set_target_properties(OpenGL::GLU PROPERTIES
  175. IMPORTED_LOCATION "${OPENGL_glu_LIBRARY}/${CMAKE_MATCH_1}")
  176. else()
  177. set_target_properties(OpenGL::GLU PROPERTIES
  178. IMPORTED_LOCATION "${OPENGL_glu_LIBRARY}")
  179. endif()
  180. endif()
  181. endif()
  182. mark_as_advanced(
  183. OPENGL_INCLUDE_DIR
  184. OPENGL_xmesa_INCLUDE_DIR
  185. OPENGL_glu_LIBRARY
  186. OPENGL_gl_LIBRARY
  187. )