13

I'm trying to compile the Paraview graphical visualization software for my ARM-based laptop; however, I am getting a few configuration warnings that seem to relate to cmake 'policies'. The warning text and the cmake man page suggest that I should be able to run the command cmake_policy() to set a particular policy; however, I can't figure out how or where to run it.

How can I set a particular cmake policy?

3 Answers 3

12

The CMake command cmake_policy() is documented in the CMake documentation.

It is usually added to the CMakeLists.txt file of the project to change the behaviour of CMake itself, usually to be able to handle older CMakeLists.txt features with newer versions of CMake.

You may use it to set an individual policy using

cmake_policy(SET CMP<NNNN> OLD)

where <NNNN> is a CMake policy number and where OLD indicates that you want the "old behaviour" of this policy (the word OLD could also be NEW).

Or, you may use the command to set policies for compatibility with a particular version of CMake using

cmake_policy(VERSION x.xx)

where x.xx must be at least 2.4.

In either case, the CMakeLists.txt file of the project is modified, and cmake will have to be re-run.

See also the documentation for cmake_minimum_required().

4
  • Thanks for your answer. So, is NEW the default for policies, unless overridden? Also, it seems like any policy changes tend to be more for a specific project, rather than 'global' settings, is that correct?
    – Time4Tea
    Apr 16, 2019 at 13:06
  • 1
    @Time4Tea I think that you are correct on both points. NEW exists to allow toggling policies on or off for specific parts of a CMakeLists.txt file.
    – Kusalananda
    Apr 16, 2019 at 13:33
  • 1
    Is there a way to do it from command line? Namely with cmake ...?
    – Royi
    May 3, 2020 at 12:33
  • 13
    @Royi Yes, you can set CMAKE_POLICY_DEFAULT_CMP<NNNN> on the command line, e.g. -DCMAKE_POLICY_DEFAULT_CMP0063=NEW.
    – Jake Cobb
    Jul 20, 2020 at 19:32
6

I use Cmake version 3.22.0 and @kusalananda answer did not fix the issue for me. I added the following line to the top of CMakeLists.txt and the issue was fixed:

set(CMAKE_POLICY_DEFAULT_CMP<NNNN> NEW)

Of course, NNNN should be replaced with the number given in the command line.

4

The CMake policy warnings at the end explicitly inform users that they should not concern themselves with the messages. The messages are there for the project developers.

CMake Warning (dev) at c/tools/CMakeLists.txt:22 (add_executable):
  Policy CMP0069 is not set: INTERPROCEDURAL_OPTIMIZATION is enforced when
  enabled.  Run "cmake --help-policy CMP0069" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  INTERPROCEDURAL_OPTIMIZATION property will be ignored for target
  'msgr-recv'.
This warning is for project developers.  Use -Wno-dev to suppress it.

Use -Wno-dev to suppress it.

However, sometimes as a user of a software, you have a good reason to set a policy when you are installing the project. One reason might be to enable the link-time optimization (also called interprocedural optimization). Without setting a policy, CMake will ignore the -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON.

In such a case, you can use -DCMAKE_POLICY_DEFAULT_CMP<NNNN> to get the behavior you need, without editing CMakeLists.txt. Of course, contacting the developer, suggesting that they deal with the policy in source, is a good practice.

-DCMAKE_POLICY_DEFAULT_CMP0069=NEW -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .