correct usage of CMP0011

I’m doing something like this:

INSTALL(SCRIPT "Path/Script.cmake")

In Script.cmake I’m doing a if (var IN_LIST list) which, according to cmake warnings, requires CMP0057 being set to NEW. Yet it seems that Script.cmake does not inherit the calling CMakeLists policies.
Setting CMP0057 inside Script.cmake rises a new warning implying policy CMP0011. I can silence the warning by setting CMP0011 to NEW inside Script.cmake but is it the right place to do it?
cmake_policy documentation (and CMP0011) left me confused.


I think you might just want to use cmake_policy(VERSION 3.12) or whatever works best for you to set all policies to some modern settings.


In my use case, the main CMakeLists does cmake_policy(VERSION x.y) but it seems that a delegated cmake script does not inherite it (see use-case in using read -p from in script launched by execute_process).


No, a policy only applies to the cmake code that will be seen in the current execution. Anything that has another cmake -P involved will need its own policy settings.

The given solution didn’t resolve the problem of CMake policy warnings being raised during an INSTALL(SCRIPT ...) command. However, setting the policy as CODE during the INSTALL command seems to work:

  CODE "cmake_policy(SET CMP0011 NEW)"
  SCRIPT "script.cmake"

install(CODE) is included verbatim in the generated code; install(SCRIPT) is include()'d, so CMP0011 applies in that case. Since (presumably) the script sets policy settings, the caller’s lack of CMP0011 means that your policies affect the caller too. With your call, you’re setting CMP0011 so that it doesn’t do the old behavior (and doesn’t warn either).