visibility.m4 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. dnl From Bruno Haible.
  7. dnl Modified for use in wxWidgets by Vaclav Slavik:
  8. dnl - don't define HAVE_VISIBILITY (=0) if not supported
  9. dnl - use -fvisibility-inlines-hidden too
  10. dnl - test in C++ mode
  11. dnl Tests whether the compiler supports the command-line option
  12. dnl -fvisibility=hidden and the function and variable attributes
  13. dnl __attribute__((__visibility__("hidden"))) and
  14. dnl __attribute__((__visibility__("default"))).
  15. dnl Does *not* test for __visibility__("protected") - which has tricky
  16. dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on
  17. dnl MacOS X.
  18. dnl Does *not* test for __visibility__("internal") - which has processor
  19. dnl dependent semantics.
  20. dnl Does *not* test for #pragma GCC visibility push(hidden) - which is
  21. dnl "really only recommended for legacy code".
  22. dnl Set the variable CFLAG_VISIBILITY.
  23. dnl Defines and sets the variable HAVE_VISIBILITY.
  24. AC_DEFUN([WX_VISIBILITY],
  25. [
  26. AC_REQUIRE([AC_PROG_CC])
  27. if test -n "$GCC"; then
  28. CFLAGS_VISIBILITY="-fvisibility=hidden"
  29. CXXFLAGS_VISIBILITY="-fvisibility=hidden -fvisibility-inlines-hidden"
  30. AC_MSG_CHECKING([for symbols visibility support])
  31. AC_CACHE_VAL(wx_cv_cc_visibility, [
  32. wx_save_CXXFLAGS="$CXXFLAGS"
  33. CXXFLAGS="$CXXFLAGS $CXXFLAGS_VISIBILITY"
  34. AC_LANG_PUSH(C++)
  35. AC_TRY_COMPILE(
  36. [
  37. /* we need gcc >= 4.0, older versions with visibility support
  38. didn't have class visibility: */
  39. #if defined(__GNUC__) && __GNUC__ < 4
  40. error this gcc is too old;
  41. #endif
  42. /* visibility only makes sense for ELF shared libs: */
  43. #if !defined(__ELF__) && !defined(__APPLE__)
  44. error this platform has no visibility;
  45. #endif
  46. /* at the time of Xcode 4.1 / Clang 3, Clang++ still didn't have the bugs sorted out: */
  47. #if defined(__clang__)
  48. clang compiler is still broken w.r.t. visibility;
  49. #endif
  50. extern __attribute__((__visibility__("hidden"))) int hiddenvar;
  51. extern __attribute__((__visibility__("default"))) int exportedvar;
  52. extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
  53. extern __attribute__((__visibility__("default"))) int exportedfunc (void);
  54. class __attribute__((__visibility__("default"))) Foo {
  55. Foo() {}
  56. };
  57. ],
  58. [],
  59. wx_cv_cc_visibility=yes,
  60. wx_cv_cc_visibility=no)
  61. AC_LANG_POP()
  62. CXXFLAGS="$wx_save_CXXFLAGS"])
  63. AC_MSG_RESULT([$wx_cv_cc_visibility])
  64. if test $wx_cv_cc_visibility = yes; then
  65. dnl we do have basic visibility support, now check if we can use it:
  66. dnl
  67. dnl Debian/Ubuntu's gcc 4.1 is affected:
  68. dnl https://bugs.launchpad.net/ubuntu/+source/gcc-4.1/+bug/109262
  69. AC_MSG_CHECKING([for broken libstdc++ visibility])
  70. AC_CACHE_VAL(wx_cv_cc_broken_libstdcxx_visibility, [
  71. wx_save_CXXFLAGS="$CXXFLAGS"
  72. wx_save_LDFLAGS="$LDFLAGS"
  73. CXXFLAGS="$CXXFLAGS $CXXFLAGS_VISIBILITY"
  74. LDFLAGS="$LDFLAGS -shared -fPIC"
  75. AC_LANG_PUSH(C++)
  76. AC_TRY_LINK(
  77. [
  78. #include <string>
  79. ],
  80. [
  81. std::string s("hello");
  82. return s.length();
  83. ],
  84. wx_cv_cc_broken_libstdcxx_visibility=no,
  85. wx_cv_cc_broken_libstdcxx_visibility=yes)
  86. AC_LANG_POP()
  87. CXXFLAGS="$wx_save_CXXFLAGS"
  88. LDFLAGS="$wx_save_LDFLAGS"])
  89. AC_MSG_RESULT([$wx_cv_cc_broken_libstdcxx_visibility])
  90. if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then
  91. AC_MSG_CHECKING([whether we can work around it])
  92. AC_CACHE_VAL(wx_cv_cc_visibility_workaround, [
  93. AC_LANG_PUSH(C++)
  94. AC_TRY_LINK(
  95. [
  96. #pragma GCC visibility push(default)
  97. #include <string>
  98. #pragma GCC visibility pop
  99. ],
  100. [
  101. std::string s("hello");
  102. return s.length();
  103. ],
  104. wx_cv_cc_visibility_workaround=no,
  105. wx_cv_cc_visibility_workaround=yes)
  106. AC_LANG_POP()
  107. ])
  108. AC_MSG_RESULT([$wx_cv_cc_visibility_workaround])
  109. if test $wx_cv_cc_visibility_workaround = no; then
  110. dnl we can't use visibility at all then
  111. wx_cv_cc_visibility=no
  112. fi
  113. fi
  114. fi
  115. if test $wx_cv_cc_visibility = yes; then
  116. AC_DEFINE([HAVE_VISIBILITY])
  117. if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then
  118. AC_DEFINE([HAVE_BROKEN_LIBSTDCXX_VISIBILITY])
  119. fi
  120. else
  121. CFLAGS_VISIBILITY=""
  122. CXXFLAGS_VISIBILITY=""
  123. fi
  124. AC_SUBST([CFLAGS_VISIBILITY])
  125. AC_SUBST([CXXFLAGS_VISIBILITY])
  126. fi
  127. ])