


Set_property(TARGET target PROPERTY CXX_STANDARD_REQUIRED On) set_property(TARGET target PROPERTY CXX_STANDARD 17) Setting these properties to targets can be done with the following snippets.
#CMAKE SET LIST PORTABLE#
For more portable code, set this value to Off to ensure your code will compile in all compilers. Briefly speaking, it tells CMake whether compiler extensions (such as inline assembly) are allowed or not.

CXX_STANDARD dictates which standard version the target will be compiled with.Each target has properties set by CMake, and some of those properties relate to the C++ standard for the compilation: For example, creating executables in CMake will in turn generate a named target for it in CMake. Let’s Talk About The C++ Standard CMake Variablesįirstly, let’s discuss how CMake sets the standard throughout your project.Įssentially, every executable or library you declared in your CMakeSettings.txtis a target. In fact, you only need to set three main variables: CMAKE_CXX_STANDARD, CMAKE_CXX_STANDARD_REQUIRED, and CMAKE_CXX_EXTENSIONS. With CMake, this isn’t as difficult as many think. Setting the C++ standard is just about turning some of these cogs. Figure 1: A nice illustration of the infinite cogs that make up CMake’s usefulness. In this post, we will set the C++ standard with CMake. For this reason, you need to set your compiler’s C++ standards to whatever new version you need. If you’re serious about your coding standards, you’re probably using the latest and greatest C++ features.
