FindGLUT.cmake 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #
  7. # try to find glut library and include files.
  8. #
  9. # IMPORTED Targets
  10. # ^^^^^^^^^^^^^^^^
  11. #
  12. # This module defines the :prop_tgt:`IMPORTED` targets:
  13. #
  14. # ``GLUT::GLUT``
  15. # Defined if the system has GLUT.
  16. #
  17. # Result Variables
  18. # ^^^^^^^^^^^^^^^^
  19. #
  20. # This module sets the following variables:
  21. #
  22. # ::
  23. #
  24. # GLUT_INCLUDE_DIR, where to find GL/glut.h, etc.
  25. # GLUT_LIBRARIES, the libraries to link against
  26. # GLUT_FOUND, If false, do not try to use GLUT.
  27. #
  28. # Also defined, but not for general use are:
  29. #
  30. # ::
  31. #
  32. # GLUT_glut_LIBRARY = the full path to the glut library.
  33. # GLUT_Xmu_LIBRARY = the full path to the Xmu library.
  34. # GLUT_Xi_LIBRARY = the full path to the Xi Library.
  35. if (WIN32)
  36. find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
  37. PATHS ${GLUT_ROOT_PATH}/include )
  38. find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut
  39. PATHS
  40. ${OPENGL_LIBRARY_DIR}
  41. ${GLUT_ROOT_PATH}/Release
  42. )
  43. else ()
  44. if (APPLE)
  45. find_path(GLUT_INCLUDE_DIR glut.h ${OPENGL_LIBRARY_DIR})
  46. find_library(GLUT_glut_LIBRARY GLUT DOC "GLUT library for OSX")
  47. find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX")
  48. if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa)
  49. add_library(GLUT::Cocoa UNKNOWN IMPORTED)
  50. # Cocoa should always be a Framework, but we check to make sure.
  51. if(GLUT_cocoa_LIBRARY MATCHES "/([^/]+)\\.framework$")
  52. set_target_properties(GLUT::Cocoa PROPERTIES
  53. IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}/${CMAKE_MATCH_1}")
  54. else()
  55. set_target_properties(GLUT::Cocoa PROPERTIES
  56. IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}")
  57. endif()
  58. endif()
  59. else ()
  60. if (BEOS)
  61. set(_GLUT_INC_DIR /boot/develop/headers/os/opengl)
  62. set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86)
  63. else()
  64. find_library( GLUT_Xi_LIBRARY Xi
  65. /usr/openwin/lib
  66. )
  67. find_library( GLUT_Xmu_LIBRARY Xmu
  68. /usr/openwin/lib
  69. )
  70. if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi)
  71. add_library(GLUT::Xi UNKNOWN IMPORTED)
  72. set_target_properties(GLUT::Xi PROPERTIES
  73. IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}")
  74. endif()
  75. if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu)
  76. add_library(GLUT::Xmu UNKNOWN IMPORTED)
  77. set_target_properties(GLUT::Xmu PROPERTIES
  78. IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}")
  79. endif()
  80. endif ()
  81. find_path( GLUT_INCLUDE_DIR GL/glut.h
  82. /usr/include/GL
  83. /usr/openwin/share/include
  84. /usr/openwin/include
  85. /opt/graphics/OpenGL/include
  86. /opt/graphics/OpenGL/contrib/libglut
  87. ${_GLUT_INC_DIR}
  88. )
  89. find_library( GLUT_glut_LIBRARY glut
  90. /usr/openwin/lib
  91. ${_GLUT_glut_LIB_DIR}
  92. )
  93. unset(_GLUT_INC_DIR)
  94. unset(_GLUT_glut_LIB_DIR)
  95. endif ()
  96. endif ()
  97. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  98. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
  99. if (GLUT_FOUND)
  100. # Is -lXi and -lXmu required on all platforms that have it?
  101. # If not, we need some way to figure out what platform we are on.
  102. set( GLUT_LIBRARIES
  103. ${GLUT_glut_LIBRARY}
  104. )
  105. foreach(v GLUT_Xmu_LIBRARY GLUT_Xi_LIBRARY GLUT_cocoa_LIBRARY)
  106. if(${v})
  107. list(APPEND GLUT_LIBRARIES ${${v}})
  108. endif()
  109. endforeach()
  110. if(NOT TARGET GLUT::GLUT)
  111. add_library(GLUT::GLUT UNKNOWN IMPORTED)
  112. set_target_properties(GLUT::GLUT PROPERTIES
  113. INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIR}")
  114. if(GLUT_glut_LIBRARY MATCHES "/([^/]+)\\.framework$")
  115. set_target_properties(GLUT::GLUT PROPERTIES
  116. IMPORTED_LOCATION "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}")
  117. else()
  118. set_target_properties(GLUT::GLUT PROPERTIES
  119. IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
  120. endif()
  121. if(TARGET GLUT::Xmu)
  122. set_property(TARGET GLUT::GLUT APPEND
  123. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu)
  124. endif()
  125. if(TARGET GLUT::Xi)
  126. set_property(TARGET GLUT::GLUT APPEND
  127. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi)
  128. endif()
  129. if(TARGET GLUT::Cocoa)
  130. set_property(TARGET GLUT::GLUT APPEND
  131. PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa)
  132. endif()
  133. endif()
  134. #The following deprecated settings are for backwards compatibility with CMake1.4
  135. set (GLUT_LIBRARY ${GLUT_LIBRARIES})
  136. set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
  137. endif()
  138. mark_as_advanced(
  139. GLUT_INCLUDE_DIR
  140. GLUT_glut_LIBRARY
  141. GLUT_Xmu_LIBRARY
  142. GLUT_Xi_LIBRARY
  143. )