summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2023-01-09 15:01:52 +0000
committerSimon McVittie <smcv@collabora.com>2023-01-09 15:01:52 +0000
commit237063358edd9175dfee7835cf4e4379edb8ebd2 (patch)
tree9eb2f47ef4669073e6ebf1aa2dbb1a34a6488f47
parent81dc8af6ae0ee79923bdb4bd7e825c52c19aaa60 (diff)
parentc1661d7c5dd35aeffaa4b3b6f2c3a54355cdbe98 (diff)
Merge branch 'meson-fvisibility-hidden' into 'master'
meson: Use -fvisibility=hidden on Unix if supported See merge request dbus/dbus!383
-rw-r--r--meson.build21
1 files changed, 21 insertions, 0 deletions
diff --git a/meson.build b/meson.build
index fdb54e77..31423007 100644
--- a/meson.build
+++ b/meson.build
@@ -200,6 +200,27 @@ if using_cpp
add_project_arguments(compile_args_cpp, language: 'cpp')
endif
+# Try to use hidden visibility on Unix. We don't do this on Windows to avoid
+# interfering with use of __declspec(dllexport) and __declspec(dllimport),
+# which have a similar effect.
+if cc.has_argument('-fvisibility=hidden') and not platform_windows
+ default_visibility = '__attribute__ ((__visibility__ ("default")))'
+ test_visibility = '''
+@0@ void public_func (void);
+@0@ int public_var;
+int main (void) { return 0; }
+'''.format(default_visibility)
+
+ if cc.compiles(test_visibility, args: compile_args_c + ['-fvisibility=hidden'])
+ add_project_arguments(['-fvisibility=hidden'], language: 'c')
+ config.set('DBUS_PRIVATE_EXPORT', default_visibility)
+ config.set('DBUS_EXPORT', default_visibility)
+ # If we were using C++ then we'd need to add -fvisibility=hidden
+ # to the C++ arguments too, but that's not currently applicable here.
+ assert(not using_cpp, 'C++ only used on Windows')
+ endif
+endif
+
if host_machine.endian() == 'big'
config.set('WORDS_BIGENDIAN', 1)
endif