Allow cmake_policy(VERSION) for unknown CMake version
Currently we are working with CMake 3.16, but require at least only CMake 3.11
cmake_minimum_required(VERSION 3.11.0)
cmake_policy(SET CMP0043 NEW)
cmake_policy(SET CMP0020 NEW)
cmake_policy(SET CMP0054 NEW)
if(POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
endif()
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
if(POLICY CMP0076)
cmake_policy(SET CMP0076 NEW)
endif()
During reading the documentation I saw it is currently recommend to prefer cmake_policy(VERSION ...)
over cmake_policy(SET ...)
, so I changed our code to:
cmake_minimum_required(VERSION 3.11.0)
cmake_policy(VERSION 3.16)
And I believed it is equal to the code before, as I understood cmake_policy(VERSION ...)
so:
- All policies released until 3.16 are set to NEW
- All policies released after 3.16 are set to OLD
But instead I got:
An attempt was made to set the policy version of CMake to "3.16" which is
greater than this version of CMake. This is not allowed because the
greater version may have new policies not known to this CMake. You may
need a newer CMake version to build this project.
So I don't see any use case for calling cmake_policy(VERSION ...)
as this will always set to the minimum version passed to cmake_minimum_required
and I don't know any (good) project which is not using cmake_minimum_required
.
Therefore I suggest to allow unknown CMake versions for this function and use the behaviour described above.