[CMake] How to use CMAKE_POLICY?

Marcel Loose loose at astron.nl
Mon Dec 17 03:58:47 EST 2012


Hi David,

See my remarks inline.

On 15/12/12 16:47, David Cole wrote:
> On Sat, Dec 15, 2012 at 10:33 AM, Marcel Loose <marcel.loose at zonnet.nl 
> <mailto:marcel.loose at zonnet.nl>> wrote:
>
>     Thanks, that seems to work.
>
>     Is the idiom
>
>         if(POLICY CMP<NNNN>)
>           cmake_policy(PUSH)
>           cmake_policy(SET CMP<NNNN> OLD)
>           cmake_policy(POP)
>         endif()
>
>     one that you also need to use with newer CMakes? Or does it then
>     suffice to do
>
>         cmake_policy(SET CMP<NNNN> OLD)
>
>
> I assume you really mean:
>
> if(POLICY CMP<NNNN>)
>   cmake_policy(PUSH)
>   cmake_policy(SET CMP<NNNN> OLD)
> endif()
>
> ...
> other code where the policy is set to OLD
> ...
>
> if(POLICY CMP<NNNN>)
>   cmake_policy(POP)
> endif()
>
Yes, you're right. I was oversimplifying.
>
> The policies are tightly tied to the minimum required version of 
> CMake. So if you use cmake_minimum_required with a certain version 
> number, you can write code without if(POLICY assuming that all the 
> policies you need to set are known as of that minimum version. If they 
> are not (and they must not be in this particular case), then you'll 
> need the if(POLICY construct.
>
So, that basically means that you need to use if(POLICY...) for all 
policies that are not part of the minimum required version? Is there a 
way to find out which policies exist for which version of CMake?

I was hoping for a more forward compatible solution. In other words, I 
was hoping that I could always use CMAKE_POLICY(SET...) unconditionally. 
It's a bit of a shame that I have to clutter my CMakeLists.txt and 
*.cmake files with these extra conditionals; and have to remove them (or 
should I say: clean up) whenever I bump the minimum required version.

What's the reason that cmake doesn't silently ignore a 
CMAKE_POLICY(SET...) for a policy it doesn't know about?

> The other option is to bump up your minimum required version.
Sure, but that defeats the whole purpose of setting a minimum required 
version. I need to be compatible with version 2.6.2.

Best regards,
Marcel Loose.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20121217/02588945/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: loose.vcf
Type: text/x-vcard
Size: 292 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20121217/02588945/attachment.vcf>


More information about the CMake mailing list