I have set the following in my CMakeLists.txt:
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
However, CMake still allows g++ 6, even though it doesn't fully support c++17 (it has a c++1z standard, but not a c++17 standard). Is there a way to tell CMake to only allow compilers that fully support the standard and not just pieces of it?
FWIW, I also tried setting cxx_relaxed_constexpr, which I think should have been the relevant language feature, but that still allowed g++ 6. But it clearly can't compile code like
if constexpr (ENABLE_LOGGING) { do_loggy_stuff() };
So I'm not sure if there is a newer constexpr feature I should be looking for (there doesn't seem to be one in the latest cmake) or if CMake is just confused about what GCC 6 can do.
Edit: It seems I was slightly confused. Even though GCC 6 doesn't document c++17 as a value of -std, it does accept it as a synonym for c++-1z. So I guess what I'm looking for is a way to only look for "non-experimental" c++17 support.
Also, looking at the GCC documentation, it seems the feature I want is "constexpr if". Unfortunately, CMake doesn't recognize cxx_constexpr_if
or cxx_if_constexpr
as valid compile features.