[CMake] C++ standard version fallbacks.

Roger Leigh rleigh at codelibre.net
Sun Jun 4 07:33:57 EDT 2017


Hi folks,

I'm currently using this logic to use C++14 with a fallback to C++11 
when C++14 is unavailable:

   if(NOT CMAKE_CXX_STANDARD)
     set(CMAKE_CXX_STANDARD 14)
   endif()
   if(NOT CMAKE_CXX_STANDARD_REQUIRED)
     set(CMAKE_CXX_STANDARD_REQUIRED 11)
   endif()

which seems to work OK.

However, for some new stuff, I'd like to use C++17 when available, but 
fall back to C++14, C++11 or C++98.  Is it possible to do this?

- I'd like it to work on older CMake versions where "17" isn't a valid 
version for the above; is there any way to introspect the supported 
standards?
- And I'd like it to fall back intelligently, i.e. if 17 isn't available 
I want it to select the newest standard possible, rather than falling 
back all the way to 98

Any suggestions?


Thanks,
Roger


More information about the CMake mailing list