Help: Behavior of calling cmake_minimum_required() inside a function not fully documented
The documentation for the cmake_minimum_required()
command contains this note:
Calling
cmake_minimum_required()
inside afunction()
limits some effects to the function scope when invoked. Such calls should not be made with the intention of having global effects.
I've been unable to find any further details in the docs about what those limitations are. As far as I can tell, calling cmake_minimum_required()
inside a function should be well-defined. While functions create their own scope, that scope does not affect policies. Therefore, one would expect such a call to propagate the policy settings up to the caller's policy scope. This seems consistent with this comment from the cmake_policy()
command's docs:
Commands created by the
function()
andmacro()
commands record policy settings when they are created and use the pre-record policies when they are invoked. If the function or macro implementation sets policies, the changes automatically propagate up through callers until they reach the closest nested policy stack entry.
We should update the docs in cmake_minimum_required()
to drop or soften the note quoted above, or add the missing details about what the limitations are if there are indeed any.