So, back in GCC 10.2 (which used C++14 as the default), I could use this to tell CMake I wanted -std=gnu++17:
target_compile_features(mytarget PRIVATE cxx_std_17)
set_target_properties(mytarget PROPERTIES
CXX_STANDARD_REQUIRED ON
)
...which I actually didn't want, so I used CXX_EXTENSIONS OFF to force -std=c++17:
target_compile_features(mytarget PRIVATE cxx_std_17)
set_target_properties(mytarget PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF # -std=c++17 instead of gnu++17
)
Enter GCC 11.1. The default now is the 2017 version of the ISO C++ standard, so that the first snippet above doesn't generate any -std flag for GCC, which is compatible with GCC 11's man page:
c++17: The 2017 ISO C++ standard plus amendments.
gnu++17: GNU dialect of-std=c++17. This is the default for C++ code.
The problem is that the second CMake snippet above also doesn't generate any -std flag. How do I do it now, is this a bug in CMake? How to I tell it I want an explicit -std=c++17 flag?
Remark 1: I know I can just stick -std=c++17 in target_compile_options, but I don't want to do that, do I?
Remark 2: Sanity check: if I change cxx_std_17 to cxx_std_20, then CXX_EXTENSIONS OFF correctly switches from -std=gnu++2a to -std=c++2a.