FindGLUT.cmake 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. .. versionadded:: 3.1
  10. This module defines the :prop_tgt:`IMPORTED` targets:
  11. ``GLUT::GLUT``
  12. Defined if the system has GLUT.
  13. Result Variables
  14. ^^^^^^^^^^^^^^^^
  15. This module defines the following variables:
  16. ``GLUT_FOUND``
  17. True if ``glut`` was found.
  18. ``GLUT_INCLUDE_DIRS``
  19. .. versionadded:: 3.23
  20. Where to find GL/glut.h, etc.
  21. ``GLUT_LIBRARIES``
  22. List of libraries for using ``glut``.
  23. Cache Variables
  24. ^^^^^^^^^^^^^^^
  25. This module may set the following variables depending on platform.
  26. These variables may optionally be set to help this module find the
  27. correct files, but clients should not use these as results:
  28. ``GLUT_INCLUDE_DIR``
  29. The full path to the directory containing ``GL/glut.h``,
  30. not including ``GL/``.
  31. ``GLUT_glut_LIBRARY``
  32. The full path to the glut library.
  33. ``GLUT_Xmu_LIBRARY``
  34. The full path to the Xmu library.
  35. ``GLUT_Xi_LIBRARY``
  36. The full path to the Xi Library.
  37. Obsolete Variables
  38. ^^^^^^^^^^^^^^^^^^
  39. The following variables may also be provided, for backwards compatibility:
  40. ``GLUT_INCLUDE_DIR``
  41. This is one of above `Cache Variables`_, but prior to CMake 3.23 was
  42. also a result variable. Prefer to use ``GLUT_INCLUDE_DIRS`` instead
  43. in CMake 3.23 and above.
  44. #]=======================================================================]
  45. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  46. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  47. find_package(PkgConfig QUIET)
  48. if(PKG_CONFIG_FOUND)
  49. pkg_check_modules(PC_GLUT QUIET glut)
  50. if(NOT PC_GLUT_FOUND)
  51. pkg_check_modules(PC_GLUT QUIET freeglut)
  52. endif()
  53. endif()
  54. if(WIN32)
  55. find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
  56. PATHS ${GLUT_ROOT_PATH}/include
  57. HINTS ${PC_GLUT_INCLUDE_DIRS})
  58. mark_as_advanced(GLUT_INCLUDE_DIR)
  59. find_library( GLUT_glut_LIBRARY_RELEASE NAMES freeglut glut glut32
  60. PATHS
  61. ${OPENGL_LIBRARY_DIR}
  62. ${GLUT_ROOT_PATH}/Release
  63. HINTS
  64. ${PC_GLUT_LIBRARY_DIRS}
  65. )
  66. # N.B. As the pkg-config cannot distinguish between release and debug libraries,
  67. # assume that their hint was the both Debug and Release library.
  68. find_library( GLUT_glut_LIBRARY_DEBUG NAMES freeglutd
  69. PATHS
  70. ${OPENGL_LIBRARY_DIR}
  71. ${GLUT_ROOT_PATH}/Debug
  72. HINTS
  73. ${PC_GLUT_LIBRARY_DIRS}
  74. )
  75. mark_as_advanced(GLUT_glut_LIBRARY_RELEASE GLUT_glut_LIBRARY_DEBUG)
  76. select_library_configurations(GLUT_glut)
  77. elseif(APPLE)
  78. find_path(GLUT_INCLUDE_DIR glut.h PATHS ${OPENGL_LIBRARY_DIR} HINTS ${PC_GLUT_INCLUDE_DIRS})
  79. mark_as_advanced(GLUT_INCLUDE_DIR)
  80. find_library(GLUT_glut_LIBRARY GLUT HINTS ${PC_GLUT_LIBRARY_DIRS} DOC "GLUT library for OSX")
  81. find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX")
  82. mark_as_advanced(GLUT_glut_LIBRARY GLUT_cocoa_LIBRARY)
  83. if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa)
  84. add_library(GLUT::Cocoa UNKNOWN IMPORTED)
  85. # Cocoa should always be a Framework, but we check to make sure.
  86. if(GLUT_cocoa_LIBRARY MATCHES "/([^/]+)\\.framework$")
  87. set(_glut_cocoa "${GLUT_cocoa_LIBRARY}/${CMAKE_MATCH_1}")
  88. if(EXISTS "${_glut_cocoa}.tbd")
  89. string(APPEND _glut_cocoa ".tbd")
  90. endif()
  91. set_target_properties(GLUT::Cocoa PROPERTIES
  92. IMPORTED_LOCATION "${_glut_cocoa}")
  93. else()
  94. set_target_properties(GLUT::Cocoa PROPERTIES
  95. IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}")
  96. endif()
  97. endif()
  98. else()
  99. if(BEOS)
  100. set(_GLUT_INC_DIR /boot/develop/headers/os/opengl)
  101. set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86)
  102. else()
  103. find_library( GLUT_Xi_LIBRARY Xi
  104. /usr/openwin/lib
  105. )
  106. mark_as_advanced(GLUT_Xi_LIBRARY)
  107. find_library( GLUT_Xmu_LIBRARY Xmu
  108. /usr/openwin/lib
  109. )
  110. mark_as_advanced(GLUT_Xmu_LIBRARY)
  111. if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi)
  112. add_library(GLUT::Xi UNKNOWN IMPORTED)
  113. set_target_properties(GLUT::Xi PROPERTIES
  114. IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}")
  115. endif()
  116. if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu)
  117. add_library(GLUT::Xmu UNKNOWN IMPORTED)
  118. set_target_properties(GLUT::Xmu PROPERTIES
  119. IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}")
  120. endif()
  121. endif ()
  122. find_path( GLUT_INCLUDE_DIR GL/glut.h
  123. PATHS
  124. /usr/include/GL
  125. /usr/openwin/share/include
  126. /usr/openwin/include
  127. /opt/graphics/OpenGL/include
  128. /opt/graphics/OpenGL/contrib/libglut
  129. ${_GLUT_INC_DIR}
  130. HINTS
  131. ${PC_GLUT_INCLUDE_DIRS}
  132. )
  133. mark_as_advanced(GLUT_INCLUDE_DIR)
  134. find_library( GLUT_glut_LIBRARY glut
  135. PATHS
  136. /usr/openwin/lib
  137. ${_GLUT_glut_LIB_DIR}
  138. HINTS
  139. ${PC_GLUT_LIBRARY_DIRS}
  140. )
  141. mark_as_advanced(GLUT_glut_LIBRARY)
  142. unset(_GLUT_INC_DIR)
  143. unset(_GLUT_glut_LIB_DIR)
  144. endif()
  145. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
  146. if (GLUT_FOUND)
  147. # Is -lXi and -lXmu required on all platforms that have it?
  148. # If not, we need some way to figure out what platform we are on.
  149. set( GLUT_LIBRARIES
  150. ${GLUT_glut_LIBRARY}
  151. )
  152. set(GLUT_INCLUDE_DIRS
  153. ${GLUT_INCLUDE_DIR}
  154. )
  155. foreach(v GLUT_Xmu_LIBRARY GLUT_Xi_LIBRARY GLUT_cocoa_LIBRARY)
  156. if(${v})
  157. list(APPEND GLUT_LIBRARIES ${${v}})
  158. endif()
  159. endforeach()
  160. if(NOT TARGET GLUT::GLUT)
  161. add_library(GLUT::GLUT UNKNOWN IMPORTED)
  162. set_target_properties(GLUT::GLUT PROPERTIES
  163. INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIRS}")
  164. if(GLUT_glut_LIBRARY MATCHES "/([^/]+)\\.framework$")
  165. set(_glut_glut "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}")
  166. if(EXISTS "${_glut_glut}.tbd")
  167. string(APPEND _glut_glut ".tbd")
  168. endif()
  169. set_target_properties(GLUT::GLUT PROPERTIES
  170. IMPORTED_LOCATION "${_glut_glut}")
  171. else()
  172. if(GLUT_glut_LIBRARY_RELEASE)
  173. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  174. IMPORTED_CONFIGURATIONS RELEASE)
  175. set_target_properties(GLUT::GLUT PROPERTIES
  176. IMPORTED_LOCATION_RELEASE "${GLUT_glut_LIBRARY_RELEASE}")
  177. endif()
  178. if(GLUT_glut_LIBRARY_DEBUG)
  179. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  180. IMPORTED_CONFIGURATIONS DEBUG)
  181. set_target_properties(GLUT::GLUT PROPERTIES
  182. IMPORTED_LOCATION_DEBUG "${GLUT_glut_LIBRARY_DEBUG}")
  183. endif()
  184. if(NOT GLUT_glut_LIBRARY_RELEASE AND NOT GLUT_glut_LIBRARY_DEBUG)
  185. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  186. IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
  187. endif()
  188. endif()
  189. if(TARGET GLUT::Xmu)
  190. set_property(TARGET GLUT::GLUT APPEND
  191. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu)
  192. endif()
  193. if(TARGET GLUT::Xi)
  194. set_property(TARGET GLUT::GLUT APPEND
  195. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi)
  196. endif()
  197. if(TARGET GLUT::Cocoa)
  198. set_property(TARGET GLUT::GLUT APPEND
  199. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa)
  200. endif()
  201. endif()
  202. endif()