Re: Testing for compiler capabilities

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> is there a simple macro that will test for a specific compiler flag and set
> a variable in both Makefile and config.h?
> I am looking for an easy way to test for GCC's -fvisibility=hidden and
> have an indicator whether or not it is available in said files.

Hi,
	Here's (attached) a test for visibility attributes instead of
visibility flags, which might give the same effect.  It defines the
config.h variables HAVE_ATTRIBUTE_VISIBILITY_HIDDEN and
HAVE_ATTRIBUTE_VISIBILITY_DEFAULT if the respective attributes are
understood.  You can easily add an AM_CONDITIONAL to it as well.  This
particular test runs in C++ mode.  I had to temporarily add the -Werror
flag to the compile flags to make the compiler reject warnings about
unsupported attributes.  Feedback is welcome.

Fang
dnl @synopsis FANG_CXX_ATTRIBUTE_VISIBILITY
dnl
dnl Checking for visibility attributes, "hidden" and "default"
dnl New since gcc-4.0.
dnl Define HAVE_ATTRIBUTE_VISIBILITY_HIDDEN if supported.  
dnl Define HAVE_ATTRIBUTE_VISIBILITY_DEFAULT if supported.  
dnl
dnl @category Cxx
dnl @version 2006-05-08
dnl @author David Fang <fangism@xxxxxxxxxxxxxxxxxxxxx>
dnl @license AllPermissive
dnl
AC_DEFUN([FANG_CXX_ATTRIBUTE_VISIBILITY],
[
AC_LANG_PUSH(C++)
saved_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$saved_CXXFLAGS -Werror"
dnl check for __visibility__(("hidden"))
AC_CACHE_CHECK([whether compiler accepts __attribute__((visibility("hidden")))],
[fang_cv_cxx_attribute_visibility_hidden],
	AC_COMPILE_IFELSE(
		AC_LANG_PROGRAM(
		[struct __attribute__((visibility("hidden"))) foo {
			foo() { }
			~foo() { }
		};],
		[foo bar;]),
		[fang_cv_cxx_attribute_visibility_hidden=yes],
		[fang_cv_cxx_attribute_visibility_hidden=no]
	)
)
if test "$fang_cv_cxx_attribute_visibility_hidden" = "yes"; then
AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY_HIDDEN, [],
        [True if compiler supports __attribute__((visibility("hidden"))) ])
fi
dnl check for __visibility__(("default"))
AC_CACHE_CHECK([whether compiler accepts __attribute__((visibility("default")))],
[fang_cv_cxx_attribute_visibility_default],
	AC_COMPILE_IFELSE(
		AC_LANG_PROGRAM(
		[struct __attribute__((visibility("default"))) foo {
			foo() { }
			~foo() { }
		};],
		[foo bar;]),
		[fang_cv_cxx_attribute_visibility_default=yes],
		[fang_cv_cxx_attribute_visibility_default=no]
	)
)
if test "$fang_cv_cxx_attribute_visibility_default" = "yes"; then
AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY_DEFAULT, [],
        [True if compiler supports __attribute__((visibility("default"))) ])
fi
dnl restore flags and language
CXXFLAGS=$saved_CXXFLAGS
AC_LANG_POP(C++)
])dnl


_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux