FindGLUT.cmake 4.9 KB

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