Skip to content

Commit

Permalink
attempt to reduce the compilation noise in the generated code by wrap…
Browse files Browse the repository at this point in the history
…ping into pragmas
  • Loading branch information
evaleev committed Apr 2, 2020
1 parent 1e8b40d commit 43631f7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions include/libint2/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions src/bin/libint/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
Expand All @@ -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 "";
}
Expand Down

0 comments on commit 43631f7

Please sign in to comment.