FindOpenGL.cmake 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. # Handle HP-UX cases where we only want to find OpenGL in either hpux64
  38. # or hpux32 depending on if we're doing a 64 bit build.
  39. IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
  40. SET(HPUX_IA_OPENGL_LIB_PATH /opt/graphics/OpenGL/lib/hpux32/)
  41. ELSE(CMAKE_SIZEOF_VOID_P EQUAL 4)
  42. SET(HPUX_IA_OPENGL_LIB_PATH
  43. /opt/graphics/OpenGL/lib/hpux64/
  44. /opt/graphics/OpenGL/lib/pa20_64)
  45. ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4)
  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/openwin/share/include
  56. /opt/graphics/OpenGL/include /usr/X11R6/include
  57. )
  58. FIND_PATH(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
  59. /usr/share/doc/NVIDIA_GLX-1.0/include
  60. /usr/openwin/share/include
  61. /opt/graphics/OpenGL/include /usr/X11R6/include
  62. )
  63. FIND_LIBRARY(OPENGL_gl_LIBRARY
  64. NAMES GL MesaGL
  65. PATHS /opt/graphics/OpenGL/lib
  66. /usr/openwin/lib
  67. /usr/shlib /usr/X11R6/lib
  68. ${HPUX_IA_OPENGL_LIB_PATH}
  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. # It's not true on OSX.
  74. IF (OPENGL_gl_LIBRARY)
  75. IF(NOT X11_FOUND)
  76. INCLUDE(FindX11)
  77. ENDIF(NOT X11_FOUND)
  78. IF (X11_FOUND)
  79. IF (NOT APPLE)
  80. SET (OPENGL_LIBRARIES ${X11_LIBRARIES})
  81. ENDIF (NOT APPLE)
  82. ENDIF (X11_FOUND)
  83. ENDIF (OPENGL_gl_LIBRARY)
  84. FIND_LIBRARY(OPENGL_glu_LIBRARY
  85. NAMES GLU MesaGLU
  86. PATHS ${OPENGL_gl_LIBRARY}
  87. /opt/graphics/OpenGL/lib
  88. /usr/openwin/lib
  89. /usr/shlib /usr/X11R6/lib
  90. )
  91. ENDIF(APPLE)
  92. ENDIF (WIN32)
  93. SET( OPENGL_FOUND "NO" )
  94. IF(OPENGL_gl_LIBRARY)
  95. IF(OPENGL_xmesa_INCLUDE_DIR)
  96. SET( OPENGL_XMESA_FOUND "YES" )
  97. ELSE(OPENGL_xmesa_INCLUDE_DIR)
  98. SET( OPENGL_XMESA_FOUND "NO" )
  99. ENDIF(OPENGL_xmesa_INCLUDE_DIR)
  100. SET( OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES})
  101. IF(OPENGL_glu_LIBRARY)
  102. SET( OPENGL_GLU_FOUND "YES" )
  103. SET( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
  104. ELSE(OPENGL_glu_LIBRARY)
  105. SET( OPENGL_GLU_FOUND "NO" )
  106. ENDIF(OPENGL_glu_LIBRARY)
  107. SET( OPENGL_FOUND "YES" )
  108. # This deprecated setting is for backward compatibility with CMake1.4
  109. SET (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
  110. ENDIF(OPENGL_gl_LIBRARY)
  111. # This deprecated setting is for backward compatibility with CMake1.4
  112. SET(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
  113. MARK_AS_ADVANCED(
  114. OPENGL_INCLUDE_DIR
  115. OPENGL_xmesa_INCLUDE_DIR
  116. OPENGL_glu_LIBRARY
  117. OPENGL_gl_LIBRARY
  118. )