# Feature idea - warn about defined policy breaking \`cmake\_minimum\_required\`

**URL:** https://discourse.cmake.org/t/feature-idea-warn-about-defined-policy-breaking-cmake-minimum-required/14992
**Category:** Development
**Created:** [August 13, 2025, 6:24am UTC](https://discourse.cmake.org/t/feature-idea-warn-about-defined-policy-breaking-cmake-minimum-required/14992 "2025-08-13T06:24:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Andrej730](https://discourse.cmake.org/user_avatar/discourse.cmake.org/andrej730/32/5752_2.png) [@Andrej730](https://discourse.cmake.org/u/Andrej730)
#### Post date: [August 13, 2025, 6:24am UTC](https://discourse.cmake.org/t/feature-idea-warn-about-defined-policy-breaking-cmake-minimum-required/14992/1 "2025-08-13T06:24:59Z")

</div>

E.g. if project has `cmake_minimum_required(VERSION 3.10)`, but introduced `cmake_policy(SET CMP0177 OLD)`.

Since `CMP0177` was added in 3.31, anyone using it `cmake_policy` with it, will get `Policy "CMP0177" is not known to this version of CMake.` error. So `cmake_minimum_required` effectively becomes `3.31`.

Would be great if cmake can warn about this kind of mistakes.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [August 13, 2025, 1:23pm UTC](https://discourse.cmake.org/t/feature-idea-warn-about-defined-policy-breaking-cmake-minimum-required/14992/2 "2025-08-13T13:23:38Z")

</div>

This is a common pattern:

```cmake
cmake_minimum_required(VERSION 3.10)
if(POLICY CMP0177)
  cmake_policy(SET CMP0177 NEW)
endif()
project(Example)

```

Since the language is imperative there is no way for `cmake_policy(SET)` to warn in one case and not the other. If a project mistakenly leaves out the `if` guard, it’s a bug in that project.

---

<div class="post-metadata">

### Author: ![Andrej730](https://discourse.cmake.org/user_avatar/discourse.cmake.org/andrej730/32/5752_2.png) [@Andrej730](https://discourse.cmake.org/u/Andrej730)
#### Post date: [August 13, 2025, 5:42pm UTC](https://discourse.cmake.org/t/feature-idea-warn-about-defined-policy-breaking-cmake-minimum-required/14992/3 "2025-08-13T17:42:12Z")

</div>

~~Have been noticing this pattern, but it seems it’s better to avoid it in general to keep behaviour consistent across supported cmake versions and keep code easier to reason about.~~ Nevermind, for some reason I’ve assumed `cmake_policy(SET CMP0177 OLD)` doesn’t trigger errors on older cmakes, thought it’s only on `NEW`.

Sorry, if it’s a dumb question and I’m just missing something, but doesn’t cmake know when it’s executing `cmake_policy(SET CMP0177 NEW)` that minimum required version is set to `3.10` and it would be able to compare version associated with `CMP0177` with minimum required version and show a warning if `cmake_policy` contradicts it?  
Though I don’t know if cmake is currently aware of versions associated with each policy or it’s just a note in the documentation.

Agree, that it is a bug in the project in the first place, it just might go under the radar until someone with older cmake version stumbles upon it.

---

<div class="post-metadata">

### Author: ![Andrej730](https://discourse.cmake.org/user_avatar/discourse.cmake.org/andrej730/32/5752_2.png) [@Andrej730](https://discourse.cmake.org/u/Andrej730)
#### Post date: [August 14, 2025, 7:24am UTC](https://discourse.cmake.org/t/feature-idea-warn-about-defined-policy-breaking-cmake-minimum-required/14992/4 "2025-08-14T07:24:23Z")

</div>

Thinking about it more, I think you’re right, this is probably not possible, since then `cmake_policy` would need to somehow figure that it’s not inside `if(POLICY)` branch to issue a warning. And this sounds like too much of complexity to fix this kind of bugs.

---

<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 16, 2025, 2:02am UTC](https://discourse.cmake.org/t/feature-idea-warn-about-defined-policy-breaking-cmake-minimum-required/14992/5 "2025-08-16T02:02:53Z")

</div>

Perhaps (I don’t know of the feasibility), we have `cmake_minimulm_required(VERSION … ACCEPT_POLICIES CMP0XYZ CMP0IJK)`. _Then_ we can warn when the upper-range of the version given makes a policy acceptance redundant.
