CMP0128ΒΆ
New in version 3.22.
When this policy is set to NEW
:
<LANG>_EXTENSIONS
is initialized toCMAKE_<LANG>_EXTENSIONS_DEFAULT
.Extensions are correctly disabled/enabled if
<LANG>_STANDARD
is unset.Standard mode-affecting flags aren't added unless necessary to achieve the specified mode.
The OLD
behavior:
Initializes
<LANG>_EXTENSIONS
toON
.Always adds a flag if
<LANG>_STANDARD
is set and<LANG>_STANDARD_REQUIRED
isOFF
.If
<LANG>_STANDARD
is unset:Doesn't disable extensions even if
<LANG>_EXTENSIONS
isOFF
.Fails to enable extensions if
<LANG>_EXTENSIONS
isON
except for theIAR
compiler.
Code may need to be updated for the NEW
behavior in the following cases:
If
<LANG>_EXTENSIONS
matchesCMAKE_<LANG>_EXTENSIONS_DEFAULT
or is unset and the compiler's default satisfies<LANG>_STANDARD
but the compiled code requires the exact standard specified. Such code should set<LANG>_STANDARD_REQUIRED
toON
.For example:
cmake_minimum_required(VERSION |release|) project(example C) add_executable(exe main.c) set_property(TARGET exe PROPERTY C_STANDARD 99)
If the compiler defaults to C11 then the standard specification for C99 is satisfied and CMake will pass no flags.
main.c
will no longer compile if it is incompatible with C11.If a standard mode flag previously overridden by CMake's and not used during compiler detection now takes effect due to CMake no longer adding one as the default detected is appropriate.
Such code should be converted to either:
Use
<LANG>_STANDARD
and<LANG>_EXTENSIONS
instead of manually adding flags.Or ensure the manually-specified flags are used during compiler detection.
If compiler flags affecting the standard mode are used during compiler
detection (for example in a toolchain file
using CMAKE_<LANG>_FLAGS_INIT
) then they will affect the detected
default standard
and
extensions
.
Unlike many policies, CMake version 3.22.0-rc2 does not warn when the policy
is not set and simply uses the OLD
behavior. Use the
cmake_policy()
command to set it to OLD
or NEW
explicitly.
See documentation of the
CMAKE_POLICY_WARNING_CMP0128
variable to control the warning.
Note
The OLD
behavior of a policy is
deprecated by definition
and may be removed in a future version of CMake.