FindOpenGL.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # - Try to find OpenGL
  2. # Once done this will define
  3. #
  4. # OPENGL_FOUND - system has OpenGL
  5. # OPENGL_XMESA_FOUND - system has XMESA
  6. # OPENGL_GLU_FOUND - system has GLU
  7. # OPENGL_INCLUDE_DIR - the GL include directory
  8. # OPENGL_LIBRARIES - Link these to use OpenGL and GLU
  9. #
  10. # If you want to use just GL you can use these values
  11. # OPENGL_gl_LIBRARY - Path to OpenGL Library
  12. # OPENGL_glu_LIBRARY - Path to GLU Library
  13. #
  14. # On OSX default to using the framework version of opengl
  15. # People will have to change the cache values of OPENGL_glu_LIBRARY
  16. # and OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX
  17. #=============================================================================
  18. # Copyright 2001-2009 Kitware, Inc.
  19. #
  20. # Distributed under the OSI-approved BSD License (the "License");
  21. # see accompanying file Copyright.txt for details.
  22. #
  23. # This software is distributed WITHOUT ANY WARRANTY; without even the
  24. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  25. # See the License for more information.
  26. #=============================================================================
  27. # (To distributed this file outside of CMake, substitute the full
  28. # License text for the above reference.)
  29. IF (WIN32)
  30. IF (CYGWIN)
  31. FIND_PATH(OPENGL_INCLUDE_DIR GL/gl.h )
  32. FIND_LIBRARY(OPENGL_gl_LIBRARY opengl32 )
  33. FIND_LIBRARY(OPENGL_glu_LIBRARY glu32 )
  34. ELSE (CYGWIN)
  35. IF(BORLAND)
  36. SET (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
  37. SET (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32")
  38. ELSE(BORLAND)
  39. SET (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32")
  40. SET (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32")
  41. ENDIF(BORLAND)
  42. ENDIF (CYGWIN)
  43. ELSE (WIN32)
  44. IF (APPLE)
  45. FIND_LIBRARY(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL lib for OSX")
  46. FIND_LIBRARY(OPENGL_glu_LIBRARY AGL DOC "AGL lib for OSX")
  47. FIND_PATH(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OSX")
  48. ELSE(APPLE)
  49. # Handle HP-UX cases where we only want to find OpenGL in either hpux64
  50. # or hpux32 depending on if we're doing a 64 bit build.
  51. IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
  52. SET(HPUX_IA_OPENGL_LIB_PATH /opt/graphics/OpenGL/lib/hpux32/)
  53. ELSE(CMAKE_SIZEOF_VOID_P EQUAL 4)
  54. SET(HPUX_IA_OPENGL_LIB_PATH
  55. /opt/graphics/OpenGL/lib/hpux64/
  56. /opt/graphics/OpenGL/lib/pa20_64)
  57. ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4)
  58. # The first line below is to make sure that the proper headers
  59. # are used on a Linux machine with the NVidia drivers installed.
  60. # They replace Mesa with NVidia's own library but normally do not
  61. # install headers and that causes the linking to
  62. # fail since the compiler finds the Mesa headers but NVidia's library.
  63. # Make sure the NVIDIA directory comes BEFORE the others.
  64. # - Atanas Georgiev <[email protected]>
  65. FIND_PATH(OPENGL_INCLUDE_DIR GL/gl.h
  66. /usr/share/doc/NVIDIA_GLX-1.0/include
  67. /usr/openwin/share/include
  68. /opt/graphics/OpenGL/include /usr/X11R6/include
  69. )
  70. FIND_PATH(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
  71. /usr/share/doc/NVIDIA_GLX-1.0/include
  72. /usr/openwin/share/include
  73. /opt/graphics/OpenGL/include /usr/X11R6/include
  74. )
  75. FIND_LIBRARY(OPENGL_gl_LIBRARY
  76. NAMES GL MesaGL
  77. PATHS /opt/graphics/OpenGL/lib
  78. /usr/openwin/lib
  79. /usr/shlib /usr/X11R6/lib
  80. ${HPUX_IA_OPENGL_LIB_PATH}
  81. )
  82. # On Unix OpenGL most certainly always requires X11.
  83. # Feel free to tighten up these conditions if you don't
  84. # think this is always true.
  85. # It's not true on OSX.
  86. IF (OPENGL_gl_LIBRARY)
  87. IF(NOT X11_FOUND)
  88. INCLUDE(FindX11)
  89. ENDIF(NOT X11_FOUND)
  90. IF (X11_FOUND)
  91. IF (NOT APPLE)
  92. SET (OPENGL_LIBRARIES ${X11_LIBRARIES})
  93. ENDIF (NOT APPLE)
  94. ENDIF (X11_FOUND)
  95. ENDIF (OPENGL_gl_LIBRARY)
  96. FIND_LIBRARY(OPENGL_glu_LIBRARY
  97. NAMES GLU MesaGLU
  98. PATHS ${OPENGL_gl_LIBRARY}
  99. /opt/graphics/OpenGL/lib
  100. /usr/openwin/lib
  101. /usr/shlib /usr/X11R6/lib
  102. )
  103. ENDIF(APPLE)
  104. ENDIF (WIN32)
  105. SET( OPENGL_FOUND "NO" )
  106. IF(OPENGL_gl_LIBRARY)
  107. IF(OPENGL_xmesa_INCLUDE_DIR)
  108. SET( OPENGL_XMESA_FOUND "YES" )
  109. ELSE(OPENGL_xmesa_INCLUDE_DIR)
  110. SET( OPENGL_XMESA_FOUND "NO" )
  111. ENDIF(OPENGL_xmesa_INCLUDE_DIR)
  112. SET( OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES})
  113. IF(OPENGL_glu_LIBRARY)
  114. SET( OPENGL_GLU_FOUND "YES" )
  115. SET( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
  116. ELSE(OPENGL_glu_LIBRARY)
  117. SET( OPENGL_GLU_FOUND "NO" )
  118. ENDIF(OPENGL_glu_LIBRARY)
  119. SET( OPENGL_FOUND "YES" )
  120. # This deprecated setting is for backward compatibility with CMake1.4
  121. SET (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
  122. ENDIF(OPENGL_gl_LIBRARY)
  123. # This deprecated setting is for backward compatibility with CMake1.4
  124. SET(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
  125. MARK_AS_ADVANCED(
  126. OPENGL_INCLUDE_DIR
  127. OPENGL_xmesa_INCLUDE_DIR
  128. OPENGL_glu_LIBRARY
  129. OPENGL_gl_LIBRARY
  130. )