FindOpenGL.cmake 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 - Pat to GLU Librar
  14. #
  15. IF (WIN32)
  16. IF (CYGWIN)
  17. FIND_PATH(OPENGL_INCLUDE_DIR GL/gl.h
  18. /usr/include
  19. /usr/X11R6/include
  20. )
  21. FIND_LIBRARY(OPENGL_gl_LIBRARY opengl32
  22. /usr/lib
  23. /usr/lib/w32api
  24. )
  25. FIND_LIBRARY(OPENGL_glu_LIBRARY glu32
  26. /usr/lib
  27. /usr/lib/w32api
  28. )
  29. ELSE (CYGWIN)
  30. IF(BORLAND)
  31. SET (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
  32. SET (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32")
  33. ELSE(BORLAND)
  34. SET (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32")
  35. SET (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32")
  36. ENDIF(BORLAND)
  37. # No extra include path needed because OpenGL includes are with
  38. # the system includes but, cmake will create makefiles with
  39. # "-I${OPENGL_INCLUDE_DIR}" options if OPENGL_INCLUDE_DIR is
  40. # not set. OPENGL_INCLUDE_DIR cannot be set to "" because the
  41. # resulting -I option to "cl" will eat the following
  42. # "-IC:\really\needed" option. This is a kludge to get around
  43. # cmake not ignoring INCLUDE_DIRECTORIES commands with empty
  44. # strings.
  45. SET( OPENGL_INCLUDE_DIR "${PROJECT_SOURCE_DIR}" )
  46. ENDIF (CYGWIN)
  47. ELSE (WIN32)
  48. # The first line below is to make sure that the proper headers
  49. # are used on a Linux machine with the NVidia drivers installed.
  50. # They replace Mesa with NVidia's own library but normally do not
  51. # install headers and that causes the linking to
  52. # fail since the compiler finds the Mesa headers but NVidia's library.
  53. # Make sure the NVIDIA directory comes BEFORE the others.
  54. # - Atanas Georgiev <[email protected]>
  55. FIND_PATH(OPENGL_INCLUDE_DIR GL/gl.h
  56. /usr/share/doc/NVIDIA_GLX-1.0/include
  57. /usr/include
  58. /usr/local/include
  59. /usr/openwin/share/include
  60. /opt/graphics/OpenGL/include
  61. /usr/X11R6/include
  62. )
  63. FIND_PATH(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
  64. /usr/share/doc/NVIDIA_GLX-1.0/include
  65. /usr/include
  66. /usr/local/include
  67. /usr/openwin/share/include
  68. /opt/graphics/OpenGL/include
  69. /usr/X11R6/include
  70. )
  71. FIND_LIBRARY(OPENGL_gl_LIBRARY
  72. NAMES MesaGL GL
  73. PATHS /usr/lib
  74. /usr/local/lib
  75. /opt/graphics/OpenGL/lib
  76. /usr/openwin/lib
  77. /usr/X11R6/lib
  78. )
  79. # On Unix OpenGL most certainly always requires X11.
  80. # Feel free to tighten up these conditions if you don't 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 /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_INCLUDE_DIR)
  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. #The following deprecated settings are for backwards compatibility with CMake1.4
  113. SET (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
  114. SET (OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
  115. ENDIF(OPENGL_gl_LIBRARY)
  116. SET(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
  117. ENDIF(OPENGL_INCLUDE_DIR)
  118. # On OSX, OpenGL is always there - this will need refining for those using OpenGL with X11
  119. IF (APPLE)
  120. SET (OPENGL_FOUND "YES")
  121. SET (OPENGL_GLU_FOUND "YES")
  122. SET (OPENGL_LIBRARIES "-framework AGL -framework OpenGL" CACHE STRING "OpenGL lib for OSX")
  123. SET (OPENGL_LIBRARY ${OPENGL_LIBRARIES} CACHE STRING "OpenGL lib for OSX (for CMake 1.4)")
  124. SET (OPENGL_gl_LIBRARY "-framework OpenGL" CACHE STRING "OpenGL lib for OSX")
  125. SET (OPENGL_glu_LIBRARY "-framework AGL" CACHE STRING "AGL lib for OSX")
  126. ENDIF (APPLE)
  127. MARK_AS_ADVANCED(
  128. OPENGL_INCLUDE_DIR
  129. OPENGL_xmesa_INCLUDE_DIR
  130. OPENGL_glu_LIBRARY
  131. OPENGL_gl_LIBRARY
  132. )