]> git.saurik.com Git - wxWidgets.git/blame_incremental - build/aclocal/visibility.m4
add a few comments about wxDEPRECATED stuff to ease upgrade path (closes #10628)
[wxWidgets.git] / build / aclocal / visibility.m4
... / ...
CommitLineData
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
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
52 extern __attribute__((__visibility__("hidden"))) int hiddenvar;
53 extern __attribute__((__visibility__("default"))) int exportedvar;
54 extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
55 extern __attribute__((__visibility__("default"))) int exportedfunc (void);
56 class __attribute__((__visibility__("default"))) Foo {
57 Foo() {}
58 };
59 ],
60 [],
61 wx_cv_cc_visibility=yes,
62 wx_cv_cc_visibility=no)
63 AC_LANG_POP()
64 CXXFLAGS="$wx_save_CXXFLAGS"])
65 AC_MSG_RESULT([$wx_cv_cc_visibility])
66 if test $wx_cv_cc_visibility = yes; then
67 dnl we do have basic visibility support, now check if we can use it:
68 dnl
69 dnl Debian/Ubuntu's gcc 4.1 is affected:
70 dnl https://bugs.launchpad.net/ubuntu/+source/gcc-4.1/+bug/109262
71 AC_MSG_CHECKING([for broken libstdc++ visibility])
72 AC_CACHE_VAL(wx_cv_cc_broken_libstdcxx_visibility, [
73 wx_save_CXXFLAGS="$CXXFLAGS"
74 wx_save_LDFLAGS="$LDFLAGS"
75 CXXFLAGS="$CXXFLAGS $CXXFLAGS_VISIBILITY"
76 LDFLAGS="$LDFLAGS -shared -fPIC"
77 AC_LANG_PUSH(C++)
78 AC_TRY_LINK(
79 [
80 #include <string>
81 ],
82 [
83 std::string s("hello");
84 return s.length();
85 ],
86 wx_cv_cc_broken_libstdcxx_visibility=no,
87 wx_cv_cc_broken_libstdcxx_visibility=yes)
88 AC_LANG_POP()
89 CXXFLAGS="$wx_save_CXXFLAGS"
90 LDFLAGS="$wx_save_LDFLAGS"])
91 AC_MSG_RESULT([$wx_cv_cc_broken_libstdcxx_visibility])
92
93 if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then
94 AC_MSG_CHECKING([whether we can work around it])
95 AC_CACHE_VAL(wx_cv_cc_visibility_workaround, [
96 AC_LANG_PUSH(C++)
97 AC_TRY_LINK(
98 [
99 #pragma GCC visibility push(default)
100 #include <string>
101 #pragma GCC visibility pop
102 ],
103 [
104 std::string s("hello");
105 return s.length();
106 ],
107 wx_cv_cc_visibility_workaround=no,
108 wx_cv_cc_visibility_workaround=yes)
109 AC_LANG_POP()
110 ])
111 AC_MSG_RESULT([$wx_cv_cc_visibility_workaround])
112
113 if test $wx_cv_cc_visibility_workaround = no; then
114 dnl we can't use visibility at all then
115 wx_cv_cc_visibility=no
116 fi
117 fi
118 fi
119
120 if test $wx_cv_cc_visibility = yes; then
121 AC_DEFINE([HAVE_VISIBILITY])
122 if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then
123 AC_DEFINE([HAVE_BROKEN_LIBSTDCXX_VISIBILITY])
124 fi
125 else
126 CFLAGS_VISIBILITY=""
127 CXXFLAGS_VISIBILITY=""
128 fi
129 AC_SUBST([CFLAGS_VISIBILITY])
130 AC_SUBST([CXXFLAGS_VISIBILITY])
131 fi
132])