diff --git a/configure.ac b/configure.ac index e733267..e5a6ba0 100644 --- a/configure.ac +++ b/configure.ac @@ -125,25 +125,39 @@ AM_CONDITIONAL(HAS_GLES1, test x$has_gles1 = xyes) AC_CHECK_LIB([dl], [dlopen], [DLOPEN_LIBS="-ldl"]) AC_SUBST([DLOPEN_LIBS]) -case $host_os in - mingw*) - # visibility flags aren't supported for windows DLLs, and the - # compiler whines to tell you so, so don't set them up. - ;; - *) - if test "x$GCC" = xyes; then - save_CFLAGS="$CFLAGS" - AC_MSG_CHECKING([whether $CC supports -fvisibility=hidden]) - VISIBILITY_CFLAGS="-fvisibility=hidden" - CFLAGS="$CFLAGS $VISIBILITY_CFLAGS" - AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]), - [VISIBILITY_CFLAGS=""; AC_MSG_RESULT([no])]); - - # Restore CFLAGS; VISIBILITY_CFLAGS are added to it where needed. - CFLAGS=$save_CFLAGS - fi - ;; -esac +VISIBILITY_CFLAGS="" +AS_CASE(["$host"], + + [*-*-mingw*], [ + dnl on mingw32 we do -fvisibility=hidden and __declspec(dllexport) + AC_DEFINE([EPOXY_PUBLIC], + [__attribute__((visibility("default"))) __declspec(dllexport) extern], + [defines how to decorate public symbols while building]) + VISIBILITY_CFLAGS="-fvisibility=hidden" + ], + + [ + dnl on other compilers, check if we can do -fvisibility=hidden + SAVED_CFLAGS="${CFLAGS}" + CFLAGS="-fvisibility=hidden" + AC_MSG_CHECKING([for -fvisibility=hidden compiler flag]) + AC_TRY_COMPILE([], [int main (void) { return 0; }], [ + AC_MSG_RESULT(yes) + enable_fvisibility_hidden=yes + ], [ + AC_MSG_RESULT(no) + enable_fvisibility_hidden=no + ]) + CFLAGS="${SAVED_CFLAGS}" + + AS_IF([test "${enable_fvisibility_hidden}" = "yes"], [ + AC_DEFINE([EPOXY_PUBLIC], + [__attribute__((visibility("default"))) extern], + [defines how to decorate public symbols while building]) + VISIBILITY_CFLAGS="-fvisibility=hidden" + ]) + ] +) AC_SUBST([VISIBILITY_CFLAGS]) diff --git a/include/epoxy/Makefile.am b/include/epoxy/Makefile.am index b5b94a6..494c96e 100644 --- a/include/epoxy/Makefile.am +++ b/include/epoxy/Makefile.am @@ -22,6 +22,7 @@ epoxyincludedir = $(includedir)/epoxy epoxyinclude_HEADERS = \ + common.h \ gl.h \ $(EGL_INCLUDES) \ $(GLX_INCLUDES) \ diff --git a/include/epoxy/common.h b/include/epoxy/common.h new file mode 100644 index 0000000..a745f16 --- /dev/null +++ b/include/epoxy/common.h @@ -0,0 +1,44 @@ +/* + * Copyright 2017 Emmanuele Bassi + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** @file common.h + * + * A common header file, used to define macros and shared symbols. + */ + +#ifndef EPOXY_COMMON_H +#define EPOXY_COMMON_H + +#ifdef __cplusplus +# define EPOXY_BEGIN_DECLS extern "C" { +# define EPOXY_END_DECLS } +#else +# define EPOXY_BEGIN_DECLS +# define EPOXY_END_DECLS +#endif + +#ifndef EPOXY_PUBLIC +# define EPOXY_PUBLIC extern +#endif + +#endif /* EPOXY_COMMON_H */ diff --git a/include/epoxy/egl.h b/include/epoxy/egl.h index f1c3f56..79e9bb4 100644 --- a/include/epoxy/egl.h +++ b/include/epoxy/egl.h @@ -30,12 +30,10 @@ #ifndef EPOXY_EGL_H #define EPOXY_EGL_H -#ifdef __cplusplus -extern "C" { -#endif - #include +#include "epoxy/common.h" + #if defined(__egl_h_) || defined(__eglext_h_) #error epoxy/egl.h must be included before (or in place of) GL/egl.h #else @@ -45,11 +43,11 @@ extern "C" { #include "epoxy/egl_generated.h" -bool epoxy_has_egl_extension(EGLDisplay dpy, const char *extension); -int epoxy_egl_version(EGLDisplay dpy); +EPOXY_BEGIN_DECLS -#ifdef __cplusplus -} /* extern "C" */ -#endif +EPOXY_PUBLIC bool epoxy_has_egl_extension(EGLDisplay dpy, const char *extension); +EPOXY_PUBLIC int epoxy_egl_version(EGLDisplay dpy); + +EPOXY_END_DECLS #endif /* EPOXY_EGL_H */ diff --git a/include/epoxy/gl.h b/include/epoxy/gl.h index 0be3a66..425431c 100644 --- a/include/epoxy/gl.h +++ b/include/epoxy/gl.h @@ -30,12 +30,10 @@ #ifndef EPOXY_GL_H #define EPOXY_GL_H -#ifdef __cplusplus -extern "C" { -#endif - #include +#include "epoxy/common.h" + #if defined(__gl_h_) || defined(__glext_h_) #error epoxy/gl.h must be included before (or in place of) GL/gl.h #else @@ -51,7 +49,6 @@ extern "C" { /* APIENTRY and GLAPIENTRY are not used on Linux or Mac. */ #define APIENTRY #define GLAPIENTRY -#define EPOXY_IMPORTEXPORT #define EPOXY_CALLSPEC #define GLAPI #define KHRONOS_APIENTRY @@ -70,10 +67,6 @@ extern "C" { #define EPOXY_CALLSPEC __stdcall #endif -#ifndef EPOXY_IMPORTEXPORT -#define EPOXY_IMPORTEXPORT __declspec(dllimport) -#endif - #ifndef GLAPI #define GLAPI extern #endif @@ -93,12 +86,12 @@ extern "C" { #include "epoxy/gl_generated.h" -EPOXY_IMPORTEXPORT bool epoxy_has_gl_extension(const char *extension); -EPOXY_IMPORTEXPORT bool epoxy_is_desktop_gl(void); -EPOXY_IMPORTEXPORT int epoxy_gl_version(void); +EPOXY_BEGIN_DECLS -#ifdef __cplusplus -} /* extern "C" */ -#endif +EPOXY_PUBLIC bool epoxy_has_gl_extension(const char *extension); +EPOXY_PUBLIC bool epoxy_is_desktop_gl(void); +EPOXY_PUBLIC int epoxy_gl_version(void); + +EPOXY_END_DECLS #endif /* EPOXY_GL_H */ diff --git a/include/epoxy/glx.h b/include/epoxy/glx.h index 8df33b8..a67cb07 100644 --- a/include/epoxy/glx.h +++ b/include/epoxy/glx.h @@ -30,10 +30,6 @@ #ifndef EPOXY_GLX_H #define EPOXY_GLX_H -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include @@ -49,11 +45,11 @@ extern "C" { #include "epoxy/glx_generated.h" -bool epoxy_has_glx_extension(Display *dpy, int screen, const char *extension); -int epoxy_glx_version(Display *dpy, int screen); +EPOXY_BEGIN_DECLS -#ifdef __cplusplus -} /* extern "C" */ -#endif +EPOXY_PUBLIC bool epoxy_has_glx_extension(Display *dpy, int screen, const char *extension); +EPOXY_PUBLIC int epoxy_glx_version(Display *dpy, int screen); + +EPOXY_END_DECLS #endif /* EPOXY_GLX_H */ diff --git a/include/epoxy/meson.build b/include/epoxy/meson.build index 545e991..809b92c 100644 --- a/include/epoxy/meson.build +++ b/include/epoxy/meson.build @@ -1,3 +1,5 @@ +headers = [ 'common.h' ] + gl_generated = custom_target('gl_generated.h', input: gl_registry, output: [ @@ -15,7 +17,7 @@ gl_generated = custom_target('gl_generated.h', install_dir: join_paths(epoxy_includedir, 'epoxy')) gen_headers = [ gl_generated ] -headers = [ 'gl.h', ] +headers += [ 'gl.h', ] if build_egl egl_generated = custom_target('egl_generated.h', diff --git a/include/epoxy/wgl.h b/include/epoxy/wgl.h index fdd7b4f..84d26ac 100644 --- a/include/epoxy/wgl.h +++ b/include/epoxy/wgl.h @@ -30,13 +30,11 @@ #ifndef EPOXY_WGL_H #define EPOXY_WGL_H -#ifdef __cplusplus -extern "C" { -#endif - #include #include +#include "epoxy/common.h" + #undef wglUseFontBitmaps #undef wglUseFontOutlines @@ -54,11 +52,11 @@ extern "C" { #include "epoxy/wgl_generated.h" -EPOXY_IMPORTEXPORT bool epoxy_has_wgl_extension(HDC hdc, const char *extension); -EPOXY_IMPORTEXPORT void epoxy_handle_external_wglMakeCurrent(void); +EPOXY_BEGIN_DECLS -#ifdef __cplusplus -} /* extern "C" */ -#endif +EPOXY_PUBLIC bool epoxy_has_wgl_extension(HDC hdc, const char *extension); +EPOXY_PUBLIC void epoxy_handle_external_wglMakeCurrent(void); + +EPOXY_END_DECLS #endif /* EPOXY_WGL_H */ diff --git a/meson.build b/meson.build index f9ea607..c75622c 100644 --- a/meson.build +++ b/meson.build @@ -91,6 +91,23 @@ foreach cflag: test_cflags endif endforeach +# Visibility compiler flags +visibility_cflags = [] +if get_option('default_library') != 'static' + if host_system == 'windows' + conf.set('DLL_EXPORT', true) + if cc.get_id() == 'msvc' + conf.set('EPOXY_PUBLIC', '__declspec(dllexport) extern') + else + conf.set('EPOXY_PUBLIC', '__attribute__((visibility("default"))) __declspec(dllexport) extern') + visibility_cflags += [ '-fvisibility=hidden' ] + endif + else + conf.set('EPOXY_PUBLIC', '__attribute__((visibility("default")))') + visibility_cflags += [ '-fvisibility=hidden' ] + endif +endif + # Dependencies dl_dep = cc.find_library('dl', required: false) gl_dep = dependency('gl', required: false) diff --git a/src/dispatch_common.c b/src/dispatch_common.c index ab1fb92..374f6d5 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -269,7 +269,7 @@ do_dlsym(void **handle, const char *lib_name, const char *name, return result; } -PUBLIC bool +bool epoxy_is_desktop_gl(void) { const char *es_prefix = "OpenGL ES"; @@ -333,7 +333,7 @@ epoxy_internal_gl_version(int error_version) return 10 * major + minor; } -PUBLIC int +int epoxy_gl_version(void) { return epoxy_internal_gl_version(0); @@ -459,7 +459,7 @@ epoxy_current_context_is_glx(void) * \sa epoxy_has_egl_extension() * \sa epoxy_has_glx_extension() */ -PUBLIC bool +bool epoxy_has_gl_extension(const char *ext) { return epoxy_internal_has_gl_extension(ext, false); @@ -698,5 +698,5 @@ WRAPPER(epoxy_glEnd)(void) #endif } -PUBLIC PFNGLBEGINPROC epoxy_glBegin = epoxy_glBegin_wrapped; -PUBLIC PFNGLENDPROC epoxy_glEnd = epoxy_glEnd_wrapped; +PFNGLBEGINPROC epoxy_glBegin = epoxy_glBegin_wrapped; +PFNGLENDPROC epoxy_glEnd = epoxy_glEnd_wrapped; diff --git a/src/dispatch_common.h b/src/dispatch_common.h index 52743a6..40d4bbc 100644 --- a/src/dispatch_common.h +++ b/src/dispatch_common.h @@ -21,28 +21,26 @@ * IN THE SOFTWARE. */ +#include "config.h" + #include #ifdef _WIN32 #define PLATFORM_HAS_EGL 0 #define PLATFORM_HAS_GLX 0 #define PLATFORM_HAS_WGL 1 -#define EPOXY_IMPORTEXPORT __declspec(dllexport) #elif defined(__APPLE__) #define PLATFORM_HAS_EGL 0 #define PLATFORM_HAS_GLX 0 #define PLATFORM_HAS_WGL 0 -#define EPOXY_IMPORTEXPORT #elif defined(ANDROID) #define PLATFORM_HAS_EGL 1 #define PLATFORM_HAS_GLX 0 #define PLATFORM_HAS_WGL 0 -#define EPOXY_IMPORTEXPORT #else #define PLATFORM_HAS_EGL 1 #define PLATFORM_HAS_GLX 1 #define PLATFORM_HAS_WGL 0 -#define EPOXY_IMPORTEXPORT #endif #include "epoxy/gl.h" @@ -56,16 +54,6 @@ #include "epoxy/wgl.h" #endif -#ifndef PUBLIC -# ifdef _WIN32 -# define PUBLIC __declspec(dllexport) -# elif (defined(__GNUC__) && __GNUC__ >= 4) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) -# define PUBLIC __attribute__((visibility("default"))) -# else -# define PUBLIC -# endif -#endif - #if defined(__GNUC__) #define PACKED __attribute__((__packed__)) #define ENDPACKED diff --git a/src/dispatch_egl.c b/src/dispatch_egl.c index b42aacd..d1dc53c 100644 --- a/src/dispatch_egl.c +++ b/src/dispatch_egl.c @@ -38,7 +38,7 @@ epoxy_conservative_egl_version(void) return epoxy_egl_version(dpy); } -PUBLIC int +int epoxy_egl_version(EGLDisplay dpy) { int major, minor; @@ -57,7 +57,7 @@ epoxy_conservative_has_egl_extension(const char *ext) return epoxy_has_egl_extension(eglGetCurrentDisplay(), ext); } -PUBLIC bool +bool epoxy_has_egl_extension(EGLDisplay dpy, const char *ext) { return epoxy_extension_in_string(eglQueryString(dpy, EGL_EXTENSIONS), ext) || epoxy_extension_in_string(eglQueryString(NULL, EGL_EXTENSIONS), ext); diff --git a/src/dispatch_glx.c b/src/dispatch_glx.c index 9e4cef6..9396f1c 100644 --- a/src/dispatch_glx.c +++ b/src/dispatch_glx.c @@ -47,7 +47,7 @@ epoxy_conservative_glx_version(void) return epoxy_glx_version(dpy, screen); } -PUBLIC int +int epoxy_glx_version(Display *dpy, int screen) { int server_major, server_minor; @@ -98,7 +98,7 @@ epoxy_conservative_has_glx_extension(const char *ext) return epoxy_has_glx_extension(dpy, screen, ext); } -PUBLIC bool +bool epoxy_has_glx_extension(Display *dpy, int screen, const char *ext) { /* No, you can't just use glXGetClientString or diff --git a/src/dispatch_wgl.c b/src/dispatch_wgl.c index bfe9bb1..fe5379d 100644 --- a/src/dispatch_wgl.c +++ b/src/dispatch_wgl.c @@ -46,7 +46,7 @@ epoxy_conservative_has_wgl_extension(const char *ext) return epoxy_has_wgl_extension(hdc, ext); } -PUBLIC bool +bool epoxy_has_wgl_extension(HDC hdc, const char *ext) { PFNWGLGETEXTENSIONSSTRINGARBPROC getext; @@ -72,7 +72,7 @@ epoxy_has_wgl_extension(HDC hdc, const char *ext) * table per context and reuse it when the context is made current * again. */ -PUBLIC void +void epoxy_handle_external_wglMakeCurrent(void) { if (!first_context_current) { @@ -190,7 +190,7 @@ WRAPPER(epoxy_wglMakeAssociatedContextCurrentAMD)(HGLRC hglrc) return ret; } -PUBLIC PFNWGLMAKECURRENTPROC epoxy_wglMakeCurrent = epoxy_wglMakeCurrent_wrapped; -PUBLIC PFNWGLMAKECONTEXTCURRENTEXTPROC epoxy_wglMakeContextCurrentEXT = epoxy_wglMakeContextCurrentEXT_wrapped; -PUBLIC PFNWGLMAKECONTEXTCURRENTARBPROC epoxy_wglMakeContextCurrentARB = epoxy_wglMakeContextCurrentARB_wrapped; -PUBLIC PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC epoxy_wglMakeAssociatedContextCurrentEXT = epoxy_wglMakeAssociatedContextCurrentAMD_wrapped; +PFNWGLMAKECURRENTPROC epoxy_wglMakeCurrent = epoxy_wglMakeCurrent_wrapped; +PFNWGLMAKECONTEXTCURRENTEXTPROC epoxy_wglMakeContextCurrentEXT = epoxy_wglMakeContextCurrentEXT_wrapped; +PFNWGLMAKECONTEXTCURRENTARBPROC epoxy_wglMakeContextCurrentARB = epoxy_wglMakeContextCurrentARB_wrapped; +PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC epoxy_wglMakeAssociatedContextCurrentEXT = epoxy_wglMakeAssociatedContextCurrentAMD_wrapped; diff --git a/src/gen_dispatch.py b/src/gen_dispatch.py index 013a4bd..548c2bb 100755 --- a/src/gen_dispatch.py +++ b/src/gen_dispatch.py @@ -77,7 +77,7 @@ class GLFunction(object): self.public = '' else: self.wrapped_name = name - self.public = 'PUBLIC ' + self.public = 'EPOXY_PUBLIC ' # This is the string of C code for passing through the # arguments to the function. @@ -485,6 +485,8 @@ class Generator(object): def write_header(self, file): self.write_header_header(file) + self.outln('#include "epoxy/common.h"') + if self.target != "gl": self.outln('#include "epoxy/gl.h"') if self.target == "egl": @@ -529,9 +531,9 @@ class Generator(object): self.write_function_ptr_typedefs() for func in self.sorted_functions: - self.outln('extern EPOXY_IMPORTEXPORT {0} (EPOXY_CALLSPEC *epoxy_{1})({2});'.format(func.ret_type, - func.name, - func.args_decl)) + self.outln('EPOXY_PUBLIC {0} (EPOXY_CALLSPEC *epoxy_{1})({2});'.format(func.ret_type, + func.name, + func.args_decl)) self.outln('') for func in self.sorted_functions: @@ -621,9 +623,7 @@ class Generator(object): func.args_list)) def write_function_pointer(self, func): - self.outln('{0}{1} epoxy_{2} = epoxy_{2}_global_rewrite_ptr;'.format(func.public, - func.ptr_type, - func.wrapped_name)) + self.outln('{0} epoxy_{1} = epoxy_{1}_global_rewrite_ptr;'.format(func.ptr_type, func.wrapped_name)) self.outln('') def write_provider_enums(self): @@ -753,6 +753,8 @@ class Generator(object): self.write_copyright_comment_body() self.outln(' */') self.outln('') + self.outln('#include "config.h"') + self.outln('') self.outln('#include ') self.outln('#include ') self.outln('#include ') diff --git a/src/meson.build b/src/meson.build index f6df778..fced355 100644 --- a/src/meson.build +++ b/src/meson.build @@ -103,7 +103,7 @@ if libtype != 'shared' install: true, dependencies: epoxy_deps, include_directories: libepoxy_inc, - c_args: common_cflags, + c_args: common_cflags + visibility_cflags, link_args: common_ldflags) libepoxy = libepoxy_static endif