risk of using cmake_policy(VERSION ...) instead of setting policies individually

Hi,

The cmake documentation recommends the use of cmake_policy(VERSION […]) instead of setting policies individually with cmake_policy(SET CMP… NEW|OLD):

“While setting policies individually is supported, we encourage projects to set policies based on CMake versions”

Furthermore the documentation states:

“If no setting is available the OLD behavior is assumed and a warning is produced requesting that the policy be set.”

This implies that if no warnings are produced, no OLD policies are being used, and one would expect that it is safe to use cmake_policy(VERSION …) without the risk of inadvertently changing behaviour.

However, I then came across the following in the documentation of CMP0091:

“Unlike many policies, CMake version 3.20.2 does not warn when this policy is not set and simply uses OLD behavior.”

This clearly invalidates the documentation quoted above “If no setting is available the OLD behavior is assumed and a warning is produced requesting that the policy be set”. Apparently it should say instead: “… and for many policies but not all a warning is produced …”. This leaves me wondering exactly which are the policies that don’t produce a warning when the OLD behaviour is used, and for which the use of cmake_policy(VERSION …) would result in a silent change.

Could you please confirm that my assessment is correct, and that the documentation is wrong? And is there a way to find out which policies are being used with the OLD behaviour without producing a warning, like CMP0092?

Best regards,

Maarten

Using debugging facilities can make some of those warn. Some (like CMP0092) don’t warn because detection is just too hard to know how the value of the CMAKE_<LANG>_FLAGS variables are being used.