[CMake] How to use CMAKE_POLICY?

David Cole david.cole at kitware.com
Mon Dec 17 09:30:12 EST 2012


If you need to set a policy to OLD, then we have failed...

Why do you need to set a policy to OLD?

How can we make it work so that you don't need to do that?




On Mon, Dec 17, 2012 at 3:58 AM, Marcel Loose <loose at astron.nl> wrote:

>  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>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/acf6f661/attachment-0001.htm>


More information about the CMake mailing list