FindGLUT.cmake 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_target_properties(GLUT::Cocoa PROPERTIES
  52. IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}/${CMAKE_MATCH_1}")
  53. else()
  54. set_target_properties(GLUT::Cocoa PROPERTIES
  55. IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}")
  56. endif()
  57. endif()
  58. else ()
  59. if (BEOS)
  60. set(_GLUT_INC_DIR /boot/develop/headers/os/opengl)
  61. set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86)
  62. else()
  63. find_library( GLUT_Xi_LIBRARY Xi
  64. /usr/openwin/lib
  65. )
  66. mark_as_advanced(GLUT_Xi_LIBRARY)
  67. find_library( GLUT_Xmu_LIBRARY Xmu
  68. /usr/openwin/lib
  69. )
  70. mark_as_advanced(GLUT_Xmu_LIBRARY)
  71. if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi)
  72. add_library(GLUT::Xi UNKNOWN IMPORTED)
  73. set_target_properties(GLUT::Xi PROPERTIES
  74. IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}")
  75. endif()
  76. if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu)
  77. add_library(GLUT::Xmu UNKNOWN IMPORTED)
  78. set_target_properties(GLUT::Xmu PROPERTIES
  79. IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}")
  80. endif()
  81. endif ()
  82. find_path( GLUT_INCLUDE_DIR GL/glut.h
  83. /usr/include/GL
  84. /usr/openwin/share/include
  85. /usr/openwin/include
  86. /opt/graphics/OpenGL/include
  87. /opt/graphics/OpenGL/contrib/libglut
  88. ${_GLUT_INC_DIR}
  89. )
  90. find_library( GLUT_glut_LIBRARY glut
  91. /usr/openwin/lib
  92. ${_GLUT_glut_LIB_DIR}
  93. )
  94. mark_as_advanced(GLUT_glut_LIBRARY)
  95. unset(_GLUT_INC_DIR)
  96. unset(_GLUT_glut_LIB_DIR)
  97. endif ()
  98. endif ()
  99. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  100. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
  101. if (GLUT_FOUND)
  102. # Is -lXi and -lXmu required on all platforms that have it?
  103. # If not, we need some way to figure out what platform we are on.
  104. set( GLUT_LIBRARIES
  105. ${GLUT_glut_LIBRARY}
  106. )
  107. foreach(v GLUT_Xmu_LIBRARY GLUT_Xi_LIBRARY GLUT_cocoa_LIBRARY)
  108. if(${v})
  109. list(APPEND GLUT_LIBRARIES ${${v}})
  110. endif()
  111. endforeach()
  112. if(NOT TARGET GLUT::GLUT)
  113. add_library(GLUT::GLUT UNKNOWN IMPORTED)
  114. set_target_properties(GLUT::GLUT PROPERTIES
  115. INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIR}")
  116. if(GLUT_glut_LIBRARY MATCHES "/([^/]+)\\.framework$")
  117. set_target_properties(GLUT::GLUT PROPERTIES
  118. IMPORTED_LOCATION "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}")
  119. else()
  120. if(GLUT_glut_LIBRARY_RELEASE)
  121. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  122. IMPORTED_CONFIGURATIONS RELEASE)
  123. set_target_properties(GLUT::GLUT PROPERTIES
  124. IMPORTED_LOCATION_RELEASE "${GLUT_glut_LIBRARY_RELEASE}")
  125. endif()
  126. if(GLUT_glut_LIBRARY_DEBUG)
  127. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  128. IMPORTED_CONFIGURATIONS DEBUG)
  129. set_target_properties(GLUT::GLUT PROPERTIES
  130. IMPORTED_LOCATION_DEBUG "${GLUT_glut_LIBRARY_DEBUG}")
  131. endif()
  132. if(NOT GLUT_glut_LIBRARY_RELEASE AND NOT GLUT_glut_LIBRARY_DEBUG)
  133. set_property(TARGET GLUT::GLUT APPEND PROPERTY
  134. IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
  135. endif()
  136. endif()
  137. if(TARGET GLUT::Xmu)
  138. set_property(TARGET GLUT::GLUT APPEND
  139. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu)
  140. endif()
  141. if(TARGET GLUT::Xi)
  142. set_property(TARGET GLUT::GLUT APPEND
  143. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi)
  144. endif()
  145. if(TARGET GLUT::Cocoa)
  146. set_property(TARGET GLUT::GLUT APPEND
  147. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa)
  148. endif()
  149. endif()
  150. #The following deprecated settings are for backwards compatibility with CMake1.4
  151. set (GLUT_LIBRARY ${GLUT_LIBRARIES})
  152. set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
  153. endif()
  154. mark_as_advanced(GLUT_INCLUDE_DIR)