Skip to content
  • Steffen Müthing's avatar
    [CMake] Rewrite C++ standard detection test · daa2e9f4
    Steffen Müthing authored
    This patch 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.
    
    While my cleaned-up version of the old implementation generally works,
    it has a few problems:
    
    - it is not really extensible to newer standards (that will lead to the
      same kind of mess as before).
    
    - 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.
    
    So this patch mostly starts from scratch: There is a list of supported
    C++ standards (currently 17,14,11) and corresponding lists of compiler
    tests and compiler flags to switch the compiler to the respective
    standards (there might be different values for the switch, e.g. some
    compilers accept -std=c++1y, but not -std=c++14, and recent versions of
    GCC reject -std=c++1x).
    
    The code then just iterates through these versions and flags until it
    finds one that works. If that flag / version combo also passes the
    compile test, the maximum supported standard version is recorded 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.
    daa2e9f4