FindOpenGL.cmake 5.2 KB

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