libs: figure out right export define in configure
authorTim-Philipp Müller <tim@centricular.com>
Sat, 25 Aug 2018 21:56:01 +0000 (23:56 +0200)
committerTim-Philipp Müller <tim@centricular.com>
Mon, 24 Sep 2018 07:39:37 +0000 (08:39 +0100)
Add new GST_API_EXPORT in config.h and use that for GST_*_API
decorators instead of GST_EXPORT.

The right export define depends on the toolchain and whether
we're using -fvisibility=hidden or not, so it's better to set it
to the right thing directly than hard-coding a compiler whitelist
in the public header.

We put the export define into config.h instead of passing it via the
command line to the compiler because it might contain spaces and brackets
and in the autotools scenario we'd have to pass that through multiple
layers of plumbing and Makefile/shell escaping and we're just not going
to be *that* lucky.

The export define is only used if we're compiling our lib, not by external
users of the lib headers, so it's not a problem to put it into config.h

Also, this means all .c files of libs need to include config.h
to get the export marker defined, so fix up a few that didn't
include config.h.

This commit depends on a common submodule commit that makes gst-glib-gen.mak
add an #include "config.h" to generated enum/marshal .c files for the
autotools build.

https://bugzilla.gnome.org/show_bug.cgi?id=797185

22 files changed:
common
configure.ac
gst/gstconfig.h.in
libs/gst/base/base-prelude.h
libs/gst/base/gstdataqueue.c
libs/gst/base/gstflowcombiner.c
libs/gst/base/gstqueuearray.c
libs/gst/check/check-prelude.h
libs/gst/check/gstbufferstraw.c
libs/gst/check/gstconsistencychecker.c
libs/gst/controller/controller-prelude.h
libs/gst/controller/gstargbcontrolbinding.c
libs/gst/controller/gstdirectcontrolbinding.c
libs/gst/controller/gstinterpolationcontrolsource.c
libs/gst/controller/gstlfocontrolsource.c
libs/gst/controller/gsttimedvaluecontrolsource.c
libs/gst/controller/gsttriggercontrolsource.c
libs/gst/controller/meson.build
libs/gst/net/gstnetaddressmeta.c
libs/gst/net/gstnetcontrolmessagemeta.c
libs/gst/net/net-prelude.h
meson.build

