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.
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:
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).