Skip to content

Commit 478c1fe

Browse files
committed
dispatch: introduce dispatch_STATIC and honour dispatch_EXPORT
When building with CMake, `dispatch_EXPORT` is automatically defined when building a shared library. We should additionally rely on `dispatch_STATIC` to indicate that we are building a static library. When building statically, we should ensure that the ABI of dispatch does not participate in dynamic linking as otherwise any consuming library would vend the dispatch ABI. Particularly for Linux, this would be problematic as the symbol resolution is ill-defined and can end up with multiple incompatible definitions.
1 parent 67a9a5a commit 478c1fe

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

dispatch/base.h

+17-9
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,24 @@
186186
# endif
187187
#define
188188

189-
#if defined(_WIN32)
190-
#if defined(__DISPATCH_BUILDING_DISPATCH__)
191-
#define DISPATCH_EXPORT DISPATCH_EXTERN __declspec(dllexport)
192-
#else
193-
#define DISPATCH_EXPORT DISPATCH_EXTERN __declspec(dllimport)
194-
#endif
195-
#elif __GNUC__
196-
#define DISPATCH_EXPORT DISPATCH_EXTERN __attribute__((visibility("default")))
189+
#if defined(dispatch_STATIC)
190+
# if defined(__GNUC__)
191+
# define DISPATCH_EXPORT DISPATCH_EXTERN __attribute__((__visibility__("hidden")))
192+
# else
193+
# define DISPATCH_EXPORT DISPATCH_EXTERN
194+
# endif
197195
#else
198-
#define DISPATCH_EXPORT DISPATCH_EXTERN
196+
# if defined(_WIN32)
197+
# if defined(dispatch_EXPORT) || defined(__DISPATCH_BUILDING_DISPATCH__)
198+
# define DISPATCH_EXPORT DISPATCH_EXTERN __declspec(dllexport)
199+
# else
200+
# define DISPATCH_EXPORT DISPATCH_EXTERN __declspec(dllimport)
201+
# endif
202+
# elif __GNUC__
203+
# define DISPATCH_EXPORT DISPATCH_EXTERN __attribute__((__visibility__("default")))
204+
# else
205+
# define DISPATCH_EXPORT DISPATCH_EXTERN
206+
# endif
199207
#endif
200208

201209
#if __GNUC__

0 commit comments

Comments
 (0)