]> git.saurik.com Git - wxWidgets.git/blobdiff - build/aclocal/visibility.m4
reuse wxObjectRefData for various ref-counted classes (closes #10886)
[wxWidgets.git] / build / aclocal / visibility.m4
index 35a9ea02414f52ea41741b894cb3227ab40d09b6..52c97f9c8ef605d1f7481ceaf66e1227ecb29932 100644 (file)
@@ -43,7 +43,12 @@ AC_DEFUN([WX_VISIBILITY],
          #if defined(__GNUC__) && __GNUC__ < 4
          error this gcc is too old;
          #endif
-          
+
+         /* visibility only makes sense for ELF shared libs: */
+         #if !defined(__ELF__) && !defined(__APPLE__)
+         error this platform has no visibility;
+         #endif
+
          extern __attribute__((__visibility__("hidden"))) int hiddenvar;
          extern __attribute__((__visibility__("default"))) int exportedvar;
          extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
@@ -59,31 +64,64 @@ AC_DEFUN([WX_VISIBILITY],
       CXXFLAGS="$wx_save_CXXFLAGS"])
     AC_MSG_RESULT([$wx_cv_cc_visibility])
     if test $wx_cv_cc_visibility = yes; then
-      AC_DEFINE([HAVE_VISIBILITY])
-
+      dnl we do have basic visibility support, now check if we can use it:
+      dnl
       dnl Debian/Ubuntu's gcc 4.1 is affected:
       dnl https://bugs.launchpad.net/ubuntu/+source/gcc-4.1/+bug/109262
       AC_MSG_CHECKING([for broken libstdc++ visibility])
       AC_CACHE_VAL(wx_cv_cc_broken_libstdcxx_visibility, [
         wx_save_CXXFLAGS="$CXXFLAGS"
+        wx_save_LDFLAGS="$LDFLAGS"
         CXXFLAGS="$CXXFLAGS $CXXFLAGS_VISIBILITY"
+        LDFLAGS="$LDFLAGS -shared -fPIC"
         AC_LANG_PUSH(C++)
         AC_TRY_LINK(
           [
             #include <string>
           ],
           [
-            std::string x;
+            std::string s("hello");
+            return s.length();
           ],
           wx_cv_cc_broken_libstdcxx_visibility=no,
           wx_cv_cc_broken_libstdcxx_visibility=yes)
         AC_LANG_POP()
-        CXXFLAGS="$wx_save_CXXFLAGS"])
+        CXXFLAGS="$wx_save_CXXFLAGS"
+        LDFLAGS="$wx_save_LDFLAGS"])
       AC_MSG_RESULT([$wx_cv_cc_broken_libstdcxx_visibility])
+
       if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then
-        AC_DEFINE([HAVE_BROKEN_LIBSTDCXX_VISIBILITY])
+        AC_MSG_CHECKING([whether we can work around it])
+        AC_CACHE_VAL(wx_cv_cc_visibility_workaround, [
+          AC_LANG_PUSH(C++)
+          AC_TRY_LINK(
+            [
+              #pragma GCC visibility push(default)
+              #include <string>
+              #pragma GCC visibility pop
+            ],
+            [
+              std::string s("hello");
+              return s.length();
+            ],
+            wx_cv_cc_visibility_workaround=no,
+            wx_cv_cc_visibility_workaround=yes)
+          AC_LANG_POP()
+        ])
+        AC_MSG_RESULT([$wx_cv_cc_visibility_workaround])
+
+        if test $wx_cv_cc_visibility_workaround = no; then
+          dnl we can't use visibility at all then
+          wx_cv_cc_visibility=no
+        fi
       fi
+    fi
 
+    if test $wx_cv_cc_visibility = yes; then
+      AC_DEFINE([HAVE_VISIBILITY])
+      if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then
+        AC_DEFINE([HAVE_BROKEN_LIBSTDCXX_VISIBILITY])
+      fi
     else
       CFLAGS_VISIBILITY=""
       CXXFLAGS_VISIBILITY=""