FindOpenGL.cmake 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #=============================================================================
  18. # Copyright 2001-2009 Kitware, Inc.
  19. #
  20. # Distributed under the OSI-approved BSD License (the "License");
  21. # see accompanying file Copyright.txt for details.
  22. #
  23. # This software is distributed WITHOUT ANY WARRANTY; without even the
  24. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  25. # See the License for more information.
  26. #=============================================================================
  27. # (To distribute this file outside of CMake, substitute the full
  28. # License text for the above reference.)
  29. set(_OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY)
  30. if (CYGWIN)
  31. find_path(OPENGL_INCLUDE_DIR GL/gl.h )
  32. list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
  33. find_library(OPENGL_gl_LIBRARY opengl32 )
  34. find_library(OPENGL_glu_LIBRARY glu32 )
  35. elseif (WIN32)
  36. if(BORLAND)
  37. set (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
  38. set (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32")
  39. else()
  40. set (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32")
  41. set (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32")
  42. endif()
  43. elseif (APPLE)
  44. find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL lib for OSX")
  45. find_library(OPENGL_glu_LIBRARY AGL DOC "AGL lib for OSX")
  46. find_path(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OSX")
  47. list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
  48. else()
  49. if (CMAKE_SYSTEM_NAME MATCHES "HP-UX")
  50. # Handle HP-UX cases where we only want to find OpenGL in either hpux64
  51. # or hpux32 depending on if we're doing a 64 bit build.
  52. if(CMAKE_SIZEOF_VOID_P EQUAL 4)
  53. set(_OPENGL_LIB_PATH
  54. /opt/graphics/OpenGL/lib/hpux32/)
  55. else()
  56. set(_OPENGL_LIB_PATH
  57. /opt/graphics/OpenGL/lib/hpux64/
  58. /opt/graphics/OpenGL/lib/pa20_64)
  59. endif()
  60. elseif(CMAKE_SYSTEM_NAME STREQUAL Haiku)
  61. set(_OPENGL_LIB_PATH
  62. /boot/develop/lib/x86)
  63. set(_OPENGL_INCLUDE_PATH
  64. /boot/develop/headers/os/opengl)
  65. endif()
  66. # The first line below is to make sure that the proper headers
  67. # are used on a Linux machine with the NVidia drivers installed.
  68. # They replace Mesa with NVidia's own library but normally do not
  69. # install headers and that causes the linking to
  70. # fail since the compiler finds the Mesa headers but NVidia's library.
  71. # Make sure the NVIDIA directory comes BEFORE the others.
  72. # - Atanas Georgiev <[email protected]>
  73. find_path(OPENGL_INCLUDE_DIR GL/gl.h
  74. /usr/share/doc/NVIDIA_GLX-1.0/include
  75. /usr/openwin/share/include
  76. /opt/graphics/OpenGL/include /usr/X11R6/include
  77. ${_OPENGL_INCLUDE_PATH}
  78. )
  79. list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
  80. find_path(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
  81. /usr/share/doc/NVIDIA_GLX-1.0/include
  82. /usr/openwin/share/include
  83. /opt/graphics/OpenGL/include /usr/X11R6/include
  84. )
  85. find_library(OPENGL_gl_LIBRARY
  86. NAMES GL MesaGL
  87. PATHS /opt/graphics/OpenGL/lib
  88. /usr/openwin/lib
  89. /usr/shlib /usr/X11R6/lib
  90. ${_OPENGL_LIB_PATH}
  91. )
  92. unset(_OPENGL_INCLUDE_PATH)
  93. unset(_OPENGL_LIB_PATH)
  94. # On Unix OpenGL most certainly always requires X11.
  95. # Feel free to tighten up these conditions if you don't
  96. # think this is always true.
  97. if (OPENGL_gl_LIBRARY)
  98. if(NOT X11_FOUND)
  99. include(${CMAKE_CURRENT_LIST_DIR}/FindX11.cmake)
  100. endif()
  101. if (X11_FOUND)
  102. set (OPENGL_LIBRARIES ${X11_LIBRARIES})
  103. endif ()
  104. endif ()
  105. find_library(OPENGL_glu_LIBRARY
  106. NAMES GLU MesaGLU
  107. PATHS ${OPENGL_gl_LIBRARY}
  108. /opt/graphics/OpenGL/lib
  109. /usr/openwin/lib
  110. /usr/shlib /usr/X11R6/lib
  111. )
  112. endif ()
  113. if(OPENGL_gl_LIBRARY)
  114. if(OPENGL_xmesa_INCLUDE_DIR)
  115. set( OPENGL_XMESA_FOUND "YES" )
  116. else()
  117. set( OPENGL_XMESA_FOUND "NO" )
  118. endif()
  119. set( OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES})
  120. if(OPENGL_glu_LIBRARY)
  121. set( OPENGL_GLU_FOUND "YES" )
  122. set( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
  123. else()
  124. set( OPENGL_GLU_FOUND "NO" )
  125. endif()
  126. # This deprecated setting is for backward compatibility with CMake1.4
  127. set (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
  128. endif()
  129. # This deprecated setting is for backward compatibility with CMake1.4
  130. set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
  131. # handle the QUIETLY and REQUIRED arguments and set OPENGL_FOUND to TRUE if
  132. # all listed variables are TRUE
  133. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  134. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS})
  135. unset(_OpenGL_REQUIRED_VARS)
  136. mark_as_advanced(
  137. OPENGL_INCLUDE_DIR
  138. OPENGL_xmesa_INCLUDE_DIR
  139. OPENGL_glu_LIBRARY
  140. OPENGL_gl_LIBRARY
  141. )