Merge branch 'release-4.0'
[kiteware-cmake.git] / Modules / FindGLUT.cmake
blobb53aee86c4ccc3b8fe53bd62e5c7e607b1b57a5d
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
5 FindGLUT
6 --------
8 Find OpenGL Utility Toolkit (GLUT) library and include files.
10 Imported Targets
11 ^^^^^^^^^^^^^^^^
13 .. versionadded:: 3.1
15 This module defines the :prop_tgt:`IMPORTED` targets:
17 ``GLUT::GLUT``
18  Defined if the system has GLUT.
20 Result Variables
21 ^^^^^^^^^^^^^^^^
23 This module defines the following variables:
25 ``GLUT_FOUND``
26   True if ``glut`` was found.
28 ``GLUT_INCLUDE_DIRS``
29   .. versionadded:: 3.23
31   Where to find GL/glut.h, etc.
33 ``GLUT_LIBRARIES``
34   List of libraries for using ``glut``.
36 Cache Variables
37 ^^^^^^^^^^^^^^^
39 This module may set the following variables depending on platform.
40 These variables may optionally be set to help this module find the
41 correct files, but clients should not use these as results:
43 ``GLUT_INCLUDE_DIR``
44   The full path to the directory containing ``GL/glut.h``,
45   not including ``GL/``.
47 ``GLUT_glut_LIBRARY``
48   The full path to the glut library.
50 ``GLUT_Xmu_LIBRARY``
51   The full path to the Xmu library.
53 ``GLUT_Xi_LIBRARY``
54   The full path to the Xi Library.
56 Obsolete Variables
57 ^^^^^^^^^^^^^^^^^^
59 The following variables may also be provided, for backwards compatibility:
61 ``GLUT_INCLUDE_DIR``
62   This is one of above `Cache Variables`_, but prior to CMake 3.23 was
63   also a result variable.  Prefer to use ``GLUT_INCLUDE_DIRS`` instead
64   in CMake 3.23 and above.
65 #]=======================================================================]
67 include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
68 include(FindPackageHandleStandardArgs)
70 find_package(PkgConfig QUIET)
71 if(PKG_CONFIG_FOUND)
72   pkg_check_modules(PC_GLUT QUIET glut)
73   if(NOT PC_GLUT_FOUND)
74     pkg_check_modules(PC_GLUT QUIET freeglut)
75   endif()
76 endif()
78 if(WIN32)
79   find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
80     PATHS  ${GLUT_ROOT_PATH}/include
81     HINTS ${PC_GLUT_INCLUDE_DIRS})
82   mark_as_advanced(GLUT_INCLUDE_DIR)
83   find_library( GLUT_glut_LIBRARY_RELEASE NAMES freeglut glut glut32
84     PATHS
85     ${OPENGL_LIBRARY_DIR}
86     ${GLUT_ROOT_PATH}/Release
87     HINTS
88     ${PC_GLUT_LIBRARY_DIRS}
89     )
90 # N.B. As the pkg-config cannot distinguish between release and debug libraries,
91 # assume that their hint was the both Debug and Release library.
92   find_library( GLUT_glut_LIBRARY_DEBUG NAMES freeglutd
93     PATHS
94     ${OPENGL_LIBRARY_DIR}
95     ${GLUT_ROOT_PATH}/Debug
96     HINTS
97     ${PC_GLUT_LIBRARY_DIRS}
98     )
99   mark_as_advanced(GLUT_glut_LIBRARY_RELEASE GLUT_glut_LIBRARY_DEBUG)
100   select_library_configurations(GLUT_glut)
101 elseif(APPLE)
102   find_path(GLUT_INCLUDE_DIR glut.h PATHS ${OPENGL_LIBRARY_DIR} HINTS ${PC_GLUT_INCLUDE_DIRS})
103   mark_as_advanced(GLUT_INCLUDE_DIR)
104   find_library(GLUT_glut_LIBRARY GLUT HINTS ${PC_GLUT_LIBRARY_DIRS} DOC "GLUT library for OSX")
105   find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX")
106   mark_as_advanced(GLUT_glut_LIBRARY GLUT_cocoa_LIBRARY)
108   if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa)
109     add_library(GLUT::Cocoa UNKNOWN IMPORTED)
110     set_target_properties(GLUT::Cocoa PROPERTIES
111       IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}")
112   endif()
113 else()
114   if(BEOS)
115     set(_GLUT_INC_DIR /boot/develop/headers/os/opengl)
116     set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86)
117   else()
118     find_library( GLUT_Xi_LIBRARY Xi
119       /usr/openwin/lib
120       )
121     mark_as_advanced(GLUT_Xi_LIBRARY)
123     find_library( GLUT_Xmu_LIBRARY Xmu
124       /usr/openwin/lib
125       )
126     mark_as_advanced(GLUT_Xmu_LIBRARY)
128     if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi)
129       add_library(GLUT::Xi UNKNOWN IMPORTED)
130       set_target_properties(GLUT::Xi PROPERTIES
131         IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}")
132     endif()
134     if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu)
135       add_library(GLUT::Xmu UNKNOWN IMPORTED)
136       set_target_properties(GLUT::Xmu PROPERTIES
137         IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}")
138     endif()
140   endif ()
142   find_path( GLUT_INCLUDE_DIR GL/glut.h
143     PATHS
144     /usr/include/GL
145     /usr/openwin/share/include
146     /usr/openwin/include
147     /opt/graphics/OpenGL/include
148     /opt/graphics/OpenGL/contrib/libglut
149     ${_GLUT_INC_DIR}
150     HINTS
151     ${PC_GLUT_INCLUDE_DIRS}
152     )
153   mark_as_advanced(GLUT_INCLUDE_DIR)
155   find_library( GLUT_glut_LIBRARY glut
156     PATHS
157     /usr/openwin/lib
158     ${_GLUT_glut_LIB_DIR}
159     HINTS
160     ${PC_GLUT_LIBRARY_DIRS}
161     )
162   mark_as_advanced(GLUT_glut_LIBRARY)
164   unset(_GLUT_INC_DIR)
165   unset(_GLUT_glut_LIB_DIR)
166 endif()
168 find_package_handle_standard_args(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
170 if (GLUT_FOUND)
171   # Is -lXi and -lXmu required on all platforms that have it?
172   # If not, we need some way to figure out what platform we are on.
173   set( GLUT_LIBRARIES
174     ${GLUT_glut_LIBRARY}
175     )
176   set(GLUT_INCLUDE_DIRS
177     ${GLUT_INCLUDE_DIR}
178     )
179   foreach(v GLUT_Xmu_LIBRARY GLUT_Xi_LIBRARY GLUT_cocoa_LIBRARY)
180     if(${v})
181       list(APPEND GLUT_LIBRARIES ${${v}})
182     endif()
183   endforeach()
185   if(NOT TARGET GLUT::GLUT)
186     add_library(GLUT::GLUT UNKNOWN IMPORTED)
187     set_target_properties(GLUT::GLUT PROPERTIES
188       INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIRS}")
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()
196     if(GLUT_glut_LIBRARY_DEBUG)
197       set_property(TARGET GLUT::GLUT APPEND PROPERTY
198         IMPORTED_CONFIGURATIONS DEBUG)
199       set_target_properties(GLUT::GLUT PROPERTIES
200         IMPORTED_LOCATION_DEBUG "${GLUT_glut_LIBRARY_DEBUG}")
201     endif()
203     if(NOT GLUT_glut_LIBRARY_RELEASE AND NOT GLUT_glut_LIBRARY_DEBUG)
204       set_property(TARGET GLUT::GLUT APPEND PROPERTY
205         IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
206     endif()
208     if(TARGET GLUT::Xmu)
209       set_property(TARGET GLUT::GLUT APPEND
210         PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu)
211     endif()
213     if(TARGET GLUT::Xi)
214       set_property(TARGET GLUT::GLUT APPEND
215         PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi)
216     endif()
218     if(TARGET GLUT::Cocoa)
219       set_property(TARGET GLUT::GLUT APPEND
220         PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa)
221     endif()
222   endif()
223 endif()