[CMake] How to use CMAKE_POLICY?

David Cole david.cole at kitware.com
Sat Dec 15 10:47:34 EST 2012


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()


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.

The other option is to bump up your minimum required version.


HTH,
David




>
>  Best regards,
> Marcel Loose.
>
>
> Op 13-12-12 14:00, David Cole schreef:
>
> You could use if(POLICY (if 2.6.2 supports that... I think it does, but it
> was very long ago......) to avoid the call on older CMakes.
>
>
> On Thu, Dec 13, 2012 at 6:31 AM, Marcel Loose <loose at astron.nl> wrote:
>
>> Hi all,
>>
>> I'm trying to figure out how to use the CMAKE_POLICY() command. I want to
>> get rid of the warning on CMP0017. I've strategically placed
>> "cmake_policy(PUSH)", "cmake_policy(SET CMP0017 OLD)", and
>> "cmake_policy(POP)" which solves the problem when configuring with CMake
>> 2.8.9.
>>
>> However, our project also needs to be compatible with CMake 2.6.2. The
>> problem is that this older CMake now bails out with an error message:
>>
>> CMake Error at CMake/FindLAPACK.cmake:44 (cmake_policy):
>>   Policy "CMP0017" is not known to this version of CMake.
>>
>> This sounds like a catch-22. I've fixed the warning for the new CMake,
>> but get an error in return for the old CMake. What am I doing wrong??
>>
>> Best regards,
>> Marcel Loose.
>>
>>
>> --
>>
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20121215/03050e9a/attachment-0001.htm>


More information about the CMake mailing list