# What is the difference between cmake\_policy specifying only min or specifying min and max at the same time?

**URL:** https://discourse.cmake.org/t/what-is-the-difference-between-cmake-policy-specifying-only-min-or-specifying-min-and-max-at-the-same-time/10864
**Category:** Usage
**Created:** [May 17, 2024, 6:46am UTC](https://discourse.cmake.org/t/what-is-the-difference-between-cmake-policy-specifying-only-min-or-specifying-min-and-max-at-the-same-time/10864 "2024-05-17T06:46:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![hq354974212](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hq354974212/32/4597_2.png) [@hq354974212](https://discourse.cmake.org/u/hq354974212)
#### Post date: [May 17, 2024, 6:46am UTC](https://discourse.cmake.org/t/what-is-the-difference-between-cmake-policy-specifying-only-min-or-specifying-min-and-max-at-the-same-time/10864/1 "2024-05-17T06:46:37Z")

</div>

I tried the following two ways of writing:

cmake\_policy(VERSION **3.24** )  
cmake\_policy(VERSION 3.20… **3.24** )

the other test code is:

```auto
cmake_policy(GET CMP0139 v)
message("CMP0143=${v} ")  

#CMake 3.22 （CMP0127 ~ CMP0128） 
cmake_policy(GET CMP0127 v)
message("CMP0127=${v} ")  

#CMake 3.21 （CMP0121 ~ CMP0126） 
cmake_policy(GET CMP0126 v)
message("CMP0126=${v} ")  

#CMake 3.20 （CMP0115 ~ CMP0120） 
cmake_policy(GET CMP0120 v)
message("CMP0120=${v} ")  

#CMake 2.6 （CMP0000 ~ CMP0011）
cmake_policy(GET CMP0000 v)
message("CMP0000=${v} ")  

```

The results of the two tests are the same  
cmake\_policy(VERSION **3.24** )  
 ![QQ截图20240517145320](https://discourse.cmake.org/uploads/default/original/2X/f/f328a9b085e2e08154d79b463a12cc159a654f20.png)

cmake\_policy(VERSION 3.20… **3.24** )  
the same as above

So I am very confused whether the max here is necessary. If so, then I would like to ask how to test the difference. I am eager for the advice of the experts!

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [May 17, 2024, 11:23am UTC](https://discourse.cmake.org/t/what-is-the-difference-between-cmake-policy-specifying-only-min-or-specifying-min-and-max-at-the-same-time/10864/2 "2024-05-17T11:23:03Z")

</div>

To see the difference, try running your tests with CMake 3.20 (and with 3.19).

How `cmake_policy(VERION min...max)` works:

- CMake of version less than `min` will error out and not process the project.
- CMake of version `min` or later will process the code. All policies which it knows and which were introduced in `max` or earlier will be set to `NEW`, later ones will be unset.
- If `max` is not specified, it behaves the same as if it was equal to `min`.

In other words: set the minimum version based on what you require to process your project. If your project requires at least CMake 3.15, that’s your `min`.

As CMake introduces new versions with new policies, these policies may affect behaviour which you’re using in your project. When that happens, processing your project with this newer CMake produces a developer warning “Policy X is unset, treating as `OLD` for now. Please update your project.”

What you as project author should do in this case is indeed update the project. However, if you don’t want to force your users to upgrade their CMake, you can make the update such that it works with both the old version and the new one. Doing that is the proper time to use the `min...max` version range. What such a version range says:

> I, project author, rely on CMake `min` being used for processing. I have adapted my project to processing with CMake `max` and guarantee that it behaves correctly. If you use a version newer than `max`, there may be behaviour I wasn’t expecting and you may get “using OLD policy behaviour” warnings.

---

<div class="post-metadata">

### Author: ![hq354974212](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hq354974212/32/4597_2.png) [@hq354974212](https://discourse.cmake.org/u/hq354974212)
#### Post date: [May 20, 2024, 5:18am UTC](https://discourse.cmake.org/t/what-is-the-difference-between-cmake-policy-specifying-only-min-or-specifying-min-and-max-at-the-same-time/10864/3 "2024-05-20T05:18:52Z")

</div>

I I Thank you very much for your help and advice!  
I changed my cmake to **CMake 3.20**. The following are the two running results. There seems to be no difference between setting or not setting max here? Who can tell me how the max parameter can work?

```auto
#设置策略最小版本
cmake_policy( VERSION 3.20)
#cmake_policy( VERSION 3.19...3.20)

cmake_policy(GET CMP0139 v)
message("CMP0139=${v} ")  

#CMake 3.22 （CMP0127 ~ CMP0128） 
cmake_policy(GET CMP0127 v)
message("CMP0127=${v} ")  

#CMake 3.21 （CMP0121 ~ CMP0126） 
cmake_policy(GET CMP0126 v)
message("CMP0126=${v} ")  

#CMake 3.20 （CMP0115 ~ CMP0120） 
cmake_policy(GET CMP0120 v)
message("CMP0120=${v} ")  

#CMake 2.6 （CMP0000 ~ CMP0011）
cmake_policy(GET CMP0000 v)
message("CMP0000=${v} ")  

```

when I use  
`cmake_policy( VERSION 3.20)`

the result is

 ![QQ截图20240520131541](https://discourse.cmake.org/uploads/default/original/2X/2/26fa161089d4ab38bc54381e7db74d0430c2bd3b.png)

when I use  
`#cmake_policy( VERSION 3.19...3.20)`

the result is same too ！
