FindGLUT.cmake 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. function(_add_glut_target_simple)
  48. if(TARGET GLUT::GLUT)
  49. return()
  50. endif()
  51. add_library(GLUT::GLUT INTERFACE IMPORTED)
  52. if(GLUT_INCLUDE_DIRS)
  53. target_include_directories(GLUT::GLUT SYSTEM
  54. INTERFACE "${GLUT_INCLUDE_DIRS}")
  55. endif()
  56. if(GLUT_LIBRARIES)
  57. target_link_libraries(GLUT::GLUT INTERFACE ${GLUT_LIBRARIES})
  58. endif()
  59. if(GLUT_LIBRARY_DIRS)
  60. target_link_directories(GLUT::GLUT INTERFACE ${GLUT_LIBRARY_DIRS})
  61. endif()
  62. if(GLUT_LDFLAGS)
  63. target_link_options(GLUT::GLUT INTERFACE ${GLUT_LDFLAGS})
  64. endif()
  65. if(GLUT_CFLAGS)
  66. separate_arguments(GLUT_CFLAGS_SPLIT UNIX_COMMAND "${GLUT_CFLAGS}")
  67. target_compile_options(GLUT::GLUT INTERFACE ${GLUT_CFLAGS_SPLIT})
  68. endif()
  69. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  70. IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
  71. endfunction()
  72. find_package(PkgConfig QUIET)
  73. if(PKG_CONFIG_FOUND)
  74. pkg_check_modules(GLUT QUIET glut)
  75. if(GLUT_FOUND)
  76. # GLUT_INCLUDE_DIRS is now the official result variable, but
  77. # older versions of CMake only provided GLUT_INCLUDE_DIR.
  78. set(GLUT_INCLUDE_DIR "${GLUT_INCLUDE_DIRS}")
  79. _add_glut_target_simple()
  80. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_FOUND)
  81. return()
  82. endif()
  83. endif()
  84. if(WIN32)
  85. find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
  86. PATHS ${GLUT_ROOT_PATH}/include )
  87. mark_as_advanced(GLUT_INCLUDE_DIR)
  88. find_library( GLUT_glut_LIBRARY_RELEASE NAMES glut glut32 freeglut
  89. PATHS
  90. ${OPENGL_LIBRARY_DIR}
  91. ${GLUT_ROOT_PATH}/Release
  92. )
  93. find_library( GLUT_glut_LIBRARY_DEBUG NAMES freeglutd
  94. PATHS
  95. ${OPENGL_LIBRARY_DIR}
  96. ${GLUT_ROOT_PATH}/Debug
  97. )
  98. mark_as_advanced(GLUT_glut_LIBRARY_RELEASE GLUT_glut_LIBRARY_DEBUG)
  99. select_library_configurations(GLUT_glut)
  100. elseif(APPLE)
  101. find_path(GLUT_INCLUDE_DIR glut.h ${OPENGL_LIBRARY_DIR})
  102. mark_as_advanced(GLUT_INCLUDE_DIR)
  103. find_library(GLUT_glut_LIBRARY GLUT DOC "GLUT library for OSX")
  104. find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX")
  105. mark_as_advanced(GLUT_glut_LIBRARY GLUT_cocoa_LIBRARY)
  106. if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa)
  107. add_library(GLUT::Cocoa UNKNOWN IMPORTED)
  108. # Cocoa should always be a Framework, but we check to make sure.
  109. if(GLUT_cocoa_LIBRARY MATCHES "/([^/]+)\\.framework$")
  110. set(_glut_cocoa "${GLUT_cocoa_LIBRARY}/${CMAKE_MATCH_1}")
  111. if(EXISTS "${_glut_cocoa}.tbd")
  112. string(APPEND _glut_cocoa ".tbd")
  113. endif()
  114. set_target_properties(GLUT::Cocoa PROPERTIES
  115. IMPORTED_LOCATION "${_glut_cocoa}")
  116. else()
  117. set_target_properties(GLUT::Cocoa PROPERTIES
  118. IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}")
  119. endif()
  120. endif()
  121. else()
  122. if(BEOS)
  123. set(_GLUT_INC_DIR /boot/develop/headers/os/opengl)
  124. set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86)
  125. else()
  126. find_library( GLUT_Xi_LIBRARY Xi
  127. /usr/openwin/lib
  128. )
  129. mark_as_advanced(GLUT_Xi_LIBRARY)
  130. find_library( GLUT_Xmu_LIBRARY Xmu
  131. /usr/openwin/lib
  132. )
  133. mark_as_advanced(GLUT_Xmu_LIBRARY)
  134. if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi)
  135. add_library(GLUT::Xi UNKNOWN IMPORTED)
  136. set_target_properties(GLUT::Xi PROPERTIES
  137. IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}")
  138. endif()
  139. if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu)
  140. add_library(GLUT::Xmu UNKNOWN IMPORTED)
  141. set_target_properties(GLUT::Xmu PROPERTIES
  142. IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}")
  143. endif()
  144. endif ()
  145. find_path( GLUT_INCLUDE_DIR GL/glut.h
  146. /usr/include/GL
  147. /usr/openwin/share/include
  148. /usr/openwin/include
  149. /opt/graphics/OpenGL/include
  150. /opt/graphics/OpenGL/contrib/libglut
  151. ${_GLUT_INC_DIR}
  152. )
  153. mark_as_advanced(GLUT_INCLUDE_DIR)
  154. find_library( GLUT_glut_LIBRARY glut
  155. /usr/openwin/lib
  156. ${_GLUT_glut_LIB_DIR}
  157. )
  158. mark_as_advanced(GLUT_glut_LIBRARY)
  159. unset(_GLUT_INC_DIR)
  160. unset(_GLUT_glut_LIB_DIR)
  161. endif()
  162. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
  163. if (GLUT_FOUND)
  164. # Is -lXi and -lXmu required on all platforms that have it?
  165. # If not, we need some way to figure out what platform we are on.
  166. set( GLUT_LIBRARIES
  167. ${GLUT_glut_LIBRARY}
  168. )
  169. set(GLUT_INCLUDE_DIRS
  170. ${GLUT_INCLUDE_DIR}
  171. )
  172. foreach(v GLUT_Xmu_LIBRARY GLUT_Xi_LIBRARY GLUT_cocoa_LIBRARY)
  173. if(${v})
  174. list(APPEND GLUT_LIBRARIES ${${v}})
  175. endif()
  176. endforeach()
  177. if(NOT TARGET GLUT::GLUT)
  178. add_library(GLUT::GLUT UNKNOWN IMPORTED)
  179. set_target_properties(GLUT::GLUT PROPERTIES
  180. INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIRS}")
  181. if(GLUT_glut_LIBRARY MATCHES "/([^/]+)\\.framework$")
  182. set(_glut_glut "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}")
  183. if(EXISTS "${_glut_glut}.tbd")
  184. string(APPEND _glut_glut ".tbd")
  185. endif()
  186. set_target_properties(GLUT::GLUT PROPERTIES
  187. IMPORTED_LOCATION "${_glut_glut}")
  188. else()
  189. if(GLUT_glut_LIBRARY_RELEASE)
  190. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  191. IMPORTED_CONFIGURATIONS RELEASE)
  192. set_target_properties(GLUT::GLUT PROPERTIES
  193. IMPORTED_LOCATION_RELEASE "${GLUT_glut_LIBRARY_RELEASE}")
  194. endif()
  195. if(GLUT_glut_LIBRARY_DEBUG)
  196. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  197. IMPORTED_CONFIGURATIONS DEBUG)
  198. set_target_properties(GLUT::GLUT PROPERTIES
  199. IMPORTED_LOCATION_DEBUG "${GLUT_glut_LIBRARY_DEBUG}")
  200. endif()
  201. if(NOT GLUT_glut_LIBRARY_RELEASE AND NOT GLUT_glut_LIBRARY_DEBUG)
  202. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  203. IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
  204. endif()
  205. endif()
  206. if(TARGET GLUT::Xmu)
  207. set_property(TARGET GLUT::GLUT APPEND
  208. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu)
  209. endif()
  210. if(TARGET GLUT::Xi)
  211. set_property(TARGET GLUT::GLUT APPEND
  212. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi)
  213. endif()
  214. if(TARGET GLUT::Cocoa)
  215. set_property(TARGET GLUT::GLUT APPEND
  216. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa)
  217. endif()
  218. endif()
  219. #The following deprecated settings are for backwards compatibility with CMake1.4
  220. set (GLUT_LIBRARY ${GLUT_LIBRARIES})
  221. set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIRS})
  222. endif()