diff --git a/common b/common
index ed78bee..cd1dee0 160000 (submodule)
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit ed78bee437dcbe22e6eef0031d9a29d157c0461f
+Subproject commit cd1dee06bf07f094677d0cf3eea4a2e8c2636b24
index 79a2b8c..93a6755 100644 (file)
@@ -892,7 +892,13 @@ AC_ARG_WITH([memory-alignment],
 
 dnl Symbol visibility
 VISIBILITY_CFLAGS=""
-AS_COMPILER_FLAG([-fvisibility=hidden], [VISIBILITY_CFLAGS="-fvisibility=hidden"])
+AS_COMPILER_FLAG([-fvisibility=hidden], [
+  VISIBILITY_CFLAGS="-fvisibility=hidden"
+  AC_DEFINE(GST_API_EXPORT, [extern __attribute__ ((visibility ("default")))], [public symbol export define])
+], [
+  VISIBILITY_CFLAGS=""
+  AC_DEFINE(GST_API_EXPORT, [extern], [public symbol export define])
+])
 AC_SUBST(VISIBILITY_CFLAGS)
 
 dnl Check for -Bsymbolic-functions linker flag used to avoid
index a0f5771..41bbdde 100644 (file)
 
 #ifndef GST_API
 # ifdef BUILDING_GST
-#define GST_API GST_EXPORT
+#  define GST_API GST_API_EXPORT        /* from config.h */
 # else
 #  define GST_API GST_API_IMPORT
 # endif
index ae98d38..87defde 100644 (file)
@@ -26,7 +26,7 @@
 
 #ifndef GST_BASE_API
 #ifdef BUILDING_GST_BASE
-#define GST_BASE_API GST_EXPORT
+#define GST_BASE_API GST_API_EXPORT        /* from config.h */
 #else
 #define GST_BASE_API GST_API_IMPORT
 #endif
index 7e4d71e..d6479bb 100644 (file)
@@ -28,6 +28,9 @@
  * also provides size-related functionality. This object should be used for
  * any #GstElement that wishes to provide some sort of queueing functionality.
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <gst/gst.h>
 #include "string.h"
index 831e202..8b64a46 100644 (file)
@@ -60,6 +60,9 @@
  *
  * Since: 1.4
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <gst/gst.h>
 #include "gstflowcombiner.h"
index de8e0b4..353921c 100644 (file)
@@ -29,7 +29,9 @@
  * based on an array instead of linked lists. This reduces the overhead
  * caused by memory management by a large factor.
  */
-
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <string.h>
 #include <gst/gst.h>
index f7faf83..0fc2725 100644 (file)
@@ -26,7 +26,7 @@
 
 #ifndef GST_CHECK_API
 #ifdef BUILDING_GST_CHECK
-#define GST_CHECK_API GST_EXPORT
+#define GST_CHECK_API GST_API_EXPORT        /* from config.h */
 #else
 #define GST_CHECK_API GST_API_IMPORT
 #endif
index 93a2c37..893ae6a 100644 (file)
@@ -28,6 +28,9 @@
  * These macros and functions are for internal use of the unit tests found
  * inside the 'check' directories of various GStreamer packages.
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include "gstbufferstraw.h"
 
index cf1dbf7..aff1875 100644 (file)
@@ -29,6 +29,9 @@
  * These macros and functions are for internal use of the unit tests found
  * inside the 'check' directories of various GStreamer packages.
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include "gstconsistencychecker.h"
 
index c7d278c..cd7f0c9 100644 (file)
@@ -26,7 +26,7 @@
 
 #ifndef GST_CONTROLLER_API
 #ifdef BUILDING_GST_CONTROLLER
-#define GST_CONTROLLER_API GST_EXPORT
+#define GST_CONTROLLER_API GST_API_EXPORT        /* from config.h */
 #else
 #define GST_CONTROLLER_API GST_API_IMPORT
 #endif
index 6fe79e3..b8014a0 100644 (file)
@@ -29,6 +29,9 @@
  * gobject properties representing a color. A control value of 0.0 will turn the
  * color component off and a value of 1.0 will be the color level.
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <glib-object.h>
 #include <gst/gst.h>
index 9e5955d..bcc872e 100644 (file)
@@ -31,6 +31,9 @@
  * will be clipped. An absolute control binding will not do any value
  * transformations.
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <glib-object.h>
 #include <gst/gst.h>
index 77b8132..c0b6c86 100644 (file)
@@ -36,6 +36,9 @@
  * All functions are MT-safe.
  *
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <glib-object.h>
 #include <gst/gst.h>
index 2cea4f8..1706efd 100644 (file)
@@ -35,6 +35,9 @@
  *
  * All functions are MT-safe.
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <float.h>
 
index 35690f3..66c82a9 100644 (file)
@@ -35,6 +35,9 @@
  * All functions are MT-safe.
  *
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <glib-object.h>
 #include <gst/gst.h>
index 6415c0e..0b68cf1 100644 (file)
@@ -36,6 +36,9 @@
  *
  * All functions are MT-safe.
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <glib-object.h>
 #include <gst/gst.h>
index 93a5bec..e592b81 100644 (file)
@@ -29,6 +29,7 @@ install_headers(gst_controller_headers, subdir : 'gstreamer-1.0/gst/controller/'
 controller_enums = gnome.mkenums_simple('controller-enumtypes',
   sources : controller_mkenum_headers,
   header_prefix : '#include <gst/controller/controller-prelude.h>',
+  body_prefix : '#include "config.h"',
   decorator : 'GST_CONTROLLER_API',
   install_header : true,
   install_dir : join_paths(get_option('includedir'), 'gstreamer-1.0/gst/controller'))
index de98a1c..262c578 100644 (file)
@@ -26,6 +26,9 @@
  * in a #GstBuffer so that it network elements can track the to and from address
  * of the buffer.
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <string.h>
 
index d6cc525..4f24834 100644 (file)
@@ -28,6 +28,9 @@
  * sending and receiving ancillary data such as unix credentials (See
  * #GUnixCredentialsMessage) and Unix file descriptions (See #GUnixFDMessage).
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <string.h>
 
index e0cf2f8..47224fe 100644 (file)
@@ -26,7 +26,7 @@
 
 #ifndef GST_NET_API
 #ifdef BUILDING_GST_NET
-#define GST_NET_API GST_EXPORT
+#define GST_NET_API GST_API_EXPORT        /* from config.h */
 #else
 #define GST_NET_API GST_API_IMPORT
 #endif
index a36ce45..6e8b348 100644 (file)
@@ -33,6 +33,8 @@ helpers_install_dir = join_paths(libexecdir, 'gstreamer-1.0')
 
 cc = meson.get_compiler('c')
 
+cdata = configuration_data()
+
 # Ignore several spurious warnings for things gstreamer does very commonly
 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
@@ -51,11 +53,20 @@ elif cc.has_link_argument('-Wl,-Bsymbolic-functions')
 endif
 
 # Symbol visibility
-have_visibility_hidden = cc.has_argument('-fvisibility=hidden')
-if have_visibility_hidden
+have_visibility_hidden = false
+if cc.get_id() == 'msvc'
+  export_define = '__declspec(dllexport) extern'
+elif cc.has_argument('-fvisibility=hidden')
   add_project_arguments('-fvisibility=hidden', language: 'c')
+  export_define = 'extern __attribute__ ((visibility ("default")))'
+  have_visibility_hidden = true
+else
+  export_define = 'extern'
 endif
 
+# Passing this through the command line would be too messy
+cdata.set('GST_API_EXPORT', export_define)
+
 # Disable strict aliasing
 if cc.has_argument('-fno-strict-aliasing')
   add_project_arguments('-fno-strict-aliasing', language: 'c')
@@ -85,7 +96,6 @@ if glib_checks.disabled() or (glib_checks.auto() and not gst_version_is_dev)
   add_project_arguments('-DG_DISABLE_CHECKS', language: 'c')
 endif
 
-cdata = configuration_data()
 cdata.set_quoted('GST_API_VERSION', apiversion)
 cdata.set_quoted('GST_DATADIR', join_paths(prefix, get_option('datadir')))
 cdata.set_quoted('LOCALEDIR', join_paths(prefix, get_option('localedir')))