triadamv.blogg.se

Cmake set compiler
Cmake set compiler







cmake set compiler
  1. #Cmake set compiler generator
  2. #Cmake set compiler full
  3. #Cmake set compiler code

The COMPILE_FEATURES generator expression tests whether the named feature is supported by the compiler.

cmake set compiler

To see the subset of features supported by your current compiler, place the following line anywhere after your project() command: message("Supported features = $/no_variadics)

#Cmake set compiler full

The full set of features CMake knows about is included in the CMake documentation and can also be obtained from the CMAKE_CXX_KNOWN_FEATURES global property (so you need to use get_property() to access it). The supported feature entries depend on the compiler being used. commands, controlling whether the feature requirement should apply to just this target ( PRIVATE), this target and anything that links to it ( PUBLIC) or just things that link to it ( INTERFACE). The PRIVATE, PUBLIC and INTERFACE keywords work just like they do for the various other target_. To specify that a particular target requires a certain feature, CMake provides the target_compile_features() command: target_compile_features( ) Initial support for compiler features was made available in CMake 3.1 for just a small number of compilers, expanded to a broader set of compilers in version 3.2 and from 3.6 all commonly used compilers are supported.

#Cmake set compiler code

As an alternative, CMake also offers a finer grained approach, allowing you to specify the compiler features that your code requires and letting CMake work out the C++ standard automatically. ) Setting the C++ standard based on featuresįor most situations, the above method is the simplest and most convenient way to handle the compiler and linker flags for a particular C++ standard. For example: set_target_properties(myTarget Where your CMakeLists.txt might be getting included from some higher level project or if you don’t want to set the global behaviour, then setting the CXX_STANDARD, CXX_STANDARD_REQUIRED and CXX_EXTENSIONS properties on each target will achieve the same thing on a target-by-target basis. In most cases, you probably want to use a consistent C++ standard for all targets defined in a project, so setting the global CMAKE_CXX_STANDARD, CMAKE_CXX_STANDARD_REQUIRED and CMAKE_CXX_EXTENSIONS variables would be the most convenient. Credit to ajneu in the comments for pointing out this particular variable and its effects.Īnd that’s all it takes to get CMake to set the compiler and linker flags appropriately for a specific C++ standard. The default behavior is for C++ extensions to be enabled, but for broadest compatibility across compilers, projects should prefer to explicitly disable them.

cmake set compiler

This results in modifying the flag used to set the language standard (e.g. Projects will also probably want to set the following too: set(CMAKE_CXX_EXTENSIONS OFF)

cmake set compiler

Note that CMake may still end up selecting a more recent language standard than the one specified (see the discussion of compiler features in the next section). Since you will likely be wanting to disable the fallback behaviour in most situations, you will probably find it easier to just set the CMAKE_CXX_STANDARD_REQUIRED variable to YES instead, since it acts as the default for the CXX_STANDARD_REQUIRED target property. To prevent this fallback behaviour, the CXX_STANDARD_REQUIRED target property should be set to YES. It does not generate an error by default. There is a minor wrinkle in that if the compiler doesn’t support the specified standard, by default CMake falls back to the latest standard the compiler does support instead. It results in adding the relevant compiler and linker flags to the target to make it build with the specified C++ standard. The CXX_STANDARD target property mostly behaves as you would expect. This variable is used as the default for the CXX_STANDARD target property, so all targets defined after the variable is set will pick up the requirement. Valid values for CMAKE_CXX_STANDARD are 98, 11 and 14, with 17 also being added in CMake 3.8 and 20 added in CMake 3.12. The simplest way to use a particular C++ standard in your project is to add the following two variable definitions before you define any targets: set(CMAKE_CXX_STANDARD 11) Happily, with features added in CMake 3.1, it is trivial to handle this in a generic way. If your project targets multiple platforms and compilers, this can be a headache to set up. With the constant evolution of C++, build systems have had to deal with the complication of selecting the relevant compiler and linker flags.









Cmake set compiler