From 675ce5cc59f6b28cb54b3789dca339bc703f120c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=BCthing?= <muething@dune-project.org> Date: Fri, 18 Aug 2017 19:56:30 +0200 Subject: [PATCH] [cmake] Add test for inline variables Inline variables are a C++17 feature that gives variables the same type of linkage as inline functions, which avoids object file bloat and linker problems. For us, this is mostly interesting in the context of constexpr variables like the partition sets provided in dune-grid: Right now, a separate copy of those objects is emitted by each translation unit, and those copies do not get merged by the linker. This has created problems in the past and forced us to place the variables in an anonymous namespace, which creates unique symbol names for each translation unit. With inline variables, the problem will eventually go away. --- cmake/modules/CheckCXXFeatures.cmake | 12 ++++++++++++ config.h.cmake | 3 +++ 2 files changed, 15 insertions(+) diff --git a/cmake/modules/CheckCXXFeatures.cmake b/cmake/modules/CheckCXXFeatures.cmake index 5c4bd828c..d8f922837 100644 --- a/cmake/modules/CheckCXXFeatures.cmake +++ b/cmake/modules/CheckCXXFeatures.cmake @@ -481,3 +481,15 @@ check_cxx_source_compiles(" } " DUNE_SUPPORTS_CXX_THROW_IN_CONSTEXPR ) + + +# Check whether the compiler supports inline variables +check_cxx_source_compiles(" + inline int foo = 42; + + int main() + { + return not (foo == 42); + } +" DUNE_HAVE_CXX_INLINE_VARIABLES + ) diff --git a/config.h.cmake b/config.h.cmake index fa6b9d211..a15ab8a8d 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -35,6 +35,9 @@ /* does the compiler support conditionally throwing exceptions in constexpr context? */ #cmakedefine DUNE_SUPPORTS_CXX_THROW_IN_CONSTEXPR 1 +/* does the compiler support inline variables? */ +#cmakedefine DUNE_HAVE_CXX_INLINE_VARIABLES 1 + /* Define if you have a BLAS library. */ #cmakedefine HAVE_BLAS 1 -- GitLab