FindGLUT.cmake 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindGLUT
  5. --------
  6. Finds the OpenGL Utility Toolkit (GLUT) library, which provides a simple API
  7. for creating windows, handling input, and managing events in OpenGL
  8. applications:
  9. .. code-block:: cmake
  10. find_package(GLUT [...])
  11. Imported Targets
  12. ^^^^^^^^^^^^^^^^
  13. This module provides the following :ref:`Imported Targets`:
  14. ``GLUT::GLUT``
  15. .. versionadded:: 3.1
  16. Target encapsulating the GLUT usage requirements, available if GLUT is found.
  17. Result Variables
  18. ^^^^^^^^^^^^^^^^
  19. This module defines the following variables:
  20. ``GLUT_FOUND``
  21. Boolean indicating whether GLUT was found.
  22. ``GLUT_INCLUDE_DIRS``
  23. .. versionadded:: 3.23
  24. Include directories needed to use GLUT. Starting with CMake 3.23, this
  25. variable is intended to be used in target usage requirements instead of the
  26. cache variable ``GLUT_INCLUDE_DIR``, which is intended for finding GLUT.
  27. ``GLUT_LIBRARIES``
  28. List of libraries needed to link against for using GLUT.
  29. Cache Variables
  30. ^^^^^^^^^^^^^^^
  31. This module may set the following cache variables depending on platform.
  32. These variables may optionally be set to help this module find the
  33. correct files, but should not be used as result variables:
  34. ``GLUT_INCLUDE_DIR``
  35. The full path to the directory containing ``GL/glut.h`` (without the ``GL/``).
  36. ``GLUT_glut_LIBRARY``
  37. The full path to the ``glut`` library.
  38. ``GLUT_Xi_LIBRARY``
  39. The full path to the dependent ``Xi`` (X Input Device Extension) library on
  40. some systems.
  41. ``GLUT_Xmu_LIBRARY``
  42. The full path to the dependent ``Xmu`` (X Miscellaneous Utilities) library on
  43. some systems.
  44. Examples
  45. ^^^^^^^^
  46. Finding GLUT and linking it to a project target:
  47. .. code-block:: cmake
  48. find_package(GLUT)
  49. target_link_libraries(project_target PRIVATE GLUT::GLUT)
  50. #]=======================================================================]
  51. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  52. include(FindPackageHandleStandardArgs)
  53. find_package(PkgConfig QUIET)
  54. if(PkgConfig_FOUND)
  55. pkg_check_modules(PC_GLUT QUIET glut)
  56. if(NOT PC_GLUT_FOUND)
  57. pkg_check_modules(PC_GLUT QUIET freeglut)
  58. endif()
  59. endif()
  60. if(WIN32)
  61. find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
  62. PATHS ${GLUT_ROOT_PATH}/include
  63. HINTS ${PC_GLUT_INCLUDE_DIRS})
  64. mark_as_advanced(GLUT_INCLUDE_DIR)
  65. find_library( GLUT_glut_LIBRARY_RELEASE NAMES freeglut glut glut32
  66. PATHS
  67. ${OPENGL_LIBRARY_DIR}
  68. ${GLUT_ROOT_PATH}/Release
  69. HINTS
  70. ${PC_GLUT_LIBRARY_DIRS}
  71. )
  72. # N.B. As the pkg-config cannot distinguish between release and debug libraries,
  73. # assume that their hint was the both Debug and Release library.
  74. find_library( GLUT_glut_LIBRARY_DEBUG NAMES freeglutd
  75. PATHS
  76. ${OPENGL_LIBRARY_DIR}
  77. ${GLUT_ROOT_PATH}/Debug
  78. HINTS
  79. ${PC_GLUT_LIBRARY_DIRS}
  80. )
  81. mark_as_advanced(GLUT_glut_LIBRARY_RELEASE GLUT_glut_LIBRARY_DEBUG)
  82. select_library_configurations(GLUT_glut)
  83. elseif(APPLE)
  84. find_path(GLUT_INCLUDE_DIR glut.h PATHS ${OPENGL_LIBRARY_DIR} HINTS ${PC_GLUT_INCLUDE_DIRS})
  85. mark_as_advanced(GLUT_INCLUDE_DIR)
  86. find_library(GLUT_glut_LIBRARY GLUT HINTS ${PC_GLUT_LIBRARY_DIRS} DOC "GLUT library for OSX")
  87. find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX")
  88. mark_as_advanced(GLUT_glut_LIBRARY GLUT_cocoa_LIBRARY)
  89. if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa)
  90. add_library(GLUT::Cocoa UNKNOWN IMPORTED)
  91. set_target_properties(GLUT::Cocoa PROPERTIES
  92. IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}")
  93. endif()
  94. else()
  95. if(BEOS)
  96. set(_GLUT_INC_DIR /boot/develop/headers/os/opengl)
  97. set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86)
  98. else()
  99. find_library( GLUT_Xi_LIBRARY Xi
  100. /usr/openwin/lib
  101. )
  102. mark_as_advanced(GLUT_Xi_LIBRARY)
  103. find_library( GLUT_Xmu_LIBRARY Xmu
  104. /usr/openwin/lib
  105. )
  106. mark_as_advanced(GLUT_Xmu_LIBRARY)
  107. if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi)
  108. add_library(GLUT::Xi UNKNOWN IMPORTED)
  109. set_target_properties(GLUT::Xi PROPERTIES
  110. IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}")
  111. endif()
  112. if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu)
  113. add_library(GLUT::Xmu UNKNOWN IMPORTED)
  114. set_target_properties(GLUT::Xmu PROPERTIES
  115. IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}")
  116. endif()
  117. endif ()
  118. find_path( GLUT_INCLUDE_DIR GL/glut.h
  119. PATHS
  120. /usr/include/GL
  121. /usr/openwin/share/include
  122. /usr/openwin/include
  123. /opt/graphics/OpenGL/include
  124. /opt/graphics/OpenGL/contrib/libglut
  125. ${_GLUT_INC_DIR}
  126. HINTS
  127. ${PC_GLUT_INCLUDE_DIRS}
  128. )
  129. mark_as_advanced(GLUT_INCLUDE_DIR)
  130. find_library( GLUT_glut_LIBRARY glut
  131. PATHS
  132. /usr/openwin/lib
  133. ${_GLUT_glut_LIB_DIR}
  134. HINTS
  135. ${PC_GLUT_LIBRARY_DIRS}
  136. )
  137. mark_as_advanced(GLUT_glut_LIBRARY)
  138. unset(_GLUT_INC_DIR)
  139. unset(_GLUT_glut_LIB_DIR)
  140. endif()
  141. find_package_handle_standard_args(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
  142. if (GLUT_FOUND)
  143. # Is -lXi and -lXmu required on all platforms that have it?
  144. # If not, we need some way to figure out what platform we are on.
  145. set( GLUT_LIBRARIES
  146. ${GLUT_glut_LIBRARY}
  147. )
  148. set(GLUT_INCLUDE_DIRS
  149. ${GLUT_INCLUDE_DIR}
  150. )
  151. foreach(v GLUT_Xmu_LIBRARY GLUT_Xi_LIBRARY GLUT_cocoa_LIBRARY)
  152. if(${v})
  153. list(APPEND GLUT_LIBRARIES ${${v}})
  154. endif()
  155. endforeach()
  156. if(NOT TARGET GLUT::GLUT)
  157. add_library(GLUT::GLUT UNKNOWN IMPORTED)
  158. set_target_properties(GLUT::GLUT PROPERTIES
  159. INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIRS}")
  160. if(GLUT_glut_LIBRARY_RELEASE)
  161. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  162. IMPORTED_CONFIGURATIONS RELEASE)
  163. set_target_properties(GLUT::GLUT PROPERTIES
  164. IMPORTED_LOCATION_RELEASE "${GLUT_glut_LIBRARY_RELEASE}")
  165. endif()
  166. if(GLUT_glut_LIBRARY_DEBUG)
  167. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  168. IMPORTED_CONFIGURATIONS DEBUG)
  169. set_target_properties(GLUT::GLUT PROPERTIES
  170. IMPORTED_LOCATION_DEBUG "${GLUT_glut_LIBRARY_DEBUG}")
  171. endif()
  172. if(NOT GLUT_glut_LIBRARY_RELEASE AND NOT GLUT_glut_LIBRARY_DEBUG)
  173. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  174. IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
  175. endif()
  176. if(TARGET GLUT::Xmu)
  177. set_property(TARGET GLUT::GLUT APPEND
  178. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu)
  179. endif()
  180. if(TARGET GLUT::Xi)
  181. set_property(TARGET GLUT::GLUT APPEND
  182. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi)
  183. endif()
  184. if(TARGET GLUT::Cocoa)
  185. set_property(TARGET GLUT::GLUT APPEND
  186. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa)
  187. endif()
  188. endif()
  189. endif()