Skip to content
Snippets Groups Projects
Commit 675ce5cc authored by Steffen Müthing's avatar Steffen Müthing
Browse files

[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.
parent e90c9657
No related branches found
No related tags found
No related merge requests found
......@@ -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
)
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment