From 43631f70f44b036ddfa5b40a15d3c9c19721b315 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Thu, 2 Apr 2020 09:07:09 -0400 Subject: [PATCH] attempt to reduce the compilation noise in the generated code by wrapping into pragmas --- CHANGES | 3 ++- include/libint2/config.h.in | 42 +++++++++++++++++++++++++++++++++++++ src/bin/libint/context.cc | 4 ++-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 57074721c..cd7cbdaa4 100644 --- a/CHANGES +++ b/CHANGES @@ -3,9 +3,10 @@ Following is a brief summary of changes made in each release of Libint. -- 2019-04-01: 2.7.0-beta.5 +- 2019-04-02: 2.7.0-beta.5 - made usable as a CMake subproject - the deprecated autotools build harness has been removed from the exported library; CMake is the only way to build exported libs + - reduced compilation noise in generated code - 2019-03-01: 2.7.0-beta.4 - PR #159: fixed description of cmake option REQUIRE_CXX_API diff --git a/include/libint2/config.h.in b/include/libint2/config.h.in index d96590995..f67334ef1 100644 --- a/include/libint2/config.h.in +++ b/include/libint2/config.h.in @@ -305,4 +305,46 @@ /* have posix_memalign ? */ #undef HAVE_POSIX_MEMALIGN +/* compiler type detection */ +#define LIBINT_COMPILER_ID_GNU 0 +#define LIBINT_COMPILER_ID_Clang 1 +#define LIBINT_COMPILER_ID_AppleClang 2 +#define LIBINT_COMPILER_ID_XLClang 3 +#define LIBINT_COMPILER_ID_Intel 4 +#if defined(__INTEL_COMPILER_BUILD_DATE) /* macros like __ICC and even __INTEL_COMPILER can be affected by command options like -no-icc */ +# define LIBINT_COMPILER_ID LIBINT_COMPILER_ID_Intel +# define LIBINT_COMPILER_IS_ICC 1 +#endif +#if defined(__clang__) && !defined(LIBINT_COMPILER_IS_ICC) +# define LIBINT_COMPILER_IS_CLANG 1 +# if defined(__apple_build_version__) +# define LIBINT_COMPILER_ID LIBINT_COMPILER_ID_AppleClang +# elif defined(__ibmxl__) +# define LIBINT_COMPILER_ID LIBINT_COMPILER_ID_XLClang +# else +# define LIBINT_COMPILER_ID LIBINT_COMPILER_ID_Clang +# endif +#endif +#if defined(__GNUG__) && !defined(LIBINT_COMPILER_IS_ICC) && !defined(LIBINT_COMPILER_IS_CLANG) +# define LIBINT_COMPILER_ID LIBINT_COMPILER_ID_GNU +# define LIBINT_COMPILER_IS_GCC 1 +#endif + +/* ----------- pragma helpers ---------------*/ +#define LIBINT_PRAGMA(x) _Pragma(#x) +/* same as LIBINT_PRAGMA(x), but expands x */ +#define LIBINT_XPRAGMA(x) LIBINT_PRAGMA(x) +/* "concats" a and b with a space in between */ +#define LIBINT_CONCAT(a,b) a b +#if defined(LIBINT_COMPILER_IS_CLANG) +#define LIBINT_PRAGMA_CLANG(x) LIBINT_XPRAGMA( LIBINT_CONCAT(clang,x) ) +#else +#define LIBINT_PRAGMA_CLANG(x) +#endif +#if defined(LIBINT_COMPILER_IS_GCC) +#define LIBINT_PRAGMA_GCC(x) LIBINT_XPRAGMA( LIBINT_CONCAT(GCC,x) ) +#else +#define LIBINT_PRAGMA_GCC(x) +#endif + #endif /* header guard */ diff --git a/src/bin/libint/context.cc b/src/bin/libint/context.cc index 84bd249fd..c03d4c3b3 100644 --- a/src/bin/libint/context.cc +++ b/src/bin/libint/context.cc @@ -197,7 +197,7 @@ std::string CppCodeContext::code_prefix() const { if (cparams()->use_C_linking()) { - return "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"; + return "#ifdef __cplusplus\nLIBINT_PRAGMA_CLANG(diagnostic push)\nLIBINT_PRAGMA_CLANG(diagnostic ignored \"-Wunused-variable\")\nLIBINT_PRAGMA_GCC(diagnostic push)\nLIBINT_PRAGMA_GCC(diagnostic ignored \"-Wunused-variable\")\nextern \"C\" {\n#endif\n"; } return ""; } @@ -206,7 +206,7 @@ std::string CppCodeContext::code_postfix() const { if (cparams()->use_C_linking()) { - return "#ifdef __cplusplus\n};\n#endif\n"; + return "#ifdef __cplusplus\n};\nLIBINT_PRAGMA_CLANG(diagnostic pop)\nLIBINT_PRAGMA_GCC(diagnostic pop)\n#endif\n"; } return ""; }