Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

301 lines
11KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_check_gl.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_CHECK_GL([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
  8. #
  9. # DESCRIPTION
  10. #
  11. # Checks for an OpenGL implementation. If a valid OpenGL implementation is
  12. # found, this macro would set C preprocessor symbol HAVE_GL to 1.
  13. #
  14. # If either a valid OpenGL header or library was not found, by default the
  15. # configuration would exits on error. This behavior can be overwritten by
  16. # providing a custom "ACTION-IF-NOT-FOUND" hook.
  17. #
  18. # If the header, library was found, and been tested for compiling and
  19. # linking the configuration would export the required compiler flags to
  20. # "GL_CFLAGS" and "GL_LIBS". These two variables can also be overwritten
  21. # by user from the command line if they want to link against the library
  22. # they specified instead of having the configuration script to detect the
  23. # flags automatically. Note that having "GL_CFLAGS" or "GL_LIBS" set
  24. # doesn't mean it can compile or link with the flags, since it could be
  25. # overwritten by user. However the "HAVE_GL" symbol and "ACTION-IF-FOUND"
  26. # hook is always guaranteed to reflect a valid OpenGL implementation.
  27. #
  28. # If user didn't specify the "ACTION-IF-FOUND" hook, the configuration
  29. # would prepend "GL_CFLAGS" and "GL_LIBS" to "CFLAGS" and "LIBS", like
  30. # many other autoconf macros do.
  31. #
  32. # OpenGL is one of the libraries that has different header names on
  33. # different platforms. This macro does the header detection, and will
  34. # export the following symbol: "HAVE_GL_GL_H" for having "GL/gl.h" or
  35. # "HAVE_OPENGL_GL_H" for having "OpenGL/gl.h". To write a portable OpenGL
  36. # code, you should include OpenGL header like so:
  37. #
  38. # #if defined(HAVE_WINDOWS_H) && defined(_WIN32)
  39. # # include <windows.h>
  40. # #endif
  41. # #ifdef HAVE_GL_GL_H
  42. # # include <GL/gl.h>
  43. # #elif defined(HAVE_OPENGL_GL_H)
  44. # # include <OpenGL/gl.h>
  45. # #else
  46. # # error no gl.h
  47. # #endif
  48. #
  49. # On the OSX platform, there's two possible OpenGL implementation. One is
  50. # the OpenGL that ships with OSX, the other comes with X11/XQuartz
  51. # (http://www.xquartz.org). To use the xquartz variant, user can use the
  52. # option --with-xquartz-gl[=path to xquartz root]. By default the
  53. # configuration will check "/opt/X11", which is the default X11 install
  54. # location on OSX.
  55. #
  56. # LICENSE
  57. #
  58. # Copyright (c) 2009 Braden McDaniel <braden@endoframe.com>
  59. # Copyright (c) 2012 Bastien Roucaries <roucaries.bastien+autoconf@gmail.com>
  60. # Copyright (c) 2016 Felix Chern <idryman@gmail.com>
  61. #
  62. # This program is free software; you can redistribute it and/or modify it
  63. # under the terms of the GNU General Public License as published by the
  64. # Free Software Foundation; either version 2 of the License, or (at your
  65. # option) any later version.
  66. #
  67. # This program is distributed in the hope that it will be useful, but
  68. # WITHOUT ANY WARRANTY; without even the implied warranty of
  69. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  70. # Public License for more details.
  71. #
  72. # You should have received a copy of the GNU General Public License along
  73. # with this program. If not, see <https://www.gnu.org/licenses/>.
  74. #
  75. # As a special exception, the respective Autoconf Macro's copyright owner
  76. # gives unlimited permission to copy, distribute and modify the configure
  77. # scripts that are the output of Autoconf when processing the Macro. You
  78. # need not follow the terms of the GNU General Public License when using
  79. # or distributing such scripts, even though portions of the text of the
  80. # Macro appear in them. The GNU General Public License (GPL) does govern
  81. # all other use of the material that constitutes the Autoconf Macro.
  82. #
  83. # This special exception to the GPL applies to versions of the Autoconf
  84. # Macro released by the Autoconf Archive. When you make and distribute a
  85. # modified version of the Autoconf Macro, you may extend this special
  86. # exception to the GPL to apply to your modified version as well.
  87. #serial 22
  88. # example gl program
  89. m4_define([_AX_CHECK_GL_PROGRAM],
  90. [AC_LANG_PROGRAM([[
  91. # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
  92. # include <windows.h>
  93. # endif
  94. # ifdef HAVE_GL_GL_H
  95. # include <GL/gl.h>
  96. # elif defined(HAVE_OPENGL_GL_H)
  97. # include <OpenGL/gl.h>
  98. # elif defined(HAVE_GLES_GL_H)
  99. # include <GLES/gl.h>
  100. # else
  101. # error no gl.h
  102. # endif
  103. ]],[[glBegin(0)]])])
  104. dnl Default include : add windows.h
  105. dnl see http://www.opengl.org/wiki/Platform_specifics:_Windows
  106. dnl (acceded 20120801)
  107. AC_DEFUN([_AX_CHECK_GL_INCLUDES_DEFAULT],dnl
  108. [
  109. AC_INCLUDES_DEFAULT
  110. [
  111. # if defined(HAVE_WINDOWS_H) && defined(_WIN32)
  112. # include <windows.h>
  113. # endif
  114. ]
  115. ])
  116. # _AX_CHECK_GL_SAVE_FLAGS(LIST-OF-FLAGS)
  117. # Use this macro before you modify the flags.
  118. # Restore the flags by _AX_CHECK_GL_RESTORE_FLAGS
  119. #
  120. # Example: _AX_CHECK_GL_SAVE_FLAGS([[CFLAGS],[LIBS]]) expands to
  121. # gl_saved_flag_cflags=$CFLAGS
  122. # gl_saved_flag_libs=$LIBS
  123. # CFLAGS="$GL_CFLAGS $CFLAGS"
  124. # LIBS="$GL_LIBS $LIBS"
  125. AC_DEFUN([_AX_CHECK_GL_SAVE_FLAGS], [
  126. AX_SAVE_FLAGS_WITH_PREFIX([GL],[$1])
  127. AC_LANG_PUSH([C])
  128. ])
  129. # _AX_CHECK_GL_RESTORE_FLAGS(LIST-OF-FLAGS)
  130. # Use this marcro to restore the flags you saved using
  131. # _AX_CHECK_GL_SAVE_FLAGS
  132. #
  133. # Example: _AX_CHECK_GL_RESTORE_FLAGS([[CFLAGS],[LIBS]]) expands to
  134. # CFLAGS="$gl_saved_flag_cflags"
  135. # LIBS="$gl_saved_flag_libs"
  136. AC_DEFUN([_AX_CHECK_GL_RESTORE_FLAGS], [
  137. AX_RESTORE_FLAGS_WITH_PREFIX([GL],[$1])
  138. AC_LANG_POP([C])
  139. ])
  140. # Check if the program compiles
  141. AC_DEFUN([_AX_CHECK_GL_COMPILE],
  142. [dnl
  143. _AX_CHECK_GL_SAVE_FLAGS([CFLAGS])
  144. AC_COMPILE_IFELSE([_AX_CHECK_GL_PROGRAM],
  145. [ax_check_gl_compile_opengl="yes"],
  146. [ax_check_gl_compile_opengl="no"])
  147. _AX_CHECK_GL_RESTORE_FLAGS([CFLAGS])
  148. ])
  149. # Compile the example program (cache)
  150. AC_DEFUN([_AX_CHECK_GL_COMPILE_CV],
  151. [dnl
  152. AC_CACHE_CHECK([for compiling a minimal OpenGL program],[ax_cv_check_gl_compile_opengl],
  153. [_AX_CHECK_GL_COMPILE()
  154. ax_cv_check_gl_compile_opengl="${ax_check_gl_compile_opengl}"])
  155. ax_check_gl_compile_opengl="${ax_cv_check_gl_compile_opengl}"
  156. ])
  157. # Link the example program
  158. AC_DEFUN([_AX_CHECK_GL_LINK],
  159. [dnl
  160. _AX_CHECK_GL_SAVE_FLAGS([[CFLAGS],[LIBS],[LDFLAGS]])
  161. AC_LINK_IFELSE([_AX_CHECK_GL_PROGRAM],
  162. [ax_check_gl_link_opengl="yes"],
  163. [ax_check_gl_link_opengl="no"])
  164. _AX_CHECK_GL_RESTORE_FLAGS([[CFLAGS],[LIBS],[LDFLAGS]])
  165. ])
  166. # Link the example program (cache)
  167. AC_DEFUN([_AX_CHECK_GL_LINK_CV],
  168. [dnl
  169. AC_CACHE_CHECK([for linking a minimal OpenGL program],[ax_cv_check_gl_link_opengl],
  170. [_AX_CHECK_GL_LINK()
  171. ax_cv_check_gl_link_opengl="${ax_check_gl_link_opengl}"])
  172. ax_check_gl_link_opengl="${ax_cv_check_gl_link_opengl}"
  173. ])
  174. # _AX_CHECK_GL_MANUAL_LIBS_GENERIC(LIBRARIES-TO-SEARCH)
  175. # Searches library provided in $1, and output the flag
  176. # $ax_check_gl_lib_opengl
  177. AC_DEFUN([_AX_CHECK_GL_MANUAL_LIBS_GENERIC], [
  178. AS_IF([test -n "$GL_LIBS"],[], [
  179. ax_check_gl_manual_libs_generic_extra_libs="$1"
  180. AS_IF([test "X$ax_check_gl_manual_libs_generic_extra_libs" = "X"],
  181. [AC_MSG_ERROR([AX_CHECK_GL_MANUAL_LIBS_GENERIC argument must no be empty])])
  182. _AX_CHECK_GL_SAVE_FLAGS([CFLAGS])
  183. AC_SEARCH_LIBS([glBegin],[$ax_check_gl_manual_libs_generic_extra_libs], [
  184. ax_check_gl_lib_opengl="yes"
  185. break
  186. ])
  187. AS_IF([test "X$ax_check_gl_lib_opengl"="Xyes"],
  188. [GL_LIBS="${ac_cv_search_glBegin}"])
  189. _AX_CHECK_GL_RESTORE_FLAGS([CFLAGS])
  190. ])
  191. ])
  192. # _WITH_XQUARTZ_GL
  193. # ----------------
  194. # Provides an option in command line to specify the XQuartz installation
  195. # path on OSX, so that user can link to it instead of using the default
  196. # OSX OpenGL framework. (Mac OSX only)
  197. AC_DEFUN_ONCE([_WITH_XQUARTZ_GL],[
  198. AC_ARG_WITH([xquartz-gl],
  199. [AS_HELP_STRING([--with-xquartz-gl@<:@=DIR@:>@],
  200. [On Mac OSX, use opengl provided by X11/XQuartz instead of the built-in framework.
  201. If enabled, the default location is @<:@DIR=/opt/X11@:>@.
  202. This option is default to false.])],
  203. [AS_IF([test "X$with_xquartz_gl"="Xyes"],
  204. [with_xquartz_gl="/opt/X11"])],
  205. [with_xquartz_gl=no])
  206. AS_IF([test "X$with_xquartz_gl" != "Xno"],
  207. [AC_MSG_CHECKING([OSX X11 path])
  208. AS_IF([test -e "$with_xquartz_gl"],
  209. [AC_MSG_RESULT(["$with_xquartz_gl"])
  210. CFLAGS="-I$with_xquartz_gl/include $CFLAGS"
  211. LIBS="-L$with_xquartz_gl/lib $LIBS"
  212. ],
  213. [with_xquartz_gl=no
  214. AC_MSG_RESULT([no])
  215. AC_MSG_WARN([--with-xquartz-gl was given, but test for X11 failed. Fallback to system framework])
  216. ])
  217. ])
  218. ])
  219. # OSX specific setup for OpenGL check
  220. AC_DEFUN([_AX_CHECK_DARWIN_GL], [
  221. AC_REQUIRE([_WITH_XQUARTZ_GL])
  222. AS_IF([test "x$with_xquartz_gl" != "xno" && test "x$EMSCRIPTEN" == "x"],
  223. [GL_LIBS="${GL_LIBS:--lGL}"],
  224. [GL_LIBS="${GL_LIBS:--framework OpenGL}"])
  225. ])
  226. # AX_CHECK_GL_LIB([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  227. # ---------------------------------------------------------
  228. # Checks OpenGL headers and library and provides hooks for success and failures.
  229. # When $1 is not set, this macro would modify CFLAGS and LIBS environment variables.
  230. # However, user can override this behavior by providing their own hooks.
  231. # The CFLAGS and LIBS flags required by OpenGL is always exported in
  232. # GL_CFLAGS and GL_LIBS environment variable.
  233. #
  234. # In other words, the default behavior of AX_CHECK_GL_LIB() is equivalent to
  235. # AX_CHECK_GL_LIB(
  236. # [CFLAGS="$GL_CFLAGS $CFLAGS"
  237. # LIBS="$GL_LIBS $LIBS"]
  238. # )
  239. AC_DEFUN([AX_CHECK_GL],
  240. [AC_REQUIRE([AC_CANONICAL_HOST])
  241. AC_REQUIRE([PKG_PROG_PKG_CONFIG])
  242. AC_ARG_VAR([GL_CFLAGS],[C compiler flags for GL, overriding configure script defaults])
  243. AC_ARG_VAR([GL_LIBS],[Linker flags for GL, overriding configure script defaults])
  244. dnl --with-gl or not can be implemented outside of check-gl
  245. AS_CASE([${host}],
  246. [*-darwin*],[_AX_CHECK_DARWIN_GL],
  247. dnl some windows may support X11 opengl, and should be able to linked
  248. dnl by -lGL. However I have no machine to test it.
  249. [*-cygwin*|*-mingw*],[
  250. _AX_CHECK_GL_MANUAL_LIBS_GENERIC([opengl32 GL gl])
  251. AC_CHECK_HEADERS([windows.h])
  252. ],
  253. [PKG_PROG_PKG_CONFIG
  254. PKG_CHECK_MODULES([GL],[gl],
  255. [],
  256. [_AX_CHECK_GL_MANUAL_LIBS_GENERIC([GL gl])])
  257. ]) dnl host specific checks
  258. dnl this was cache
  259. _AX_CHECK_GL_SAVE_FLAGS([CFLAGS])
  260. AC_CHECK_HEADERS([GL/gl.h OpenGL/gl.h GLES/gl.h],
  261. [ax_check_gl_have_headers="yes";break])
  262. _AX_CHECK_GL_RESTORE_FLAGS([CFLAGS])
  263. AS_IF([test "X$ax_check_gl_have_headers" = "Xyes"],
  264. [_AX_CHECK_GL_COMPILE_CV()],
  265. [no_gl=yes])
  266. AS_IF([test "X$ax_check_gl_compile_opengl" = "Xyes"],
  267. [_AX_CHECK_GL_LINK_CV()],
  268. [no_gl=yes])
  269. AS_IF([test "X$no_gl" = "X"],
  270. [AC_DEFINE([HAVE_GL], [1], [Defined if a valid OpenGL implementation is found.])
  271. m4_ifval([$1],
  272. [$1],
  273. [CFLAGS="$GL_CFLAGS $CFLAGS"
  274. LIBS="$GL_LIBS $LIBS"])
  275. ],
  276. [m4_ifval([$2],
  277. [$2],
  278. [AC_MSG_ERROR([Could not find a valid OpenGL implementation])])
  279. ])
  280. ])