]> git.saurik.com Git - wxWidgets.git/blob - build/aclocal/visibility.m4
the Ubuntu visibility bug only happens when building shared libraries on some systems...
[wxWidgets.git] / build / aclocal / visibility.m4
1 dnl visibility.m4 serial 1 (gettext-0.15)
2 dnl Copyright (C) 2005 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Bruno Haible.
8
9 dnl Modified for use in wxWidgets by Vaclav Slavik:
10 dnl - don't define HAVE_VISIBILITY (=0) if not supported
11 dnl - use -fvisibility-inlines-hidden too
12 dnl - test in C++ mode
13
14 dnl Tests whether the compiler supports the command-line option
15 dnl -fvisibility=hidden and the function and variable attributes
16 dnl __attribute__((__visibility__("hidden"))) and
17 dnl __attribute__((__visibility__("default"))).
18 dnl Does *not* test for __visibility__("protected") - which has tricky
19 dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on
20 dnl MacOS X.
21 dnl Does *not* test for __visibility__("internal") - which has processor
22 dnl dependent semantics.
23 dnl Does *not* test for #pragma GCC visibility push(hidden) - which is
24 dnl "really only recommended for legacy code".
25 dnl Set the variable CFLAG_VISIBILITY.
26 dnl Defines and sets the variable HAVE_VISIBILITY.
27
28 AC_DEFUN([WX_VISIBILITY],
29 [
30 AC_REQUIRE([AC_PROG_CC])
31 if test -n "$GCC"; then
32 CFLAGS_VISIBILITY="-fvisibility=hidden"
33 CXXFLAGS_VISIBILITY="-fvisibility=hidden -fvisibility-inlines-hidden"
34 AC_MSG_CHECKING([for symbols visibility support])
35 AC_CACHE_VAL(wx_cv_cc_visibility, [
36 wx_save_CXXFLAGS="$CXXFLAGS"
37 CXXFLAGS="$CXXFLAGS $CXXFLAGS_VISIBILITY"
38 AC_LANG_PUSH(C++)
39 AC_TRY_COMPILE(
40 [
41 /* we need gcc >= 4.0, older versions with visibility support
42 didn't have class visibility: */
43 #if defined(__GNUC__) && __GNUC__ < 4
44 error this gcc is too old;
45 #endif
46
47 extern __attribute__((__visibility__("hidden"))) int hiddenvar;
48 extern __attribute__((__visibility__("default"))) int exportedvar;
49 extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
50 extern __attribute__((__visibility__("default"))) int exportedfunc (void);
51 class __attribute__((__visibility__("default"))) Foo {
52 Foo() {}
53 };
54 ],
55 [],
56 wx_cv_cc_visibility=yes,
57 wx_cv_cc_visibility=no)
58 AC_LANG_POP()
59 CXXFLAGS="$wx_save_CXXFLAGS"])
60 AC_MSG_RESULT([$wx_cv_cc_visibility])
61 if test $wx_cv_cc_visibility = yes; then
62 AC_DEFINE([HAVE_VISIBILITY])
63
64 dnl Debian/Ubuntu's gcc 4.1 is affected:
65 dnl https://bugs.launchpad.net/ubuntu/+source/gcc-4.1/+bug/109262
66 AC_MSG_CHECKING([for broken libstdc++ visibility])
67 AC_CACHE_VAL(wx_cv_cc_broken_libstdcxx_visibility, [
68 wx_save_CXXFLAGS="$CXXFLAGS"
69 wx_save_LDFLAGS="$LDFLAGS"
70 CXXFLAGS="$CXXFLAGS $CXXFLAGS_VISIBILITY"
71 LDFLAGS="$LDFLAGS -shared -fPIC"
72 AC_LANG_PUSH(C++)
73 AC_TRY_LINK(
74 [
75 #include <string>
76 ],
77 [
78 std::string s("hello");
79 return s.length();
80 ],
81 wx_cv_cc_broken_libstdcxx_visibility=no,
82 wx_cv_cc_broken_libstdcxx_visibility=yes)
83 AC_LANG_POP()
84 CXXFLAGS="$wx_save_CXXFLAGS"
85 LDFLAGS="$wx_save_LDFLAGS"])
86 AC_MSG_RESULT([$wx_cv_cc_broken_libstdcxx_visibility])
87 if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then
88 AC_DEFINE([HAVE_BROKEN_LIBSTDCXX_VISIBILITY])
89 fi
90
91 else
92 CFLAGS_VISIBILITY=""
93 CXXFLAGS_VISIBILITY=""
94 fi
95 AC_SUBST([CFLAGS_VISIBILITY])
96 AC_SUBST([CXXFLAGS_VISIBILITY])
97 fi
98 ])