This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
test for visibility
- From: "James K. Lowden" <jklowden at schemamania dot org>
- To: binutils at sourceware dot org
- Date: Wed, 25 Apr 2012 15:06:43 -0400
- Subject: test for visibility
I would like to be able to test whether or not the preprocessor
supports the visibility pragma. My program today says:
#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
#pragma GCC visibility push(hidden)
#endif
which cries out for a feature test
#if HAVE_PRAGMA_VISIBILITY
#pragma GCC visibility push(hidden)
#endif
because e.g. clang defines GCC.
My search of the docs and the m4 macro archive didn't turn up anything,
so I thought maybe I'd contribute one. The macro below almost works,
but for the fact that clang only warns about the construct. (It is
the warnings I would like to squelch.)
How do I tell the compiler to use -Werror within an m4 macro? I see
AC_LANG_WERROR and AC_PROG_CPP_WERROR, but afaict they aren't available
within m4. Alternatively, how can I construct a macro that returns
"no" if the compiler issues a diagnostic?
Text of the macro follows. Many thanks for your advice.
--jkl
dnl Test whether or not the compiler supports visibility
AC_DEFUN([AC_HAVE_PRAGMA_VISIBILITY],
[AC_CACHE_CHECK([whether the compiler supports visibility],
ac_cv_have_pragma_visibility,
[AC_LINK_IFELSE([AC_LANG_PROGRAM([
#pragma GCC visibility push(hidden)
],[
int i;
])],
ac_cv_have_pragma_visibility=yes,
ac_cv_have_pragma_visibility=no)])
if test $ac_cv_have_pragma_visibility = yes; then
AC_DEFINE(HAVE_PRAGMA_VISIBILITY, 1,
[Define to 1 if your system supports pragma GCC visibility.])
fi])