FindOpenGL.cmake 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. # Result Variables
  10. # ^^^^^^^^^^^^^^^^
  11. #
  12. # This module sets the following variables:
  13. #
  14. # ``OPENGL_FOUND``
  15. # True, if the system has OpenGL.
  16. # ``OPENGL_XMESA_FOUND``
  17. # True, if the system has XMESA.
  18. # ``OPENGL_GLU_FOUND``
  19. # True, if the system has GLU.
  20. # ``OPENGL_INCLUDE_DIR``
  21. # Path to the OpenGL include directory.
  22. # ``OPENGL_LIBRARIES``
  23. # Paths to the OpenGL and GLU libraries.
  24. #
  25. # If you want to use just GL you can use these values:
  26. #
  27. # ``OPENGL_gl_LIBRARY``
  28. # Path to the OpenGL library.
  29. # ``OPENGL_glu_LIBRARY``
  30. # Path to the GLU library.
  31. #
  32. # OSX Specific
  33. # ^^^^^^^^^^^^
  34. #
  35. # On OSX default to using the framework version of OpenGL. People will
  36. # have to change the cache values of OPENGL_glu_LIBRARY and
  37. # OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX.
  38. set(_OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY)
  39. if (CYGWIN)
  40. find_path(OPENGL_INCLUDE_DIR GL/gl.h )
  41. list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
  42. find_library(OPENGL_gl_LIBRARY opengl32 )
  43. find_library(OPENGL_glu_LIBRARY glu32 )
  44. elseif (WIN32)
  45. if(BORLAND)
  46. set (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
  47. set (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32")
  48. else()
  49. set (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32")
  50. set (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32")
  51. endif()
  52. elseif (APPLE)
  53. # The OpenGL.framework provides both gl and glu
  54. find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL library for OS X")
  55. find_library(OPENGL_glu_LIBRARY OpenGL DOC
  56. "GLU library for OS X (usually same as OpenGL library)")
  57. find_path(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OS X")
  58. list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
  59. else()
  60. if (CMAKE_SYSTEM_NAME MATCHES "HP-UX")
  61. # Handle HP-UX cases where we only want to find OpenGL in either hpux64
  62. # or hpux32 depending on if we're doing a 64 bit build.
  63. if(CMAKE_SIZEOF_VOID_P EQUAL 4)
  64. set(_OPENGL_LIB_PATH
  65. /opt/graphics/OpenGL/lib/hpux32/)
  66. else()
  67. set(_OPENGL_LIB_PATH
  68. /opt/graphics/OpenGL/lib/hpux64/
  69. /opt/graphics/OpenGL/lib/pa20_64)
  70. endif()
  71. elseif(CMAKE_SYSTEM_NAME STREQUAL Haiku)
  72. set(_OPENGL_LIB_PATH
  73. /boot/develop/lib/x86)
  74. set(_OPENGL_INCLUDE_PATH
  75. /boot/develop/headers/os/opengl)
  76. endif()
  77. # The first line below is to make sure that the proper headers
  78. # are used on a Linux machine with the NVidia drivers installed.
  79. # They replace Mesa with NVidia's own library but normally do not
  80. # install headers and that causes the linking to
  81. # fail since the compiler finds the Mesa headers but NVidia's library.
  82. # Make sure the NVIDIA directory comes BEFORE the others.
  83. # - Atanas Georgiev <[email protected]>
  84. find_path(OPENGL_INCLUDE_DIR GL/gl.h
  85. /usr/share/doc/NVIDIA_GLX-1.0/include
  86. /usr/openwin/share/include
  87. /opt/graphics/OpenGL/include /usr/X11R6/include
  88. ${_OPENGL_INCLUDE_PATH}
  89. )
  90. list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
  91. find_path(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
  92. /usr/share/doc/NVIDIA_GLX-1.0/include
  93. /usr/openwin/share/include
  94. /opt/graphics/OpenGL/include /usr/X11R6/include
  95. )
  96. find_library(OPENGL_gl_LIBRARY
  97. NAMES GL MesaGL
  98. PATHS /opt/graphics/OpenGL/lib
  99. /usr/openwin/lib
  100. /usr/shlib /usr/X11R6/lib
  101. ${_OPENGL_LIB_PATH}
  102. )
  103. unset(_OPENGL_INCLUDE_PATH)
  104. unset(_OPENGL_LIB_PATH)
  105. find_library(OPENGL_glu_LIBRARY
  106. NAMES GLU MesaGLU
  107. PATHS ${OPENGL_gl_LIBRARY}
  108. /opt/graphics/OpenGL/lib
  109. /usr/openwin/lib
  110. /usr/shlib /usr/X11R6/lib
  111. )
  112. endif ()
  113. if(OPENGL_gl_LIBRARY)
  114. if(OPENGL_xmesa_INCLUDE_DIR)
  115. set( OPENGL_XMESA_FOUND "YES" )
  116. else()
  117. set( OPENGL_XMESA_FOUND "NO" )
  118. endif()
  119. set( OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES})
  120. if(OPENGL_glu_LIBRARY)
  121. set( OPENGL_GLU_FOUND "YES" )
  122. if(NOT "${OPENGL_glu_LIBRARY}" STREQUAL "${OPENGL_gl_LIBRARY}")
  123. set( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
  124. endif()
  125. else()
  126. set( OPENGL_GLU_FOUND "NO" )
  127. endif()
  128. # This deprecated setting is for backward compatibility with CMake1.4
  129. set (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
  130. endif()
  131. # This deprecated setting is for backward compatibility with CMake1.4
  132. set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
  133. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  134. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS})
  135. unset(_OpenGL_REQUIRED_VARS)
  136. mark_as_advanced(
  137. OPENGL_INCLUDE_DIR
  138. OPENGL_xmesa_INCLUDE_DIR
  139. OPENGL_glu_LIBRARY
  140. OPENGL_gl_LIBRARY
  141. )