diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt index be7bbff7faacac9eee494f8c98176e5c83c5f6f2..00e6852a10d206c33b990005680e130fbdeabda3 100644 --- a/cmake/modules/CMakeLists.txt +++ b/cmake/modules/CMakeLists.txt @@ -1,5 +1,6 @@ set(modules DuneBoost.cmake DuneCommonMacros.cmake + DuneCxaDemangle.cmake DuneDoc.cmake DuneDoxygen.cmake DuneMacros.cmake diff --git a/cmake/modules/DuneCxaDemangle.cmake b/cmake/modules/DuneCxaDemangle.cmake new file mode 100644 index 0000000000000000000000000000000000000000..9f480fa9a519fa85a5d95da36df5f5c7fdc3110d --- /dev/null +++ b/cmake/modules/DuneCxaDemangle.cmake @@ -0,0 +1,17 @@ +# Module that checks whether the compiler supports the +# abi::__cxa_demangle function required to +# make the type names returned by typeid() human-readable +# +# Sets the following variable: +# HAVE_CXA_DEMANGLE +# +# perform tests +include(CheckCXXSourceCompiles) + +CHECK_CXX_SOURCE_COMPILES("#include <cxxabi.h> +int main(void){ + int foobar = 0; + const char *foo = typeid(foobar).name(); + int status; + char *demangled = abi::__cxa_demangle( foo, 0, 0, &status ); +}" HAVE_CXA_DEMANGLE) diff --git a/cmake/modules/DuneMacros.cmake b/cmake/modules/DuneMacros.cmake index d7df29597d6a1b7181f0c66f58fee9041f42f0c7..eb23ed70a2954baa72f9c15e20793209c2e64ebb 100644 --- a/cmake/modules/DuneMacros.cmake +++ b/cmake/modules/DuneMacros.cmake @@ -409,6 +409,8 @@ macro(dune_project) # set required compiler flags for C++11 (former C++0x) find_package(CXX11Features) + include(DuneCxaDemangle) + # search for headers include(CheckIncludeFile) include(CheckIncludeFileCXX) diff --git a/cmake/modules/Makefile.am b/cmake/modules/Makefile.am index 278aaa895c8f39600652b18ac18bf255abab99db..04631b7ddae96c54891037b9e56207a31e14888a 100644 --- a/cmake/modules/Makefile.am +++ b/cmake/modules/Makefile.am @@ -1,5 +1,6 @@ MODULES = DuneBoost.cmake \ DuneCommonMacros.cmake \ + DuneCxaDemangle.cmake \ DuneDoc.cmake \ DuneDoxygen.cmake \ DuneMacros.cmake \ diff --git a/config.h.cmake b/config.h.cmake index bd16ee7db44e5456784bad34d77463bcf0f1e206..4ebc98f750a91979d8dfc584666af32d22f6beb2 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -53,6 +53,9 @@ /* Define to 1 if you have the <boost/shared_ptr.hpp> header file. */ #cmakedefine HAVE_BOOST_SHARED_PTR_HPP 1 +/* does the compiler support abi::__cxa_demangle */ +#cmakedefine HAVE_CXA_DEMANGLE 1 + /* Define if you have LAPACK library. */ #cmakedefine HAVE_LAPACK 1 diff --git a/dune/common/classname.hh b/dune/common/classname.hh index 9e96966817040b96ec243884713a54249d62d390..0bc7d8b804e966023a42d4728a3e9eb064a73c97 100644 --- a/dune/common/classname.hh +++ b/dune/common/classname.hh @@ -12,9 +12,9 @@ #include <string> #include <typeinfo> -#if defined(__GNUC__) && ! defined(__clang__) +#if HAVE_CXA_DEMANGLE #include <cxxabi.h> -#endif // #ifdef __GNUC__ +#endif // #if HAVE_CXA_DEMANGLE namespace Dune { @@ -23,7 +23,7 @@ namespace Dune { std::string className ( T &t ) { std::string className = typeid( t ).name(); -#if defined(__GNUC__) && ! defined(__clang__) +#if HAVE_CXA_DEMANGLE int status; char *demangled = abi::__cxa_demangle( className.c_str(), 0, 0, &status ); if( demangled ) @@ -31,7 +31,7 @@ namespace Dune { className = demangled; std::free( demangled ); } -#endif // #ifdef __GNUC__ +#endif // #if HAVE_CXA_DEMANGLE return className; } @@ -40,7 +40,7 @@ namespace Dune { std::string className () { std::string className = typeid( T ).name(); -#if defined(__GNUC__) && ! defined(__clang__) +#if HAVE_CXA_DEMANGLE int status; char *demangled = abi::__cxa_demangle( className.c_str(), 0, 0, &status ); if( demangled ) @@ -48,7 +48,7 @@ namespace Dune { className = demangled; std::free( demangled ); } -#endif // #ifdef __GNUC__ +#endif // #if HAVE_CXA_DEMANGLE return className; } diff --git a/m4/dune_common.m4 b/m4/dune_common.m4 index ffd70f01fb501109012695333797b400975d1532..62daab5f56ff45f38cc14d01ab6e275f802e02e3 100644 --- a/m4/dune_common.m4 +++ b/m4/dune_common.m4 @@ -27,6 +27,7 @@ AC_DEFUN([DUNE_COMMON_CHECKS], AC_REQUIRE([DUNE_LINKCXX]) AC_REQUIRE([DUNE_CHECKDEPRECATED]) AC_REQUIRE([DUNE_CHECKUNUSED]) + AC_REQUIRE([DUNE_CHECK_CXA_DEMANGLE]) AC_REQUIRE([DUNE_SET_MINIMAL_DEBUG_LEVEL]) AC_REQUIRE([DUNE_PATH_XDR]) AC_REQUIRE([DUNE_MPI]) diff --git a/m4/dune_cxa_demangle.m4 b/m4/dune_cxa_demangle.m4 new file mode 100644 index 0000000000000000000000000000000000000000..d87396afa9e31c4451adc85f4baefbe1d866c1f6 --- /dev/null +++ b/m4/dune_cxa_demangle.m4 @@ -0,0 +1,24 @@ +# Check if the compiler supports the abi::__cxa_demangle function required to +# make the type names returned by typeid() human-readable +AC_DEFUN([DUNE_CHECK_CXA_DEMANGLE],[ + AC_CACHE_CHECK([for abi::__cxa_demangle], dune_cv_cxa_demangle, [ + AC_LANG_PUSH([C++]) + AC_TRY_COMPILE([ + #include <cxxabi.h> +], +[ + int foobar = 0; + const char *foo = typeid(foobar).name(); + int status; + char *demangled = abi::__cxa_demangle( foo, 0, 0, &status ); +], + dune_cv_cxa_demangle="yes", + dune_cv_cxa_demangle="no") + AC_LANG_POP([C++]) + ]) + + AS_IF([test "x$dune_cv_cxa_demangle" = "xyes"], + [AC_DEFINE_UNQUOTED(HAVE_CXA_DEMANGLE, + 1, + [does the compiler support abi::__cxa_demangle])]) +])