From 476851ba416c0fa478a8ec0620d482ed5079e38b Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 18 Jan 2017 15:40:00 +0000 Subject: [PATCH 1/3] Allow enabling and disabling GLX support Currently, GLX support in libepoxy at build time is hard coded, but various platforms have expressed their preference for having a configure-time option for it. For instance: - various embedded distributors do not ship with X11, but wish to use libraries that depend on libepoxy now that Wayland is available - distributors for macOS still wish to retain the ability to ship their software with X11 enabled By default, we want epoxy to build with GLX enabled pretty much everywhere it makes sense, since it's only a build-time option and it's not a run-time dependency. --- meson.build | 28 +++++++++++++++++++++++++--- meson_options.txt | 5 +++++ src/dispatch_common.h | 8 +++----- test/meson.build | 2 +- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index c8e45cd..9c44d3c 100644 --- a/meson.build +++ b/meson.build @@ -30,26 +30,48 @@ conf.set_quoted('PACKAGE_LOCALEDIR', join_paths(get_option('prefix'), get_option conf.set_quoted('PACKAGE_LIBEXECDIR', join_paths(get_option('prefix'), get_option('libexecdir'))) conf.set('HAVE_KHRPLATFORM_H', cc.has_header('KHR/khrplatform.h', required: false)) -if host_system == 'windows' +# GLX can be used on different platforms, so we expose a +# configure time switch to enable or disable it; in case +# the "auto" default value is set, we only enable GLX +# support on Linux and Unix +enable_glx = get_option('enable-glx') +if enable_glx == 'auto' + if host_system == 'windows' + build_glx = false + elif host_system == 'darwin' + build_glx = false + elif host_system == 'android' + build_glx = false + else + build_glx = true + endif +elif enable_glx == 'yes' + build_glx = true +elif enable_glx == 'no' build_glx = false +endif + +# The remaining platform specific API for GL/GLES are enabled +# depending on the platform we're building for +if host_system == 'windows' build_egl = false build_apple = false build_wgl = true has_znow = true elif host_system == 'darwin' - build_glx = false build_egl = false build_apple = true build_wgl = false has_znow = false else - build_glx = true build_egl = true build_apple = false build_wgl = false has_znow = true endif +conf.set10('ENABLE_GLX', build_glx) + # Compiler flags, taken from the Xorg macros test_cflags = [ '-Wpointer-arith', diff --git a/meson_options.txt b/meson_options.txt index 4eaa634..18932f5 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,8 @@ option('enable-docs', type: 'boolean', value: false, description: 'Enable generating the Epoxy API reference (depends on Doxygen)') +option('enable-glx', + type: 'combo', + choices: [ 'auto', 'yes', 'no' ], + value: 'auto', + description: 'Enable GLX support') diff --git a/src/dispatch_common.h b/src/dispatch_common.h index 40d4bbc..b41f54b 100644 --- a/src/dispatch_common.h +++ b/src/dispatch_common.h @@ -23,15 +23,13 @@ #include "config.h" -#include - #ifdef _WIN32 #define PLATFORM_HAS_EGL 0 -#define PLATFORM_HAS_GLX 0 +#define PLATFORM_HAS_GLX ENABLE_GLX #define PLATFORM_HAS_WGL 1 #elif defined(__APPLE__) #define PLATFORM_HAS_EGL 0 -#define PLATFORM_HAS_GLX 0 +#define PLATFORM_HAS_GLX ENABLE_GLX #define PLATFORM_HAS_WGL 0 #elif defined(ANDROID) #define PLATFORM_HAS_EGL 1 @@ -39,7 +37,7 @@ #define PLATFORM_HAS_WGL 0 #else #define PLATFORM_HAS_EGL 1 -#define PLATFORM_HAS_GLX 1 +#define PLATFORM_HAS_GLX ENABLE_GLX #define PLATFORM_HAS_WGL 0 #endif diff --git a/test/meson.build b/test/meson.build index 857a980..2340fc6 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,6 +1,6 @@ has_gles1 = gles1_dep.found() has_gles2 = gles2_dep.found() -build_x11_tests = x11_dep.found() +build_x11_tests = build_glx and x11_dep.found() test_cflags = common_cflags + [ '-D_XOPEN_SOURCE', From 2b6f01b0085e10b4644b672ef03b6120b1927911 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 18 Jan 2017 16:07:02 +0000 Subject: [PATCH 2/3] Allow enabling and disabling GLX support, part II After doing this for Meson in commit fc014fa1, let's do the same dance for the Autotools build. --- configure.ac | 111 +++++++++++++++++++++++++++++++---------------- test/Makefile.am | 7 ++- 2 files changed, 79 insertions(+), 39 deletions(-) diff --git a/configure.ac b/configure.ac index e5a6ba0..283e8c2 100644 --- a/configure.ac +++ b/configure.ac @@ -58,41 +58,71 @@ AC_CHECK_HEADER([KHR/khrplatform.h], # uintptr_t to a void *") by default. Kill that. XORG_TESTSET_CFLAG(CWARNFLAGS, [-Wno-int-conversion]) -has_znow=yes - -case $host_os in - mingw*) - build_egl=no - build_glx=no - build_wgl=yes - # On windows, the DLL has to have all of its functions - # resolved at link time, so we have to link directly aginst - # opengl32.dll. But that's the only GL provider, anyway. - EPOXY_LINK_LIBS="-lopengl32" - - # Testing our built windows binaries requires that they be run - # under wine. Yeah, we should be nice and autodetect, but - # there's lots of missing autodetection for the testsuite - # (like checking for EGL and GLX libs in non-windows.). - AC_SUBST([LOG_COMPILER], [wine]) - ;; - darwin*) - build_egl=no - build_glx=no - build_wgl=no - build_apple=yes - has_znow=no - EPOXY_LINK_LIBS="" - ;; - *) - build_egl=yes - build_glx=yes - build_wgl=no - # On platforms with dlopen, we load everything dynamically and - # don't link against a specific window system or GL implementation. - EPOXY_LINK_LIBS="" - ;; -esac +AC_ARG_ENABLE([glx], + [AC_HELP_STRING([--enable-glx=@<:@auto,yes,no@:>@], [Enable GLX support @<:@default=auto@:>@])], + [enable_glx=$enableval], + [enable_glx=auto]) + +# GLX can be used on different platforms, so we expose a +# configure time switch to enable or disable it; in case +# the "auto" default value is set, we only enable GLX +# support on Linux and Unix +AS_CASE([$enable_glx], + [auto], [ + AS_CASE([$host_os], + [mingw*], [build_glx=no], + [darwin*], [build_glx=no], + [android*], [build_glx=no], + [build_glx=yes]) + ], + + [yes], [ + build_glx=yes + ], + + [no], [ + build_glx=no + ], + + [AC_MSG_ERROR([Invalid value "$enable_glx" for option "--enable-glx"])] +]) + +# The remaining platform specific API for GL/GLES are enabled +# depending on the platform we're building for +AS_CASE([$host_os], + [mingw*], [ + build_egl=no + build_wgl=yes + has_znow=yes + # On windows, the DLL has to have all of its functions + # resolved at link time, so we have to link directly aginst + # opengl32.dll. But that's the only GL provider, anyway. + EPOXY_LINK_LIBS="-lopengl32" + + # Testing our built windows binaries requires that they be run + # under wine. Yeah, we should be nice and autodetect, but + # there's lots of missing autodetection for the testsuite + # (like checking for EGL and GLX libs in non-windows.). + AC_SUBST([LOG_COMPILER], [wine]) + ], + + [darwin*], [ + build_egl=no + build_wgl=no + build_apple=yes + has_znow=no + EPOXY_LINK_LIBS="" + ], + + [ + build_egl=yes + build_wgl=no + has_znow=yes + # On platforms with dlopen, we load everything dynamically and + # don't link against a specific window system or GL implementation. + EPOXY_LINK_LIBS="" + ] +) AC_SUBST(EPOXY_LINK_LIBS) @@ -161,9 +191,14 @@ AS_CASE(["$host"], AC_SUBST([VISIBILITY_CFLAGS]) -PKG_CHECK_MODULES(X11, [x11], [x11=yes], [x11=no]) -if test x$x11 = xno -a x$build_glx = xyes; then - AC_MSG_ERROR([libX11 headers (libx11-dev) required to build with GLX support]) +if test x$build_glx = xyes; then + PKG_CHECK_MODULES(X11, [x11], [x11=yes], [x11=no]) + if test x$x11 = xno -a x$build_glx = xyes; then + AC_MSG_ERROR([libX11 headers (libx11-dev) required to build with GLX support]) + fi + AC_DEFINE(ENABLE_GLX, [1], [Whether GLX support is enabled]) +else + x11=no fi AM_CONDITIONAL(HAVE_X11, test x$x11 = xyes) diff --git a/test/Makefile.am b/test/Makefile.am index 5781702..b1f0c7a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -72,8 +72,11 @@ check_PROGRAMS = $(TESTS) if BUILD_EGL EGL_TESTS = \ + $() + +if HAVE_X11 +EGL_TESTS += \ egl_has_extension_nocontext \ - egl_gl \ egl_gles2_without_glx \ $() @@ -83,6 +86,7 @@ endif EGL_UTIL_LIB = libegl_common.la endif +endif if BUILD_GLX if HAS_ZNOW @@ -93,6 +97,7 @@ if BUILD_EGL if BUILD_GLX if !BUILD_APPLE EGL_AND_GLX_TESTS = \ + egl_gl \ egl_and_glx_different_pointers_egl_glx \ egl_and_glx_different_pointers_egl \ egl_and_glx_different_pointers_glx \ From 7b52d33d86b23d663adb585a32a411e658d5a4c9 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 6 Feb 2017 14:49:21 +0000 Subject: [PATCH 3/3] Encode Epoxy capabilities into the pkg-config file Since Epoxy can be built with different platform-specific API, having a way for dependent projects to discover those capabilities without necessarily crashing the minute they attempt to use them is a good feature to have. We strongly direct library and application developers to use pkg-config in order to use Epoxy, so it makes sense to add variables to the epoxy.pc file that can be easily extracted at configuration time. --- configure.ac | 9 +++++++++ epoxy.pc.in | 4 ++++ meson.build | 3 +++ 3 files changed, 16 insertions(+) diff --git a/configure.ac b/configure.ac index 283e8c2..51c8ea4 100644 --- a/configure.ac +++ b/configure.ac @@ -205,6 +205,15 @@ AM_CONDITIONAL(HAVE_X11, test x$x11 = xyes) PKG_CHECK_MODULES(GL, [gl], [gl=yes], [gl=no]) +# Variables for the pkg-config file; AC_SUBST does not do `test` substitutions, +# so we need to specify the boolean values here +AS_IF([test x$build_glx = xyes], [epoxy_has_glx=1], [epoxy_has_glx=0]) +AS_IF([test x$build_egl = xyes], [epoxy_has_egl=1], [epoxy_has_egl=0]) +AS_IF([test x$build_wgl = xyes], [epoxy_has_wgl=1], [epoxy_has_wgl=0]) +AC_SUBST(epoxy_has_glx) +AC_SUBST(epoxy_has_egl) +AC_SUBST(epoxy_has_wgl) + AC_CONFIG_FILES([ epoxy.pc Makefile diff --git a/epoxy.pc.in b/epoxy.pc.in index 8c85a33..7828a77 100644 --- a/epoxy.pc.in +++ b/epoxy.pc.in @@ -3,6 +3,10 @@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ +epoxy_has_glx=@epoxy_has_glx@ +epoxy_has_egl=@epoxy_has_egl@ +epoxy_has_wgl=@epoxy_has_wgl@ + Name: epoxy Description: epoxy GL dispatch Library Version: @PACKAGE_VERSION@ diff --git a/meson.build b/meson.build index 9c44d3c..ac0c913 100644 --- a/meson.build +++ b/meson.build @@ -160,6 +160,9 @@ pkgconf.set('prefix', epoxy_prefix) pkgconf.set('exec_prefix', epoxy_prefix) pkgconf.set('libdir', epoxy_libdir) pkgconf.set('includedir', epoxy_includedir) +pkgconf.set10('epoxy_has_glx', build_glx) +pkgconf.set10('epoxy_has_egl', build_egl) +pkgconf.set10('epoxy_has_wgl', build_wgl) pkgconf.set('PACKAGE_VERSION', meson.project_version()) if dl_dep.found() pkgconf.set('DLOPEN_LIBS', '-ldl')