FindOpenGL.cmake 4.1 KB

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