# correct usage of CMP0011

**URL:** https://discourse.cmake.org/t/correct-usage-of-cmp0011/7965
**Category:** Usage
**Created:** [April 24, 2023, 10:21am UTC](https://discourse.cmake.org/t/correct-usage-of-cmp0011/7965 "2023-04-24T10:21:57Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [April 24, 2023, 10:21am UTC](https://discourse.cmake.org/t/correct-usage-of-cmp0011/7965/1 "2023-04-24T10:21:57Z")

</div>

Hi,  
I’m doing something like this:

```cmake
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](https://cmake.org/cmake/help/latest/command/cmake_policy.html#command:cmake_policy) documentation (and [CMP0011](https://cmake.org/cmake/help/latest/policy/CMP0011.html#policy:CMP0011)) left me confused.

Thx  
A.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 24, 2023, 6:48pm UTC](https://discourse.cmake.org/t/correct-usage-of-cmp0011/7965/2 "2023-04-24T18:48:22Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [April 27, 2023, 9:22am UTC](https://discourse.cmake.org/t/correct-usage-of-cmp0011/7965/3 "2023-04-27T09:22:13Z")

</div>

Hi,

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](https://discourse.cmake.org/t/using-read-p-from-in-script-launched-by-execute-process/7941)).

Thanks

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 27, 2023, 12:07pm UTC](https://discourse.cmake.org/t/correct-usage-of-cmp0011/7965/4 "2023-04-27T12:07:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![andrew-hardin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/andrew-hardin/32/3739_2.png) [@andrew-hardin](https://discourse.cmake.org/u/andrew-hardin)
#### Post date: [August 18, 2023, 4:05pm UTC](https://discourse.cmake.org/t/correct-usage-of-cmp0011/7965/5 "2023-08-18T16:05:31Z")

</div>

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:

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

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 18, 2023, 5:19pm UTC](https://discourse.cmake.org/t/correct-usage-of-cmp0011/7965/6 "2023-08-18T17:19:45Z")

</div>

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