From 22b892b44f5005d7af8d50df313e759bfdb1acd0 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 26 Aug 2016 19:27:22 +0530 Subject: [PATCH] gstconfig: Decide GST_EXPORT declaration style at build time We only use GST_EXPORT consistently when building with MSVC by using the visual studio definitions files (win32/common/*.def), so always disable it when building with Autotools and only enable it with Meson when building with MSVC. This allows you to use MinGW to link to a GStreamer built with MSVC and get the correct function prototypes to find functions and variables in DLLs. --- configure.ac | 5 +++++ gst/gstconfig.h.in | 11 ++++++----- meson.build | 8 ++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index f663bf33a2..7533bb9c90 100644 --- a/configure.ac +++ b/configure.ac @@ -131,6 +131,11 @@ AG_GST_SET_PACKAGE_RELEASE_DATETIME_WITH_NANO([$PACKAGE_VERSION_NANO], ["${srcdir}/gstreamer.doap"], [$PACKAGE_VERSION_MAJOR.$PACKAGE_VERSION_MINOR.$PACKAGE_VERSION_MICRO]) +# We only use this when building with MSVC, which is only done with the +# alternate Meson build system files +GSTCONFIG_USE_MSVC_DECLSPEC=0 +AC_SUBST(GSTCONFIG_USE_MSVC_DECLSPEC) + dnl check for bash completion AC_ARG_WITH([bash-completion-dir], AS_HELP_STRING([--with-bash-completion-dir[=PATH]], diff --git a/gst/gstconfig.h.in b/gst/gstconfig.h.in index 0ec150972e..1a96e984eb 100644 --- a/gst/gstconfig.h.in +++ b/gst/gstconfig.h.in @@ -128,20 +128,21 @@ * On Windows, this exports the plugin definition from the DLL. * On other platforms, this gets defined as a no-op. */ -/* Macro _WIN32 is defined on 32-bit and 64-bit Windows; by both GCC and MSVC +/* Only use __declspec(dllexport/import) when we have been built with MSVC. + * With MinGW we still rely on the linker to auto-export/import symbols. * - * NOTE: To link to Windows statically on Windows, you must define + * NOTE: To link to GStreamer statically on Windows, you must define * GST_STATIC_COMPILATION or the prototypes will cause the compiler to search - * for the symbol inside a DLL + * for the symbol inside a DLL. */ -#if defined(_WIN32) && !defined(GST_STATIC_COMPILATION) +#if @GSTCONFIG_USE_MSVC_DECLSPEC@ && !defined(GST_STATIC_COMPILATION) # define GST_PLUGIN_EXPORT __declspec(dllexport) # ifdef GST_EXPORTS # define GST_EXPORT __declspec(dllexport) # else # define GST_EXPORT __declspec(dllimport) extern # endif -#else /* !_WIN32 */ +#else # define GST_PLUGIN_EXPORT # if (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) # define GST_EXPORT extern __attribute__ ((visibility ("default"))) diff --git a/meson.build b/meson.build index d8de1a61b3..5dc2dc22ad 100644 --- a/meson.build +++ b/meson.build @@ -221,6 +221,14 @@ if cc.has_function('strsignal', prefix : '#include ') cdata.set('HAVE_DECL_STRSIGNAL', 1) endif +# We only want to use the __declspec(dllexport/import) dance in GST_EXPORT when +# building with MSVC +if cc.get_id() == 'msvc' + cdata.set('GSTCONFIG_USE_MSVC_DECLSPEC', 1) +else + cdata.set('GSTCONFIG_USE_MSVC_DECLSPEC', 0) +endif + configure_file(input : 'config.h.meson', output : 'config.h', configuration : cdata)