FindGLUT.cmake 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 sets the following variables:
  16. ::
  17. GLUT_INCLUDE_DIR, where to find GL/glut.h, etc.
  18. GLUT_LIBRARIES, the libraries to link against
  19. GLUT_FOUND, If false, do not try to use GLUT.
  20. Also defined, but not for general use are:
  21. ::
  22. GLUT_glut_LIBRARY = the full path to the glut library.
  23. GLUT_Xmu_LIBRARY = the full path to the Xmu library.
  24. GLUT_Xi_LIBRARY = the full path to the Xi Library.
  25. .. versionadded:: 3.13
  26. Debug and Release variants are found separately.
  27. #]=======================================================================]
  28. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  29. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  30. function(_add_glut_target_simple)
  31. if(TARGET GLUT::GLUT)
  32. return()
  33. endif()
  34. add_library(GLUT::GLUT INTERFACE IMPORTED)
  35. if(GLUT_INCLUDE_DIRS)
  36. target_include_directories(GLUT::GLUT SYSTEM
  37. INTERFACE "${GLUT_INCLUDE_DIRS}")
  38. endif()
  39. if(GLUT_LIBRARIES)
  40. target_link_libraries(GLUT::GLUT INTERFACE ${GLUT_LIBRARIES})
  41. endif()
  42. if(GLUT_LDFLAGS)
  43. target_link_options(GLUT::GLUT INTERFACE ${GLUT_LDFLAGS})
  44. endif()
  45. if(GLUT_CFLAGS)
  46. separate_arguments(GLUT_CFLAGS_SPLIT UNIX_COMMAND "${GLUT_CFLAGS}")
  47. target_compile_options(GLUT::GLUT INTERFACE ${GLUT_CFLAGS_SPLIT})
  48. endif()
  49. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  50. IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
  51. endfunction()
  52. find_package(PkgConfig)
  53. if(PKG_CONFIG_FOUND)
  54. pkg_check_modules(GLUT glut)
  55. if(GLUT_FOUND)
  56. _add_glut_target_simple()
  57. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_FOUND)
  58. return()
  59. endif()
  60. endif()
  61. if(WIN32)
  62. find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
  63. PATHS ${GLUT_ROOT_PATH}/include )
  64. find_library( GLUT_glut_LIBRARY_RELEASE NAMES glut glut32 freeglut
  65. PATHS
  66. ${OPENGL_LIBRARY_DIR}
  67. ${GLUT_ROOT_PATH}/Release
  68. )
  69. find_library( GLUT_glut_LIBRARY_DEBUG NAMES freeglutd
  70. PATHS
  71. ${OPENGL_LIBRARY_DIR}
  72. ${GLUT_ROOT_PATH}/Debug
  73. )
  74. mark_as_advanced(GLUT_glut_LIBRARY_RELEASE GLUT_glut_LIBRARY_DEBUG)
  75. select_library_configurations(GLUT_glut)
  76. elseif(APPLE)
  77. find_path(GLUT_INCLUDE_DIR glut.h ${OPENGL_LIBRARY_DIR})
  78. find_library(GLUT_glut_LIBRARY GLUT DOC "GLUT library for OSX")
  79. find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX")
  80. mark_as_advanced(GLUT_glut_LIBRARY GLUT_cocoa_LIBRARY)
  81. if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa)
  82. add_library(GLUT::Cocoa UNKNOWN IMPORTED)
  83. # Cocoa should always be a Framework, but we check to make sure.
  84. if(GLUT_cocoa_LIBRARY MATCHES "/([^/]+)\\.framework$")
  85. set(_glut_cocoa "${GLUT_cocoa_LIBRARY}/${CMAKE_MATCH_1}")
  86. if(EXISTS "${_glut_cocoa}.tbd")
  87. string(APPEND _glut_cocoa ".tbd")
  88. endif()
  89. set_target_properties(GLUT::Cocoa PROPERTIES
  90. IMPORTED_LOCATION "${_glut_cocoa}")
  91. else()
  92. set_target_properties(GLUT::Cocoa PROPERTIES
  93. IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}")
  94. endif()
  95. endif()
  96. else()
  97. if(BEOS)
  98. set(_GLUT_INC_DIR /boot/develop/headers/os/opengl)
  99. set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86)
  100. else()
  101. find_library( GLUT_Xi_LIBRARY Xi
  102. /usr/openwin/lib
  103. )
  104. mark_as_advanced(GLUT_Xi_LIBRARY)
  105. find_library( GLUT_Xmu_LIBRARY Xmu
  106. /usr/openwin/lib
  107. )
  108. mark_as_advanced(GLUT_Xmu_LIBRARY)
  109. if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi)
  110. add_library(GLUT::Xi UNKNOWN IMPORTED)
  111. set_target_properties(GLUT::Xi PROPERTIES
  112. IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}")
  113. endif()
  114. if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu)
  115. add_library(GLUT::Xmu UNKNOWN IMPORTED)
  116. set_target_properties(GLUT::Xmu PROPERTIES
  117. IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}")
  118. endif()
  119. endif ()
  120. find_path( GLUT_INCLUDE_DIR GL/glut.h
  121. /usr/include/GL
  122. /usr/openwin/share/include
  123. /usr/openwin/include
  124. /opt/graphics/OpenGL/include
  125. /opt/graphics/OpenGL/contrib/libglut
  126. ${_GLUT_INC_DIR}
  127. )
  128. find_library( GLUT_glut_LIBRARY glut
  129. /usr/openwin/lib
  130. ${_GLUT_glut_LIB_DIR}
  131. )
  132. unset(_GLUT_INC_DIR)
  133. unset(_GLUT_glut_LIB_DIR)
  134. endif()
  135. mark_as_advanced(GLUT_glut_LIBRARY)
  136. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
  137. if (GLUT_FOUND)
  138. # Is -lXi and -lXmu required on all platforms that have it?
  139. # If not, we need some way to figure out what platform we are on.
  140. set( GLUT_LIBRARIES
  141. ${GLUT_glut_LIBRARY}
  142. )
  143. foreach(v GLUT_Xmu_LIBRARY GLUT_Xi_LIBRARY GLUT_cocoa_LIBRARY)
  144. if(${v})
  145. list(APPEND GLUT_LIBRARIES ${${v}})
  146. endif()
  147. endforeach()
  148. if(NOT TARGET GLUT::GLUT)
  149. add_library(GLUT::GLUT UNKNOWN IMPORTED)
  150. set_target_properties(GLUT::GLUT PROPERTIES
  151. INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIR}")
  152. if(GLUT_glut_LIBRARY MATCHES "/([^/]+)\\.framework$")
  153. set(_glut_glut "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}")
  154. if(EXISTS "${_glut_glut}.tbd")
  155. string(APPEND _glut_glut ".tbd")
  156. endif()
  157. set_target_properties(GLUT::GLUT PROPERTIES
  158. IMPORTED_LOCATION "${_glut_glut}")
  159. else()
  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. endif()
  177. if(TARGET GLUT::Xmu)
  178. set_property(TARGET GLUT::GLUT APPEND
  179. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu)
  180. endif()
  181. if(TARGET GLUT::Xi)
  182. set_property(TARGET GLUT::GLUT APPEND
  183. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi)
  184. endif()
  185. if(TARGET GLUT::Cocoa)
  186. set_property(TARGET GLUT::GLUT APPEND
  187. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa)
  188. endif()
  189. endif()
  190. #The following deprecated settings are for backwards compatibility with CMake1.4
  191. set (GLUT_LIBRARY ${GLUT_LIBRARIES})
  192. set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
  193. endif()
  194. mark_as_advanced(GLUT_INCLUDE_DIR)