FindOpenGL.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. IF (WIN32)
  18. IF (CYGWIN)
  19. FIND_PATH(OPENGL_INCLUDE_DIR GL/gl.h )
  20. FIND_LIBRARY(OPENGL_gl_LIBRARY opengl32 )
  21. FIND_LIBRARY(OPENGL_glu_LIBRARY glu32 )
  22. ELSE (CYGWIN)
  23. IF(BORLAND)
  24. SET (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
  25. SET (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32")
  26. ELSE(BORLAND)
  27. SET (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32")
  28. SET (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32")
  29. ENDIF(BORLAND)
  30. ENDIF (CYGWIN)
  31. ELSE (WIN32)
  32. IF (APPLE)
  33. FIND_LIBRARY(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL lib for OSX")
  34. FIND_LIBRARY(OPENGL_glu_LIBRARY AGL DOC "AGL lib for OSX")
  35. FIND_PATH(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OSX")
  36. ELSE(APPLE)
  37. # The first line below is to make sure that the proper headers
  38. # are used on a Linux machine with the NVidia drivers installed.
  39. # They replace Mesa with NVidia's own library but normally do not
  40. # install headers and that causes the linking to
  41. # fail since the compiler finds the Mesa headers but NVidia's library.
  42. # Make sure the NVIDIA directory comes BEFORE the others.
  43. # - Atanas Georgiev <[email protected]>
  44. FIND_PATH(OPENGL_INCLUDE_DIR GL/gl.h
  45. /usr/share/doc/NVIDIA_GLX-1.0/include
  46. /usr/openwin/share/include
  47. /opt/graphics/OpenGL/include
  48. )
  49. FIND_PATH(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
  50. /usr/share/doc/NVIDIA_GLX-1.0/include
  51. /usr/openwin/share/include
  52. /opt/graphics/OpenGL/include
  53. )
  54. FIND_LIBRARY(OPENGL_gl_LIBRARY
  55. NAMES GL MesaGL
  56. PATHS /opt/graphics/OpenGL/lib
  57. /usr/openwin/lib
  58. /usr/shlib
  59. )
  60. # On Unix OpenGL most certainly always requires X11.
  61. # Feel free to tighten up these conditions if you don't
  62. # think this is always true.
  63. # It's not true on OSX.
  64. IF (OPENGL_gl_LIBRARY)
  65. IF(NOT X11_FOUND)
  66. INCLUDE(FindX11)
  67. ENDIF(NOT X11_FOUND)
  68. IF (X11_FOUND)
  69. IF (NOT APPLE)
  70. SET (OPENGL_LIBRARIES ${X11_LIBRARIES})
  71. ENDIF (NOT APPLE)
  72. ENDIF (X11_FOUND)
  73. ENDIF (OPENGL_gl_LIBRARY)
  74. FIND_LIBRARY(OPENGL_glu_LIBRARY
  75. NAMES GLU MesaGLU
  76. PATHS ${OPENGL_gl_LIBRARY}
  77. /opt/graphics/OpenGL/lib
  78. /usr/openwin/lib
  79. /usr/shlib
  80. )
  81. ENDIF(APPLE)
  82. ENDIF (WIN32)
  83. SET( OPENGL_FOUND "NO" )
  84. IF(OPENGL_gl_LIBRARY)
  85. IF(OPENGL_xmesa_INCLUDE_DIR)
  86. SET( OPENGL_XMESA_FOUND "YES" )
  87. ELSE(OPENGL_xmesa_INCLUDE_DIR)
  88. SET( OPENGL_XMESA_FOUND "NO" )
  89. ENDIF(OPENGL_xmesa_INCLUDE_DIR)
  90. SET( OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES})
  91. IF(OPENGL_glu_LIBRARY)
  92. SET( OPENGL_GLU_FOUND "YES" )
  93. SET( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
  94. ELSE(OPENGL_glu_LIBRARY)
  95. SET( OPENGL_GLU_FOUND "NO" )
  96. ENDIF(OPENGL_glu_LIBRARY)
  97. SET( OPENGL_FOUND "YES" )
  98. # This deprecated setting is for backward compatibility with CMake1.4
  99. SET (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
  100. ENDIF(OPENGL_gl_LIBRARY)
  101. # This deprecated setting is for backward compatibility with CMake1.4
  102. SET(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
  103. MARK_AS_ADVANCED(
  104. OPENGL_INCLUDE_DIR
  105. OPENGL_xmesa_INCLUDE_DIR
  106. OPENGL_glu_LIBRARY
  107. OPENGL_gl_LIBRARY
  108. )