1# -*- mode: autoconf -*- 2# 3# AX_CHECK_GL 4# 5# Check for an OpenGL implementation. If GL is found, the required compiler 6# and linker flags are included in the output variables "GL_CFLAGS" and 7# "GL_LIBS", respectively. If no usable GL implementation is found, "no_gl" 8# is set to "yes". 9# 10# If the header "GL/gl.h" is found, "HAVE_GL_GL_H" is defined. If the header 11# "OpenGL/gl.h" is found, HAVE_OPENGL_GL_H is defined. These preprocessor 12# definitions may not be mutually exclusive. 13# 14# version: 2.6 15# author: Braden McDaniel <braden@endoframe.com> 16# 17# This program is free software; you can redistribute it and/or modify 18# it under the terms of the GNU General Public License as published by 19# the Free Software Foundation; either version 2, or (at your option) 20# any later version. 21# 22# This program is distributed in the hope that it will be useful, 23# but WITHOUT ANY WARRANTY; without even the implied warranty of 24# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25# GNU General Public License for more details. 26# 27# You should have received a copy of the GNU General Public License 28# along with this program; if not, write to the Free Software 29# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 30# 02110-1301, USA. 31# 32# As a special exception, the you may copy, distribute and modify the 33# configure scripts that are the output of Autoconf when processing 34# the Macro. You need not follow the terms of the GNU General Public 35# License when using or distributing such scripts. 36# 37AC_DEFUN([AX_CHECK_GL], 38[AC_REQUIRE([AC_CANONICAL_HOST])dnl 39AC_REQUIRE([AC_PATH_X])dnl 40AC_REQUIRE([AC_PROG_SED])dnl 41AC_REQUIRE([AX_PTHREAD])dnl 42 43AC_LANG_PUSH([C]) 44AX_LANG_COMPILER_MS 45AS_IF([test X$ax_compiler_ms = Xno], 46 [GL_CFLAGS="${PTHREAD_CFLAGS}"; GL_LIBS="${PTHREAD_LIBS}"]) 47 48# 49# Use x_includes and x_libraries if they have been set (presumably by 50# AC_PATH_X). 51# 52AS_IF([test X$no_x != Xyes -a -n "$x_includes"], 53 [GL_CFLAGS="-I$x_includes $GL_CFLAGS"]) 54 55AC_CHECK_HEADERS([windows.h]) 56 57ax_save_CPPFLAGS=$CPPFLAGS 58CPPFLAGS="$GL_CFLAGS $CPPFLAGS" 59AC_CHECK_HEADERS([GL/gl.h OpenGL/gl.h], , , [ 60# if defined(HAVE_WINDOWS_H) && defined(_WIN32) 61# include <windows.h> 62# endif 63]) 64CPPFLAGS=$ax_save_CPPFLAGS 65 66m4_define([AX_CHECK_GL_PROGRAM], 67 [AC_LANG_PROGRAM([[ 68# if defined(HAVE_WINDOWS_H) && defined(_WIN32) 69# include <windows.h> 70# endif 71# ifdef HAVE_GL_GL_H 72# include <GL/gl.h> 73# elif defined(HAVE_OPENGL_GL_H) 74# include <OpenGL/gl.h> 75# else 76# error no gl.h 77# endif]], 78 [[glBegin(0)]])]) 79 80m4_define([AX_CHECK_GL_GLX_PROGRAM], 81 [AC_LANG_PROGRAM([[ 82# if defined(HAVE_WINDOWS_H) && defined(_WIN32) 83# include <windows.h> 84# endif 85# ifdef HAVE_GL_GL_H 86# include <GL/gl.h> 87# elif defined(HAVE_OPENGL_GL_H) 88# include <OpenGL/gl.h> 89# else 90# error no gl.h 91# endif]], 92 [[glXQueryVersion(0, 0, 0)]])]) 93 94AC_CACHE_CHECK([for OpenGL library], [ax_cv_check_gl_libgl], 95[ax_cv_check_gl_libgl=no 96case $host_cpu in 97 x86_64) ax_check_gl_libdir=lib64 ;; 98 *) ax_check_gl_libdir=lib ;; 99esac 100ax_save_CPPFLAGS=$CPPFLAGS 101CPPFLAGS="$CPPFLAGS $GL_CFLAGS" 102AS_IF([test X$no_x != Xyes -a -n "$x_libraries"], 103 [LDFLAGS="$LDFLAGS -L$x_libraries"]) 104ax_save_LDFLAGS=$LDFLAGS 105ax_save_LIBS=$LIBS 106ax_check_libs="-lopengl32 -lGL" 107for ax_lib in $ax_check_libs; do 108 AS_IF([test X$ax_compiler_ms = Xyes], 109 [ax_try_lib=`echo $ax_lib | $SED -e 's/^-l//' -e 's/$/.lib/'`], 110 [ax_try_lib=$ax_lib]) 111 LDFLAGS="$ax_save_LDFLAGS $GL_LIBS" 112 LIBS="$ax_try_lib $ax_save_LIBS" 113AC_LINK_IFELSE([AX_CHECK_GL_PROGRAM], 114 [ax_cv_check_gl_libgl=$ax_try_lib; break], 115 [ax_check_gl_nvidia_flags="-L/usr/$ax_check_gl_libdir/nvidia" 116 LDFLAGS="$ax_save_LDFLAGS $GL_LIBS $ax_check_gl_nvidia_flags" 117 AC_LINK_IFELSE([AX_CHECK_GL_PROGRAM], 118 [ax_cv_check_gl_libgl="$ax_check_gl_nvidia_flags $ax_try_lib"; break], 119 [ax_check_gl_dylib_flag='-dylib_file /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib' 120 LDFLAGS="$ax_save_LDFLAGS $GL_LIBS $ax_check_gl_dylib_flag" 121 AC_LINK_IFELSE([AX_CHECK_GL_PROGRAM], 122 [ax_cv_check_gl_libgl="$ax_check_gl_dylib_flag $ax_try_lib"; break])])]) 123done 124 125# 126# If no_x is "yes", we don't want to wind up using a libGL that is 127# linked with X11. Test to see if the found libGL includes GLX 128# functions. If it does and no_x is "yes", we want to reset 129# ax_cv_check_gl_libgl back to "no". 130# 131# Note that LDFLAGS and LIBS should still have whatever values they 132# had when we broke out of the test loop above; use that. 133# 134AS_IF([test "X$ax_cv_check_gl_libgl" != Xno], 135 [AC_LINK_IFELSE([AX_CHECK_GL_GLX_PROGRAM], 136 [AS_IF([test X$no_x = Xyes], 137 [ax_cv_check_gl_libgl=no])])]) 138 139LIBS=$ax_save_LIBS 140AS_IF([test "X$ax_cv_check_gl_libgl" = Xno -a X$no_x = Xyes], 141 [LDFLAGS="$ax_save_LDFLAGS -framework OpenGL" 142 AC_LINK_IFELSE([AX_CHECK_GL_PROGRAM], 143 [ax_cv_check_gl_libgl='-framework OpenGL'])]) 144 145LDFLAGS=$ax_save_LDFLAGS 146CPPFLAGS=$ax_save_CPPFLAGS]) 147 148AS_IF([test "X$ax_cv_check_gl_libgl" = Xno], 149 [no_gl=yes; GL_CFLAGS=""; GL_LIBS=""], 150 [GL_LIBS="$ax_cv_check_gl_libgl $GL_LIBS"]) 151AC_LANG_POP([C]) 152 153AC_SUBST([GL_CFLAGS]) 154AC_SUBST([GL_LIBS]) 155])dnl 156