[CMake] Help with cmake_policy

Brad King brad.king at kitware.com
Wed Feb 25 09:09:01 EST 2009


eblotml at free.fr wrote:
> I'm having trouble to understand how to use the cmake_policy the easy way:
> 
> My CMakeLists.txt files are written for CMake 2.6.2
> I've upgraded to CMake 2.6.3, and I got some warnings about CMP0011.
> 
> How can I tell CMake 2.6.3 to work the way CMake 2.6.2 used to work, without receiving warnings AND CMake 2.6.2 to accept the same CMakeLists.txt ?
> 
> I've tried to use CMAKE_POLICY (SET CMP0011 OLD), but this breaks CMake 2.6.2 as it seems CMake does not ignore policies that are not known for a given version of CMake.

cmake_minimum_required(VERSION 2.6.2)
if(POLICY CMP0011)
   cmake_policy(SET CMP0011 OLD) # or even better, NEW
endif(POLICY CMP0011)

However, I suggest trying to set it to NEW if the policy exists.  If the project
builds then you're all set and can bump the min version to 2.6.3 at any time
in the future without breaking anything.  If it doesn't build, then it is better
to fix it now and still set the policy to NEW.

The whole point of policies is that we can be more aggressive about fixing bad
behavior in CMake without breaking existing project releases.  The fact that
you're editing your project to set a policy means you're a developer and can
fix the project to account for the change in behavior.  Meanwhile any existing
releases you've done will work unchanged (just perhaps with a few warnings).

> As a more general question, is there a way to tell CMake, when upgrading from a patch version to another to NOT complain about any change in policy, without having to specify commands such as -Wno-dev ?

No.  This is intentional.  Otherwise the devs may not know something has changed.

-Brad


More information about the CMake mailing list