FindOpenGL.cmake 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # Try to find OpenGL
  2. # Once done this will define
  3. #
  4. # OPENGL_FOUND - system has OpenGL and it should be used
  5. # OPENGL_XMESA_FOUND - system has XMESA, and it should be used.
  6. # OPENGL_GLU_FOUND - system has GLU and it should be used.
  7. # OPENGL_INCLUDE_DIR - where the GL include directory can be found
  8. # OPENGL_LIBRARIES - Link these to use OpenGL
  9. #
  10. #
  11. # Also defined, but not for general use are
  12. # OPENGL_gl_LIBRARY - Path to OpenGL Library
  13. # OPENGL_glu_LIBRARY - Path to GLU Library
  14. #
  15. # On OSX default to using the framework version of opengl
  16. # People will have to change the cache values of OPENGL_glu_LIBRARY
  17. # and OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX
  18. IF (APPLE)
  19. SET (OPENGL_gl_LIBRARY "-framework OpenGL" CACHE STRING "OpenGL lib for OSX")
  20. SET (OPENGL_glu_LIBRARY "-framework AGL" CACHE STRING "AGL lib for OSX")
  21. ENDIF (APPLE)
  22. IF (WIN32)
  23. IF (CYGWIN)
  24. FIND_PATH(OPENGL_INCLUDE_DIR GL/gl.h
  25. /usr/include
  26. /usr/X11R6/include
  27. )
  28. FIND_LIBRARY(OPENGL_gl_LIBRARY opengl32
  29. /usr/lib
  30. /usr/lib/w32api
  31. )
  32. FIND_LIBRARY(OPENGL_glu_LIBRARY glu32
  33. /usr/lib
  34. /usr/lib/w32api
  35. )
  36. ELSE (CYGWIN)
  37. IF(BORLAND)
  38. SET (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
  39. SET (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32")
  40. ELSE(BORLAND)
  41. SET (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32")
  42. SET (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32")
  43. ENDIF(BORLAND)
  44. ENDIF (CYGWIN)
  45. ELSE (WIN32)
  46. # The first line below is to make sure that the proper headers
  47. # are used on a Linux machine with the NVidia drivers installed.
  48. # They replace Mesa with NVidia's own library but normally do not
  49. # install headers and that causes the linking to
  50. # fail since the compiler finds the Mesa headers but NVidia's library.
  51. # Make sure the NVIDIA directory comes BEFORE the others.
  52. # - Atanas Georgiev <[email protected]>
  53. FIND_PATH(OPENGL_INCLUDE_DIR GL/gl.h
  54. /usr/share/doc/NVIDIA_GLX-1.0/include
  55. /usr/include
  56. /usr/local/include
  57. /usr/openwin/share/include
  58. /opt/graphics/OpenGL/include
  59. /usr/X11R6/include
  60. )
  61. FIND_PATH(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
  62. /usr/share/doc/NVIDIA_GLX-1.0/include
  63. /usr/include
  64. /usr/local/include
  65. /usr/openwin/share/include
  66. /opt/graphics/OpenGL/include
  67. /usr/X11R6/include
  68. )
  69. FIND_LIBRARY(OPENGL_gl_LIBRARY
  70. NAMES MesaGL GL
  71. PATHS /usr/lib
  72. /usr/local/lib
  73. /opt/graphics/OpenGL/lib
  74. /usr/openwin/lib
  75. /usr/X11R6/lib
  76. )
  77. # On Unix OpenGL most certainly always requires X11.
  78. # Feel free to tighten up these conditions if you don't
  79. # think this is always true.
  80. IF (OPENGL_gl_LIBRARY)
  81. INCLUDE( ${CMAKE_ROOT}/Modules/FindX11.cmake )
  82. IF (X11_FOUND)
  83. SET (OPENGL_LIBRARIES ${X11_LIBRARIES})
  84. ENDIF (X11_FOUND)
  85. ENDIF (OPENGL_gl_LIBRARY)
  86. FIND_LIBRARY(OPENGL_glu_LIBRARY
  87. NAMES MesaGLU GLU
  88. PATHS ${OPENGL_gl_LIBRARY}
  89. /usr/lib
  90. /usr/local/lib
  91. /opt/graphics/OpenGL/lib
  92. /usr/openwin/lib
  93. /usr/X11R6/lib
  94. )
  95. ENDIF (WIN32)
  96. SET( OPENGL_FOUND "NO" )
  97. IF(OPENGL_gl_LIBRARY)
  98. IF(OPENGL_xmesa_INCLUDE_DIR)
  99. SET( OPENGL_XMESA_FOUND "YES" )
  100. ELSE(OPENGL_xmesa_INCLUDE_DIR)
  101. SET( OPENGL_XMESA_FOUND "NO" )
  102. ENDIF(OPENGL_xmesa_INCLUDE_DIR)
  103. SET( OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES})
  104. IF(OPENGL_glu_LIBRARY)
  105. SET( OPENGL_GLU_FOUND "YES" )
  106. SET( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
  107. ELSE(OPENGL_glu_LIBRARY)
  108. SET( OPENGL_GLU_FOUND "NO" )
  109. ENDIF(OPENGL_glu_LIBRARY)
  110. SET( OPENGL_FOUND "YES" )
  111. # This deprecated setting is for backward compatibility with CMake1.4
  112. SET (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
  113. ENDIF(OPENGL_gl_LIBRARY)
  114. # This deprecated setting is for backward compatibility with CMake1.4
  115. SET(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
  116. MARK_AS_ADVANCED(
  117. OPENGL_INCLUDE_DIR
  118. OPENGL_xmesa_INCLUDE_DIR
  119. OPENGL_glu_LIBRARY
  120. OPENGL_gl_LIBRARY
  121. )