FindGLUT.cmake 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindGLUT
  5. --------
  6. Find OpenGL Utility Toolkit (GLUT) library and include files.
  7. IMPORTED Targets
  8. ^^^^^^^^^^^^^^^^
  9. This module defines the :prop_tgt:`IMPORTED` targets:
  10. ``GLUT::GLUT``
  11. Defined if the system has GLUT.
  12. Result Variables
  13. ^^^^^^^^^^^^^^^^
  14. This module sets the following variables:
  15. ::
  16. GLUT_INCLUDE_DIR, where to find GL/glut.h, etc.
  17. GLUT_LIBRARIES, the libraries to link against
  18. GLUT_FOUND, If false, do not try to use GLUT.
  19. Also defined, but not for general use are:
  20. ::
  21. GLUT_glut_LIBRARY = the full path to the glut library.
  22. GLUT_Xmu_LIBRARY = the full path to the Xmu library.
  23. GLUT_Xi_LIBRARY = the full path to the Xi Library.
  24. #]=======================================================================]
  25. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  26. if (WIN32)
  27. find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
  28. PATHS ${GLUT_ROOT_PATH}/include )
  29. find_library( GLUT_glut_LIBRARY_RELEASE NAMES glut glut32 freeglut
  30. PATHS
  31. ${OPENGL_LIBRARY_DIR}
  32. ${GLUT_ROOT_PATH}/Release
  33. )
  34. find_library( GLUT_glut_LIBRARY_DEBUG NAMES freeglutd
  35. PATHS
  36. ${OPENGL_LIBRARY_DIR}
  37. ${GLUT_ROOT_PATH}/Debug
  38. )
  39. mark_as_advanced(GLUT_glut_LIBRARY_RELEASE GLUT_glut_LIBRARY_DEBUG)
  40. select_library_configurations(GLUT_glut)
  41. else ()
  42. if (APPLE)
  43. find_path(GLUT_INCLUDE_DIR glut.h ${OPENGL_LIBRARY_DIR})
  44. find_library(GLUT_glut_LIBRARY GLUT DOC "GLUT library for OSX")
  45. find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX")
  46. mark_as_advanced(GLUT_glut_LIBRARY GLUT_cocoa_LIBRARY)
  47. if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa)
  48. add_library(GLUT::Cocoa UNKNOWN IMPORTED)
  49. # Cocoa should always be a Framework, but we check to make sure.
  50. if(GLUT_cocoa_LIBRARY MATCHES "/([^/]+)\\.framework$")
  51. set(_glut_cocoa "${GLUT_cocoa_LIBRARY}/${CMAKE_MATCH_1}")
  52. if(EXISTS "${_glut_cocoa}.tbd")
  53. string(APPEND _glut_cocoa ".tbd")
  54. endif()
  55. set_target_properties(GLUT::Cocoa PROPERTIES
  56. IMPORTED_LOCATION "${_glut_cocoa}")
  57. else()
  58. set_target_properties(GLUT::Cocoa PROPERTIES
  59. IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}")
  60. endif()
  61. endif()
  62. else ()
  63. if (BEOS)
  64. set(_GLUT_INC_DIR /boot/develop/headers/os/opengl)
  65. set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86)
  66. else()
  67. find_library( GLUT_Xi_LIBRARY Xi
  68. /usr/openwin/lib
  69. )
  70. mark_as_advanced(GLUT_Xi_LIBRARY)
  71. find_library( GLUT_Xmu_LIBRARY Xmu
  72. /usr/openwin/lib
  73. )
  74. mark_as_advanced(GLUT_Xmu_LIBRARY)
  75. if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi)
  76. add_library(GLUT::Xi UNKNOWN IMPORTED)
  77. set_target_properties(GLUT::Xi PROPERTIES
  78. IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}")
  79. endif()
  80. if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu)
  81. add_library(GLUT::Xmu UNKNOWN IMPORTED)
  82. set_target_properties(GLUT::Xmu PROPERTIES
  83. IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}")
  84. endif()
  85. endif ()
  86. find_path( GLUT_INCLUDE_DIR GL/glut.h
  87. /usr/include/GL
  88. /usr/openwin/share/include
  89. /usr/openwin/include
  90. /opt/graphics/OpenGL/include
  91. /opt/graphics/OpenGL/contrib/libglut
  92. ${_GLUT_INC_DIR}
  93. )
  94. find_library( GLUT_glut_LIBRARY glut
  95. /usr/openwin/lib
  96. ${_GLUT_glut_LIB_DIR}
  97. )
  98. mark_as_advanced(GLUT_glut_LIBRARY)
  99. unset(_GLUT_INC_DIR)
  100. unset(_GLUT_glut_LIB_DIR)
  101. endif ()
  102. endif ()
  103. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  104. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
  105. if (GLUT_FOUND)
  106. # Is -lXi and -lXmu required on all platforms that have it?
  107. # If not, we need some way to figure out what platform we are on.
  108. set( GLUT_LIBRARIES
  109. ${GLUT_glut_LIBRARY}
  110. )
  111. foreach(v GLUT_Xmu_LIBRARY GLUT_Xi_LIBRARY GLUT_cocoa_LIBRARY)
  112. if(${v})
  113. list(APPEND GLUT_LIBRARIES ${${v}})
  114. endif()
  115. endforeach()
  116. if(NOT TARGET GLUT::GLUT)
  117. add_library(GLUT::GLUT UNKNOWN IMPORTED)
  118. set_target_properties(GLUT::GLUT PROPERTIES
  119. INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIR}")
  120. if(GLUT_glut_LIBRARY MATCHES "/([^/]+)\\.framework$")
  121. set(_glut_glut "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}")
  122. if(EXISTS "${_glut_glut}.tbd")
  123. string(APPEND _glut_glut ".tbd")
  124. endif()
  125. set_target_properties(GLUT::GLUT PROPERTIES
  126. IMPORTED_LOCATION "${_glut_glut}")
  127. else()
  128. if(GLUT_glut_LIBRARY_RELEASE)
  129. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  130. IMPORTED_CONFIGURATIONS RELEASE)
  131. set_target_properties(GLUT::GLUT PROPERTIES
  132. IMPORTED_LOCATION_RELEASE "${GLUT_glut_LIBRARY_RELEASE}")
  133. endif()
  134. if(GLUT_glut_LIBRARY_DEBUG)
  135. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  136. IMPORTED_CONFIGURATIONS DEBUG)
  137. set_target_properties(GLUT::GLUT PROPERTIES
  138. IMPORTED_LOCATION_DEBUG "${GLUT_glut_LIBRARY_DEBUG}")
  139. endif()
  140. if(NOT GLUT_glut_LIBRARY_RELEASE AND NOT GLUT_glut_LIBRARY_DEBUG)
  141. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  142. IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
  143. endif()
  144. endif()
  145. if(TARGET GLUT::Xmu)
  146. set_property(TARGET GLUT::GLUT APPEND
  147. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu)
  148. endif()
  149. if(TARGET GLUT::Xi)
  150. set_property(TARGET GLUT::GLUT APPEND
  151. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi)
  152. endif()
  153. if(TARGET GLUT::Cocoa)
  154. set_property(TARGET GLUT::GLUT APPEND
  155. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa)
  156. endif()
  157. endif()
  158. #The following deprecated settings are for backwards compatibility with CMake1.4
  159. set (GLUT_LIBRARY ${GLUT_LIBRARIES})
  160. set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
  161. endif()
  162. mark_as_advanced(GLUT_INCLUDE_DIR)