Macro: ax_check_gl

Back to the Main Page. | # ax_check_gl | Download the M4 Source.

Synopsis

  `AX_CHECK_GL`

Version

  1.1 (2003/01/07) braden @ ac-archive-0.5.39

Author

  Braden McDaniel <braden@endoframe.com>

Description

  Check for OpenGL/Mesa. Succeeds if both GL and GLU are found. If it succeeds, the required linker flags are included in the output variable "GL_LIBS". If the headers "GL/gl.h" and "GL/glu.h" are found, the symbols HAVE_GL_GL_H and HAVE_GL_GLU_H are defined, respectively. Otherwise, if "OpenGL/gl.h" and "OpenGL/glu.h" are found, HAVE_OPENGL_GL_H and HAVE_OPENGL_GLU_H are defined. If neither OpenGL nor Mesa is found, "no_gl" is set to "yes".

  @copyright (C) 2003 Braden McDaniel @license GNU GPL

M4 Source Code

      AC_DEFUN([AX_CHECK_GL],
      [AC_REQUIRE([AC_PATH_X])dnl
      AC_REQUIRE([ACX_PTHREAD])dnl
      GL_CFLAGS="${PTHREAD_CFLAGS}"
      GL_LIBS="${PTHREAD_LIBS} -lm"

      #
      # Use x_includes and x_libraries if they have been set (presumably by
      # AC_PATH_X).
      #
      if test "X$no_x" != "Xyes"; then
        if test -n "$x_includes"; then
          GL_CFLAGS="-I${x_includes} ${GL_CFLAGS}"
        fi
        if test -n "$x_libraries"; then
          GL_LIBS="-L${x_libraries} ${GL_LIBS}"
        fi
      fi

      AC_LANG_PUSH(C)

      ax_save_CPPFLAGS="${CPPFLAGS}"
      CPPFLAGS="${GL_CFLAGS} ${CPPFLAGS}"

      AC_CHECK_HEADERS([GL/gl.h OpenGL/gl.h], [break])

      AC_CACHE_CHECK([for OpenGL library], [ax_cv_check_gl_libgl],
      [ax_cv_check_gl_libgl="no"
      ax_save_LIBS="${LIBS}"
      LIBS=""
      ax_check_libs="-lopengl32 -lGL"
      for ax_lib in ${ax_check_libs}; do
       LIBS="${ax_lib} ${GL_LIBS} ${ax_save_LIBS}"
        AC_TRY_LINK([
      # ifdef _WIN32
      #   include <windows.h>
      # endif
      # ifdef HAVE_OPENGL_GL_H
      #   include <OpenGL/gl.h>
      # else
      #   include <GL/gl.h>
      # endif
      ],
        [glBegin(0)],
        [ax_cv_check_gl_libgl="${ax_lib}" break])
      done
      LIBS=${ax_save_LIBS}])

      if test "X${ax_cv_check_gl_libgl}" = "Xno"; then
        no_gl="yes"
      else
        GL_LIBS="${ax_cv_check_gl_libgl} ${GL_LIBS}"

        AC_CHECK_HEADERS([GL/glu.h OpenGL/glu.h], [break])

        AC_CACHE_CHECK([for OpenGL Utility library], [ax_cv_check_gl_libglu],
        [ax_cv_check_gl_libglu="no"
        ax_save_LIBS="${LIBS}"
        LIBS=""
        ax_check_libs="-lglu32 -lGLU"
        for ax_lib in ${ax_check_libs}; do
          LIBS="${ax_lib} ${GL_LIBS} ${ax_save_LIBS}"
          AC_LANG_PUSH([C++])
          AC_TRY_LINK([
      # ifdef _WIN32
      #   include <windows.h>
      # endif
      # ifdef HAVE_OPENGL_GLU_H
      #   include <OpenGL/glu.h>
      # else
      #   include <GL/glu.h>
      # endif
      ],
          [gluBeginCurve(0)],
          [ax_cv_check_gl_libglu="${ax_lib}" break])
          AC_LANG_POP([C++])
        done
        LIBS=${ax_save_LIBS}])
        if test "X${ax_cv_check_gl_libglu}" = "Xno"; then
          no_gl="yes"
        else
          GL_LIBS="${ax_cv_check_gl_libglu} ${GL_LIBS}"
        fi
      fi
      CPPFLAGS="${ax_save_CPPFLAGS}"
      AC_LANG_POP(C)

      AC_SUBST([GL_CFLAGS])
      AC_SUBST([GL_LIBS])
      ])dnl