Skip to content

Tutorial: Replace usage of CMAKE_CXX_STANDARD* variables by compile features

One of the main things we do when teaching modern cmake is to forbid changing the values of CMAKE_CXX_FLAGS, as those are mainly intended to be changed through toolchain files or the cache.
I believe that if we want to have less friction in the ecosystem with such issues, we should not introduce variables that also start with CMAKE_CXX_* in the very first (and official) tutorial, even if those variables are a bit less problematic.

This merge request switches from using CMAKE_CXX_STANDARD and CMAKE_CXX_STANDARD_REQUIRED to target_compile_features(Tutorial PUBLIC cxx_std_11).

Pros:

  • People will be less tempted to set/modify any of the CMAKE_CXX_* variables, since they will not be shown that it's something advertised in the official tutorials
  • This does not require to set 2 variables (one-liner instead of 2)

Cons:

  • This uses the PUBLIC keyword without mentioning transitive properties, however it was already used before for target_include_directories.
  • This does not set the standard for the whole project, only the Tutorial target.

Merge request reports