[CMake] Rewrite C++ standard detection
This is a complete rewrite of the existing C++ standard version test that tries the various
-std=c++xy flags and tries to figure out which version of the standard to enable.
The existing version has a few problems:
it is not really extensible to newer standards, those will just lead to a deeper and deeper nesting of
More importantly, there is no way to say: I want C++11, but not C++14 (or, in the future, I want C++14, but not C++17). Being able to do so is important for testing and compatibility reason.
There is no easy way for downstream modules to require a newer version of the standard than the core modules.
The new version of the test separates the logic from the data (versions, flag names, compiler test sources) and just iterates over lists of that data, in descending order to make sure the newest available standard gets picked. The numerical value of that standard is stored in the variable
CXX_MAX_SUPPORTED_STANDARD and the test stops. If the test fails to find a working combination, it issues a warning to the user and only records support for C++03.
The test can be influenced by two CMake variables:
DISABLE_CXX_VERSION_CHECKalready existed in the old version of the test. It completely disables all testing and requires the user to manually set
CXX_MAX_SUPPORTED_STANDARDto the correct value. Moreover, any required compiler command line switches have to be manually added to
CXX_MAX_STANDARDdefines the maximum version of the standard that the build system will try to enable. With this new switch, it becomes possible to limit the compiler to an older version of the standard than what it could theoretically support. For now, this defaults to C++14.
Requirements check with a new CMake function
In order to allow module authors to easily state their minimum version requirements, there is a new CMake function
dune_require_cxx_standard() that any Dune module can call to require support for at least a given C++
dune_require_cxx_standard(MODULE "dune-functions" VERSION 14)
If the compiler doesn't meet the requirements, the function will report the required and the actually available standard versions and abort with a fatal error.
Moreover, it knows about CXX_MAX_STANDARD and will tell the user if the value of that variable is below the requirements. This avoids desperate users that have a shiny beta of GCC 6 with C++17 support wondering why their own module using shiny C++17 concepts stubbornly fails to build...
I would very much like to backport this to 2.4.1 as it would get rid of the dirty hackery currently required in
PDELab. For the backported version, I'm not sure about the best value for
CXX_MAX_STANDARD: 11 or 14?