• Steffen Müthing's avatar
    Merge branch 'feature/cmake-rewrite-c++-standard-detection' into 'master' · 31252385
    Steffen Müthing authored
    [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 `if` statements.
    
    - 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.
    
    ## Test logic
    
    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_CHECK` already existed in the old version of the
      test. It completely disables all testing and requires the user to
      manually set `CXX_MAX_SUPPORTED_STANDARD` to the correct value.
      Moreover, any required compiler command line switches have to be
      manually added to `CMAKE_CXX_FLAGS`.
    
    - `CXX_MAX_STANDARD` defines 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++ standard:
    
    ```
    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...
    
    This fixes #16, and a backport to 2.4 will also be a fix for #15.
    
    See merge request !46
    31252385
Name
Last commit
Last update
am Loading commit data...
bin Loading commit data...
cmake Loading commit data...
doc Loading commit data...
dune Loading commit data...
lib Loading commit data...
m4 Loading commit data...
share Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
CMakeLists.txt Loading commit data...
CONTRIBUTING.md Loading commit data...
COPYING Loading commit data...
INSTALL Loading commit data...
LICENSE.md Loading commit data...
Makefile.am Loading commit data...
README.SVN Loading commit data...
README.md Loading commit data...
TODO Loading commit data...
config.h.cmake Loading commit data...
configure.ac Loading commit data...
dune-common.pc.in Loading commit data...
dune.module Loading commit data...
stamp-vc Loading commit data...