CMP0220ΒΆ
Added in version 4.5.
Languages enabled in subdirectories propagate to the top-level directory.
In CMake 4.4 and below, enabling a language with the project()
command or enable_language() command had some restrictions:
It had to be called in file scope, not in a
function()call nor inside ablock().It had be called in the highest directory common to all targets using the named language directly for compiling sources or indirectly through link dependencies.
While these restrictions could be met by enabling all needed languages in the top-level directory of a project, this was not always easy.
CMake 4.5 and above prefer to relax these restrictions so that languages
enabled by calls to the project() and enable_language()
commands in subdirectories are available to targets created in ancestor
and sibling directories created afterward. This policy provides
compatibility with projects that have not been updated for the new behavior.
One may think of an add_subdirectory() call as an effective call
site to enable_language() for languages enabled inside the
subdirectory's tree. Similarly, for languages enabled in function()
and block() scopes, the function or endblock() calls are
effectively call sites to enable_language().
This policy is evaluated independently at each "effective call site",
proceeding up the stack of variable scopes to determine if the language
should be enabled at that level. This propagation stops at the first
ancestor scope whose CMP0220 is not NEW. For example:
cmake_policy(SET CMP0220 NEW)
block()
cmake_policy(SET CMP0220 OLD)
block()
cmake_policy(SET CMP0220 NEW)
block()
cmake_policy(SET CMP0220 OLD)
enable_language(CXX)
# CXX is enabled in this scope
endblock()
# CXX is enabled in this scope
endblock()
# CXX is not enabled in this scope
endblock()
# CXX is not enabled in this scope
This policy was introduced in CMake version 4.5.
It may be set by cmake_policy() or cmake_minimum_required().
If it is not set, CMake does not warn by default, and uses OLD behavior.
See documentation of the
CMAKE_POLICY_WARNING_CMP0220
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.