From bca16e8fb4c221b7dda2915760f50023eff572ca Mon Sep 17 00:00:00 2001 From: Markus Blatt <mblatt@dune-project.org> Date: Mon, 18 Feb 2013 19:06:56 +0000 Subject: [PATCH] Merged recent changes from the trunk and add test for cxa_demangle to CMake build system. [[Imported from SVN: r7129]] --- cmake/modules/CMakeLists.txt | 1 + cmake/modules/DuneCxaDemangle.cmake | 17 +++++++++++++++++ cmake/modules/DuneMacros.cmake | 2 ++ cmake/modules/Makefile.am | 1 + config.h.cmake | 3 +++ dune/common/classname.hh | 12 ++++++------ m4/dune_common.m4 | 1 + m4/dune_cxa_demangle.m4 | 24 ++++++++++++++++++++++++ 8 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 cmake/modules/DuneCxaDemangle.cmake create mode 100644 m4/dune_cxa_demangle.m4 diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt index be7bbff7f..00e6852a1 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 000000000..9f480fa9a --- /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 d7df29597..eb23ed70a 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 278aaa895..04631b7dd 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 bd16ee7db..4ebc98f75 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 9e9696681..0bc7d8b80 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 ffd70f01f..62daab5f5 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 000000000..d87396afa --- /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])]) +]) -- GitLab