CMAKE_CXX_STANDARD vs target_compile_features?

Solution 1:

The newer alternative is definitely

target_compile_features(Foo PUBLIC cxx_std_20)

And with this you can and should remove the old set(CMAKE_CXX_STANDARD*).

However the new version has an issue if you also want to disable compiler extensions with set(CMAKE_CXX_EXTENSIONS OFF). Its not possible with the new syntax as far as I know and combining both of them does not work either.

And the second part of your question: Yes, cmake will recognize the dependencies and put the compiler in c++-20 mode whenever necessary.