]> git.saurik.com Git - wxWidgets.git/blame - build/aclocal/visibility.m4
Fix wxHash{Set,Map} compilation with g++ 4.7 in C++11 mode.
[wxWidgets.git] / build / aclocal / visibility.m4
CommitLineData
0ff20b9f
VS
1dnl visibility.m4 serial 1 (gettext-0.15)
2dnl Copyright (C) 2005 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Bruno Haible.
8
9dnl Modified for use in wxWidgets by Vaclav Slavik:
10dnl - don't define HAVE_VISIBILITY (=0) if not supported
11dnl - use -fvisibility-inlines-hidden too
12dnl - test in C++ mode
13
14dnl Tests whether the compiler supports the command-line option
15dnl -fvisibility=hidden and the function and variable attributes
16dnl __attribute__((__visibility__("hidden"))) and
17dnl __attribute__((__visibility__("default"))).
18dnl Does *not* test for __visibility__("protected") - which has tricky
19dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on
20dnl MacOS X.
21dnl Does *not* test for __visibility__("internal") - which has processor
22dnl dependent semantics.
23dnl Does *not* test for #pragma GCC visibility push(hidden) - which is
24dnl "really only recommended for legacy code".
25dnl Set the variable CFLAG_VISIBILITY.
26dnl Defines and sets the variable HAVE_VISIBILITY.
27
28AC_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
b9d4eff6
VS
46
47 /* visibility only makes sense for ELF shared libs: */
48 #if !defined(__ELF__) && !defined(__APPLE__)
49 error this platform has no visibility;
50 #endif
51
7198c336
VS
52 /* at the time of Xcode 4.1 / Clang 3, Clang++ still didn't have the bugs sorted out: */
53 #if defined(__clang__)
54 clang compiler is still broken w.r.t. visibility;
55 #endif
56
0ff20b9f
VS
57 extern __attribute__((__visibility__("hidden"))) int hiddenvar;
58 extern __attribute__((__visibility__("default"))) int exportedvar;
59 extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
60 extern __attribute__((__visibility__("default"))) int exportedfunc (void);
61 class __attribute__((__visibility__("default"))) Foo {
62 Foo() {}
63 };
64 ],
65 [],
66 wx_cv_cc_visibility=yes,
67 wx_cv_cc_visibility=no)
68 AC_LANG_POP()
69 CXXFLAGS="$wx_save_CXXFLAGS"])
70 AC_MSG_RESULT([$wx_cv_cc_visibility])
71 if test $wx_cv_cc_visibility = yes; then
c9bd045b
VZ
72 dnl we do have basic visibility support, now check if we can use it:
73 dnl
d6f513f8
VS
74 dnl Debian/Ubuntu's gcc 4.1 is affected:
75 dnl https://bugs.launchpad.net/ubuntu/+source/gcc-4.1/+bug/109262
76 AC_MSG_CHECKING([for broken libstdc++ visibility])
77 AC_CACHE_VAL(wx_cv_cc_broken_libstdcxx_visibility, [
78 wx_save_CXXFLAGS="$CXXFLAGS"
34b340a0 79 wx_save_LDFLAGS="$LDFLAGS"
d6f513f8 80 CXXFLAGS="$CXXFLAGS $CXXFLAGS_VISIBILITY"
34b340a0 81 LDFLAGS="$LDFLAGS -shared -fPIC"
d6f513f8
VS
82 AC_LANG_PUSH(C++)
83 AC_TRY_LINK(
84 [
85 #include <string>
86 ],
87 [
34b340a0
VS
88 std::string s("hello");
89 return s.length();
d6f513f8
VS
90 ],
91 wx_cv_cc_broken_libstdcxx_visibility=no,
92 wx_cv_cc_broken_libstdcxx_visibility=yes)
93 AC_LANG_POP()
34b340a0
VS
94 CXXFLAGS="$wx_save_CXXFLAGS"
95 LDFLAGS="$wx_save_LDFLAGS"])
d6f513f8 96 AC_MSG_RESULT([$wx_cv_cc_broken_libstdcxx_visibility])
c9bd045b 97
d6f513f8 98 if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then
c9bd045b
VZ
99 AC_MSG_CHECKING([whether we can work around it])
100 AC_CACHE_VAL(wx_cv_cc_visibility_workaround, [
101 AC_LANG_PUSH(C++)
102 AC_TRY_LINK(
103 [
104 #pragma GCC visibility push(default)
105 #include <string>
106 #pragma GCC visibility pop
107 ],
108 [
109 std::string s("hello");
110 return s.length();
111 ],
112 wx_cv_cc_visibility_workaround=no,
113 wx_cv_cc_visibility_workaround=yes)
114 AC_LANG_POP()
115 ])
116 AC_MSG_RESULT([$wx_cv_cc_visibility_workaround])
117
118 if test $wx_cv_cc_visibility_workaround = no; then
119 dnl we can't use visibility at all then
120 wx_cv_cc_visibility=no
121 fi
d6f513f8 122 fi
c9bd045b 123 fi
d6f513f8 124
c9bd045b
VZ
125 if test $wx_cv_cc_visibility = yes; then
126 AC_DEFINE([HAVE_VISIBILITY])
127 if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then
128 AC_DEFINE([HAVE_BROKEN_LIBSTDCXX_VISIBILITY])
129 fi
0ff20b9f
VS
130 else
131 CFLAGS_VISIBILITY=""
132 CXXFLAGS_VISIBILITY=""
133 fi
134 AC_SUBST([CFLAGS_VISIBILITY])
135 AC_SUBST([CXXFLAGS_VISIBILITY])
136 fi
137])