1
0

FindOpenGL.cmake 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. if (WIN32)
  30. if (CYGWIN)
  31. find_path(OPENGL_INCLUDE_DIR GL/gl.h )
  32. find_library(OPENGL_gl_LIBRARY opengl32 )
  33. find_library(OPENGL_glu_LIBRARY glu32 )
  34. else ()
  35. if(BORLAND)
  36. set (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
  37. set (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32")
  38. else()
  39. set (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32")
  40. set (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32")
  41. endif()
  42. endif ()
  43. else ()
  44. if (APPLE)
  45. find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL lib for OSX")
  46. find_library(OPENGL_glu_LIBRARY AGL DOC "AGL lib for OSX")
  47. find_path(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OSX")
  48. else()
  49. # Handle HP-UX cases where we only want to find OpenGL in either hpux64
  50. # or hpux32 depending on if we're doing a 64 bit build.
  51. if(CMAKE_SIZEOF_VOID_P EQUAL 4)
  52. set(HPUX_IA_OPENGL_LIB_PATH /opt/graphics/OpenGL/lib/hpux32/)
  53. else()
  54. set(HPUX_IA_OPENGL_LIB_PATH
  55. /opt/graphics/OpenGL/lib/hpux64/
  56. /opt/graphics/OpenGL/lib/pa20_64)
  57. endif()
  58. # The first line below is to make sure that the proper headers
  59. # are used on a Linux machine with the NVidia drivers installed.
  60. # They replace Mesa with NVidia's own library but normally do not
  61. # install headers and that causes the linking to
  62. # fail since the compiler finds the Mesa headers but NVidia's library.
  63. # Make sure the NVIDIA directory comes BEFORE the others.
  64. # - Atanas Georgiev <[email protected]>
  65. find_path(OPENGL_INCLUDE_DIR GL/gl.h
  66. /usr/share/doc/NVIDIA_GLX-1.0/include
  67. /usr/openwin/share/include
  68. /opt/graphics/OpenGL/include /usr/X11R6/include
  69. )
  70. find_path(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h
  71. /usr/share/doc/NVIDIA_GLX-1.0/include
  72. /usr/openwin/share/include
  73. /opt/graphics/OpenGL/include /usr/X11R6/include
  74. )
  75. find_library(OPENGL_gl_LIBRARY
  76. NAMES GL MesaGL
  77. PATHS /opt/graphics/OpenGL/lib
  78. /usr/openwin/lib
  79. /usr/shlib /usr/X11R6/lib
  80. ${HPUX_IA_OPENGL_LIB_PATH}
  81. )
  82. # On Unix OpenGL most certainly always requires X11.
  83. # Feel free to tighten up these conditions if you don't
  84. # think this is always true.
  85. # It's not true on OSX.
  86. if (OPENGL_gl_LIBRARY)
  87. if(NOT X11_FOUND)
  88. include(FindX11)
  89. endif()
  90. if (X11_FOUND)
  91. if (NOT APPLE)
  92. set (OPENGL_LIBRARIES ${X11_LIBRARIES})
  93. endif ()
  94. endif ()
  95. endif ()
  96. find_library(OPENGL_glu_LIBRARY
  97. NAMES GLU MesaGLU
  98. PATHS ${OPENGL_gl_LIBRARY}
  99. /opt/graphics/OpenGL/lib
  100. /usr/openwin/lib
  101. /usr/shlib /usr/X11R6/lib
  102. )
  103. endif()
  104. endif ()
  105. if(OPENGL_gl_LIBRARY)
  106. if(OPENGL_xmesa_INCLUDE_DIR)
  107. set( OPENGL_XMESA_FOUND "YES" )
  108. else()
  109. set( OPENGL_XMESA_FOUND "NO" )
  110. endif()
  111. set( OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES})
  112. if(OPENGL_glu_LIBRARY)
  113. set( OPENGL_GLU_FOUND "YES" )
  114. set( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
  115. else()
  116. set( OPENGL_GLU_FOUND "NO" )
  117. endif()
  118. # This deprecated setting is for backward compatibility with CMake1.4
  119. set (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
  120. endif()
  121. # This deprecated setting is for backward compatibility with CMake1.4
  122. set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
  123. # handle the QUIETLY and REQUIRED arguments and set OPENGL_FOUND to TRUE if
  124. # all listed variables are TRUE
  125. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  126. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL DEFAULT_MSG OPENGL_gl_LIBRARY)
  127. mark_as_advanced(
  128. OPENGL_INCLUDE_DIR
  129. OPENGL_xmesa_INCLUDE_DIR
  130. OPENGL_glu_LIBRARY
  131. OPENGL_gl_LIBRARY
  132. )