1# - try to find glut library and include files
2#  GLUT_INCLUDE_DIRS, where to find GL/glut.h, etc.
3#  GLUT_LIBRARIES, the libraries to link against
4#  GLUT_FOUND, If false, do not try to use GLUT.
5#  GLUT_RUNTIME_LIBRARY_DIRS, path to DLL on Windows for runtime use.
6#  GLUT_RUNTIME_LIBRARY, dll on Windows, for installation purposes
7#
8# Also defined, but not for general use are:
9#  GLUT_INCLUDE_DIR, where to find GL/glut.h, etc.
10#  GLUT_glut_LIBRARY = the full path to the glut library.
11
12#=============================================================================
13# Copyright 2001-2009 Kitware, Inc.
14# Copyright 2009-2010 Iowa State University
15#                     (Author: Ryan Pavlik <abiryan@ryand.net> )
16#
17# Distributed under the OSI-approved BSD License (the "License");
18# see below.
19#
20# This software is distributed WITHOUT ANY WARRANTY; without even the
21# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22# See the License for more information.
23#=============================================================================
24#
25# Redistribution and use in source and binary forms, with or without
26# modification, are permitted provided that the following conditions
27# are met:
28#
29# * Redistributions of source code must retain the above copyright
30#   notice, this list of conditions and the following disclaimer.
31#
32# * Redistributions in binary form must reproduce the above copyright
33#   notice, this list of conditions and the following disclaimer in the
34#   documentation and/or other materials provided with the distribution.
35#
36# * Neither the names of Kitware, Inc., the Insight Software Consortium,
37#   nor the names of their contributors may be used to endorse or promote
38#   products derived from this software without specific prior written
39#   permission.
40#
41# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
42# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
43# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
44# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
45# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
48# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
49# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
51# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52#=============================================================================
53
54if(GLUT_FIND_QUIETLY)
55	find_package(OpenGL QUIET)
56else()
57	find_package(OpenGL)
58endif()
59
60if(OPENGL_FOUND)
61	get_filename_component(_ogl_libdir ${OPENGL_gl_LIBRARY} PATH)
62	find_path(GLUT_INCLUDE_DIR
63		NAMES
64		GL/glut.h
65		GLUT/glut.h
66		glut.h
67		PATHS
68		${_ogl_libdir}/../include
69		${GLUT_ROOT_PATH}
70		${GLUT_ROOT_PATH}/include
71		/usr/include/GL
72		/usr/openwin/share/include
73		/usr/openwin/include
74		/opt/graphics/OpenGL/include
75		/opt/graphics/OpenGL/contrib/libglut)
76
77	find_library(GLUT_glut_LIBRARY
78		NAMES
79		glut
80		glut32
81		GLUT
82		freeglut
83		PATHS
84		${_ogl_libdir}
85		${GLUT_ROOT_PATH}
86		${GLUT_ROOT_PATH}/Release
87		/usr/openwin/lib)
88
89endif()
90
91# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
92# all listed variables are TRUE
93include(FindPackageHandleStandardArgs)
94find_package_handle_standard_args(GLUT
95	DEFAULT_MSG
96	GLUT_glut_LIBRARY
97	GLUT_INCLUDE_DIR
98	OPENGL_FOUND)
99
100if(GLUT_FOUND)
101	set(GLUT_LIBRARIES ${GLUT_glut_LIBRARY} ${OPENGL_LIBRARIES})
102	set(GLUT_INCLUDE_DIRS ${GLUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
103
104	if(WIN32)
105		get_filename_component(_basename "${GLUT_glut_LIBRARY}" NAME_WE)
106		get_filename_component(_libpath "${GLUT_glut_LIBRARY}" PATH)
107		find_path(GLUT_RUNTIME_LIBRARY
108			NAMES
109			${_basename}.dll
110			glut.dll
111			glut32.dll
112			freeglut.dll
113			HINTS
114			${_libpath}
115			${_libpath}/../bin)
116		if(GLUT_RUNTIME_LIBRARY)
117			get_filename_component(GLUT_RUNTIME_LIBRARY_DIRS
118				"${GLUT_RUNTIME_LIBRARY}"
119				PATH)
120		else()
121			set(GLUT_RUNTIME_LIBRARY_DIRS)
122		endif()
123	endif()
124
125	#The following deprecated settings are for backwards compatibility with CMake1.4
126	set(GLUT_LIBRARY ${GLUT_LIBRARIES})
127	set(GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
128endif()
129
130mark_as_advanced(GLUT_INCLUDE_DIR
131	GLUT_glut_LIBRARY
132	GLUT_RUNTIME_LIBRARY)
133