gstconfig: Decide GST_EXPORT declaration style at build time
authorNirbheek Chauhan <nirbheek@centricular.com>
Fri, 26 Aug 2016 13:57:22 +0000 (19:27 +0530)
committerTim-Philipp Müller <tim@centricular.com>
Fri, 26 Aug 2016 14:20:50 +0000 (15:20 +0100)
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
gst/gstconfig.h.in
meson.build

index f663bf3..7533bb9 100644 (file)
@@ -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]],
index 0ec1509..1a96e98 100644 (file)
  * 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")))
index d8de1a6..5dc2dc2 100644 (file)
@@ -221,6 +221,14 @@ if cc.has_function('strsignal', prefix : '#include <string.h>')
   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)