FindOpenGL.cmake 4.2 KB

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