1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_check_glu.html
3 # ===========================================================================
11 # Check for GLU. If GLU is found, the required preprocessor and linker
12 # flags are included in the output variables "GLU_CFLAGS" and "GLU_LIBS",
13 # respectively. If no GLU implementation is found, "no_glu" is set to
16 # If the header "GL/glu.h" is found, "HAVE_GL_GLU_H" is defined. If the
17 # header "OpenGL/glu.h" is found, HAVE_OPENGL_GLU_H is defined. These
18 # preprocessor definitions may not be mutually exclusive.
20 # You should use something like this in your headers:
22 # # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
23 # # include <windows.h>
25 # # if defined(HAVE_GL_GLU_H)
26 # # include <GL/glu.h>
27 # # elif defined(HAVE_OPENGL_GLU_H)
28 # # include <OpenGL/glu.h>
33 # Some implementations (in particular, some versions of Mac OS X) are
34 # known to treat the GLU tesselator callback function type as "GLvoid
35 # (*)(...)" rather than the standard "GLvoid (*)()". If the former
36 # condition is detected, this macro defines "HAVE_VARARGS_GLU_TESSCB".
40 # Copyright (c) 2009 Braden McDaniel <braden@endoframe.com>
41 # Copyright (c) 2013 Bastien Roucaries <roucaries.bastien+autoconf@gmail.com>
43 # This program is free software; you can redistribute it and/or modify it
44 # under the terms of the GNU General Public License as published by the
45 # Free Software Foundation; either version 2 of the License, or (at your
46 # option) any later version.
48 # This program is distributed in the hope that it will be useful, but
49 # WITHOUT ANY WARRANTY; without even the implied warranty of
50 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
51 # Public License for more details.
53 # You should have received a copy of the GNU General Public License along
54 # with this program. If not, see <http://www.gnu.org/licenses/>.
56 # As a special exception, the respective Autoconf Macro's copyright owner
57 # gives unlimited permission to copy, distribute and modify the configure
58 # scripts that are the output of Autoconf when processing the Macro. You
59 # need not follow the terms of the GNU General Public License when using
60 # or distributing such scripts, even though portions of the text of the
61 # Macro appear in them. The GNU General Public License (GPL) does govern
62 # all other use of the material that constitutes the Autoconf Macro.
64 # This special exception to the GPL applies to versions of the Autoconf
65 # Macro released by the Autoconf Archive. When you make and distribute a
66 # modified version of the Autoconf Macro, you may extend this special
67 # exception to the GPL to apply to your modified version as well.
72 m4_define([_AX_CHECK_GLU_PROGRAM],
74 # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
79 # elif defined(HAVE_OPENGL_GLU_H)
80 # include <OpenGL/glu.h>
84 ]],[[gluBeginCurve(0)]])])
87 dnl Default include : add windows.h
88 dnl see http://www.opengl.org/wiki/Platform_specifics:_Windows
89 dnl (acceded 20120801)
90 AC_DEFUN([_AX_CHECK_GLU_INCLUDES_DEFAULT],dnl
94 # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
101 AC_DEFUN([_AX_CHECK_GLU_SAVE_FLAGS],
103 ax_check_glu_saved_libs="${LIBS}"
104 ax_check_glu_saved_cflags="${CFLAGS}"
105 ax_check_glu_saved_cppflags="${CPPFLAGS}"
106 ax_check_glu_saved_ldflags="${LDFLAGS}"
110 dnl local restore flags
111 AC_DEFUN([_AX_CHECK_GLU_RESTORE_FLAGS],
113 LIBS="${ax_check_glu_saved_libs}"
114 CFLAGS="${ax_check_glu_saved_cflags}"
115 CPPFLAGS="${ax_check_glu_saved_cppflags}"
116 LDFLAGS="${ax_check_glu_saved_ldflags}"
120 # compile the example program
121 AC_DEFUN([_AX_CHECK_GLU_COMPILE],
124 _AX_CHECK_GLU_SAVE_FLAGS()
125 CFLAGS="${GLU_CFLAGS} ${CFLAGS}"
126 AC_COMPILE_IFELSE([_AX_CHECK_GLU_PROGRAM],
127 [ax_check_glu_compile_opengl="yes"],
128 [ax_check_glu_compile_opengl="no"])
129 _AX_CHECK_GLU_RESTORE_FLAGS()
133 # compile the example program (cache)
134 AC_DEFUN([_AX_CHECK_GLU_COMPILE_CV],
136 AC_CACHE_CHECK([for compiling a minimal OpenGL Utility (GLU) program],[ax_cv_check_glu_compile_opengl],
137 [_AX_CHECK_GLU_COMPILE()
138 ax_cv_check_glu_compile_opengl="${ax_check_glu_compile_opengl}"])
139 ax_check_glu_compile_opengl="${ax_cv_check_glu_compile_opengl}"
142 # link the example program
143 AC_DEFUN([_AX_CHECK_GLU_LINK],
146 _AX_CHECK_GLU_SAVE_FLAGS()
147 CFLAGS="${GLU_CFLAGS} ${CFLAGS}"
148 LIBS="${GLU_LIBS} ${LIBS}"
149 LDFLAGS="${GLU_LDFLAGS} ${LDFLAGS}"
150 AC_LINK_IFELSE([_AX_CHECK_GLU_PROGRAM],
151 [ax_check_glu_link_opengl="yes"],
152 [ax_check_glu_link_opengl="no"])
153 _AX_CHECK_GLU_RESTORE_FLAGS()
157 # link the example program (cache)
158 AC_DEFUN([_AX_CHECK_GLU_LINK_CV],
160 AC_CACHE_CHECK([for linking a minimal OpenGL Utility (GLU) program],[ax_cv_check_glu_link_opengl],
161 [_AX_CHECK_GLU_LINK()
162 ax_cv_check_glu_link_opengl="${ax_check_glu_link_opengl}"])
163 ax_check_glu_link_opengl="${ax_cv_check_glu_link_opengl}"
166 dnl Check headers manually (default case)
167 AC_DEFUN([_AX_CHECK_GLU_HEADERS],
169 _AX_CHECK_GLU_SAVE_FLAGS()
170 CFLAGS="${GLU_CFLAGS} ${CFLAGS}"
171 # see comment in _AX_CHECK_GL_INCLUDES_DEFAULT
172 AC_CHECK_HEADERS([windows.h],[],[],[AC_INCLUDES_DEFAULT])
173 AC_CHECK_HEADERS([GL/glu.h OpenGL/glu.h],
174 [ax_check_glu_have_headers="yes";break],
175 [ax_check_glu_have_headers_headers="no"],
176 [_AX_CHECK_GLU_INCLUDES_DEFAULT()])
177 # do not try darwin specific OpenGl/gl.h
178 _AX_CHECK_GLU_RESTORE_FLAGS()
182 # check tesselation callback function signature.
183 m4_define([_AX_CHECK_GLU_VARARGS_TESSVB_PROGRAM],
185 # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
186 # include <windows.h>
188 # ifdef HAVE_GL_GLU_H
190 # elif defined(HAVE_OPENGL_GLU_H)
191 # include <OpenGL/glu.h>
196 [[GLvoid (*func)(...); gluTessCallback(0, 0, func)]])
199 # compile the tesselation callback function program
201 AC_DEFUN([_AX_CHECK_GLU_COMPILE_VARARGS_TESSVB_PROGRAM],
202 [AC_REQUIRE([AC_PROG_CXX])dnl
205 _AX_CHECK_GLU_SAVE_FLAGS()
206 CFLAGS="${GLU_CFLAGS} ${CFLAGS}"
207 AC_COMPILE_IFELSE([_AX_CHECK_GLU_VARARGS_TESSVB_PROGRAM],
208 [ax_check_glu_compile_varargs_tessvb_program="yes"],
209 [ax_check_glu_compile_varargs_tessvb_program="no"])
210 _AX_CHECK_GLU_RESTORE_FLAGS()
216 # Some versions of Mac OS X include a broken interpretation of the GLU
217 # tesselation callback function signature.
219 AC_DEFUN([_AX_CHECK_GLU_VARARGS_TESSVB],
221 AC_CACHE_CHECK([for varargs OpenGL Utility (GLU) tesselator callback function type],
222 [ax_cv_varargs_glu_tesscb],
223 [_AX_CHECK_GLU_COMPILE_VARARGS_TESSVB_PROGRAM
224 ax_cv_varargs_glu_tesscb="${ax_check_glu_compile_varargs_tessvb_program}"])
225 ax_check_glu_compile_varargs_tessvb_program="${ax_cv_varargs_glu_tesscb}"
227 AS_IF([test X$ax_cv_varargs_glu_tesscb = Xyes],
228 [AC_DEFINE([HAVE_VARARGS_GLU_TESSCB], [1],
229 [Use nonstandard varargs form for the GLU tesselator callback])])
233 # dnl try to found library (generic case)
234 # dnl $1 is set to the library to found
235 AC_DEFUN([_AX_CHECK_GLU_MANUAL_LIBS_GENERIC],
237 ax_check_glu_manual_libs_generic_extra_libs="$1"
238 AS_IF([test "X$ax_check_glu_manual_libs_generic_extra_libs" = "X"],
239 [AC_MSG_ERROR([AX_CHECK_GLU_MANUAL_LIBS_GENERIC argument must no be empty])])
242 _AX_CHECK_GLU_SAVE_FLAGS()
243 CFLAGS="${GLU_CFLAGS} ${CFLAGS}"
244 LIBS="${GLU_LIBS} ${LIBS}"
245 AC_SEARCH_LIBS([gluBeginCurve],[$ax_check_glu_manual_libs_generic_extra_libs],
246 [ax_check_glu_lib_opengl="yes"],
247 [ax_check_glu_lib_opengl="no"])
248 AS_CASE([$ac_cv_search_gluBeginCurve],
249 ["none required"],[],
251 [GLU_LIBS="${ac_cv_search_gluBeginCurve} ${GLU_LIBS}"])
252 _AX_CHECK_GLU_RESTORE_FLAGS()
257 dnl Check library manually: subroutine must set
258 dnl $ax_check_gl_lib_opengl={yes,no}
259 AC_DEFUN([_AX_CHECK_GLU_MANUAL_LIBS],
260 [AC_REQUIRE([AC_CANONICAL_HOST])
261 GLU_LIBS="${GLU_LIBS} ${GL_LIBS}"
263 # try first cygwin version
264 [*-cygwin*],[_AX_CHECK_GLU_MANUAL_LIBS_GENERIC([GLU glu MesaGLU glu32])],
266 [*-mingw*],[_AX_CHECK_GLU_MANUAL_LIBS_GENERIC([glu32 GLU glu MesaGLU])],
267 [_AX_CHECK_GLU_MANUAL_LIBS_GENERIC([GLU glu MesaGLU])])
269 AC_CACHE_CHECK([for OpenGL Utility (GLU) libraries],[ax_cv_check_glu_lib_opengl],
270 [ax_cv_check_glu_lib_opengl="${ax_check_glu_lib_opengl}"])
271 ax_check_glu_lib_opengl="${ax_cv_check_glu_lib_opengl}"
275 dnl Manual way to detect GLU
276 AC_DEFUN([_AX_CHECK_GLU_MANUAL],
280 GLU_CFLAGS="${GLU_CFLAGS} ${GL_CFLAGS}"
283 _AX_CHECK_GLU_HEADERS
285 AS_IF([test "X$ax_check_glu_have_headers" = "Xyes"],
286 [_AX_CHECK_GLU_MANUAL_LIBS],
287 [ax_check_glu_lib_opengl="no"])
289 AS_IF([test "X$ax_check_glu_lib_opengl" = "Xyes"],
290 [_AX_CHECK_GLU_COMPILE_CV()],
291 [ax_cv_check_glu_compile_opengl="no"])
293 AS_IF([test "X$ax_cv_check_glu_compile_opengl" = "Xyes"],
294 [_AX_CHECK_GLU_LINK_CV()],
295 [ax_cv_check_glu_link_opengl="no"])
297 AS_IF([test "X$ax_cv_check_glu_link_opengl" = "Xyes"],
302 # detect using pkgconfig
303 AC_DEFUN([_AX_CHECK_GLU_PKG_CONFIG],
305 AC_REQUIRE([PKG_PROG_PKG_CONFIG])
307 PKG_CHECK_MODULES([GLU],[glu],[ax_check_glu_pkg_config=yes],[ax_check_glu_pkg_config=no])
309 AS_IF([test "X$ax_check_glu_pkg_config" = "Xyes"],[
312 _AX_CHECK_GLU_SAVE_FLAGS()
313 CFLAGS="${GLU_CFLAGS} ${CFLAGS}"
314 AC_CHECK_HEADERS([windows.h],[],[],[AC_INCLUDES_DEFAULT])
315 AC_CHECK_HEADERS([GL/glu.h OpenGL/glu.h],
316 [ax_check_glu_have_headers="yes";break],
317 [ax_check_glu_have_headers_headers="no"],
318 [_AX_CHECK_GLU_INCLUDES_DEFAULT()])
319 _AX_CHECK_GL_RESTORE_FLAGS()
321 AC_CACHE_CHECK([for OpenGL Utility (GLU) headers],[ax_cv_check_glu_have_headers],
322 [ax_cv_check_glu_have_headers="${ax_check_glu_have_headers}"])
324 # pkgconfig library are suposed to work ...
325 AS_IF([test "X$ax_cv_check_glu_have_headers" = "Xno"],
326 [AC_MSG_ERROR("Pkgconfig detected OpenGL Utility (GLU) library has no headers!")])
328 _AX_CHECK_GLU_COMPILE_CV()
329 AS_IF([test "X$ax_cv_check_glu_compile_opengl" = "Xno"],
330 [AC_MSG_ERROR("Pkgconfig detected OpenGL Utility (GLU) library could not be used for compiling minimal program!")])
332 _AX_CHECK_GLU_LINK_CV()
333 AS_IF([test "X$ax_cv_check_glu_link_opengl" = "Xno"],
334 [AC_MSG_ERROR("Pkgconfig detected OpenGL Utility (GLU) library could not be used for linking minimal program!")])
339 AC_DEFUN([AX_CHECK_GLU],dnl
341 AC_REQUIRE([AX_CHECK_GL])
342 AC_REQUIRE([PKG_PROG_PKG_CONFIG])
347 AC_MSG_CHECKING([for a working OpenGL Utility (GLU) implementation by pkg-config])
348 # try first pkgconfig
349 AS_IF([test "X${PKG_CONFIG}" = "X"],
351 ax_check_glu_pkg_config=no],
352 [AC_MSG_RESULT([yes])
353 _AX_CHECK_GLU_PKG_CONFIG()])
355 # if no pkg-config or pkg-config fail try manual way
356 AS_IF([test "X$ax_check_glu_pkg_config" = "Xno"],
357 [_AX_CHECK_GLU_MANUAL()],
360 # check broken implementation
361 AS_IF([test "X$no_glu" = "Xno"],
362 [_AX_CHECK_GLU_VARARGS_TESSVB],[])
364 AC_MSG_CHECKING([for a working OpenGL Utility (GLU) implementation])
365 AS_IF([test "X$no_glu" = "Xno"],
366 [AC_MSG_RESULT([yes])
367 AC_MSG_CHECKING([for CFLAGS needed for OpenGL Utility (GLU)])
368 AC_MSG_RESULT(["${GLU_CFLAGS}"])
369 AC_MSG_CHECKING([for LIBS needed for OpenGL Utility (GLU)])
370 AC_MSG_RESULT(["${GLU_LIBS}"])
371 AC_MSG_CHECKING([for LDFLAGS needed for OpenGL Utility (GLU)])
372 AC_MSG_RESULT(["${GLU_LDFLAGS}"])],
378 AC_SUBST([GLU_CFLAGS])
380 AC_SUBST([GLU_LDFLAGS])