How to fix cmake_minimum_required() deprecation warning?


Today when I recompiled one of my C++ projects using CMake I got the following deprecation warning:

% cmake .. -DCMAKE_CXX_FLAGS="-Wall -Wextra -pedantic"
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of CMake.
  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 2.8)
project(libpopcnt C CXX)

So I could fix this issue by simply increasing the minimum version (here 2.8) to something bigger. But then in a few years, the same issue will reappear when the new minimum version will be deprecated.

Is there a workaround for this issue, where I don’t need to update my code every few years to fix this issue? I know that my project does not compile with CMake 2.7, but I expect my project to compile with CMake >= 2.8.

Thanks for your help.

If you have tested and seen no policy warnings with a newer version (let’s say 3.13 here), you can indicate this with:

cmake_minimum_required(VERSION 2.8...3.13)

This will act like 2.8 as much as possible, but indicates that the project has been tested with 3.13 and does not need to warn about compatibility issues up to that version. It is still recommended to test with your actual minimum version (here, 2.8.0).

CMake 2.8.12 has been release in 2013. This message is about removing support
for behavior deprecated already at this point. Simply go and change your
minimum version from 2.8 to 2.8.12.

Simply go and change your minimum version from 2.8 to 2.8.12.

Indeed, that already fixes the issue on my new M1 Mac Mini. However I am a little confused, won’t the same deprecation warning reappear quickly as I have not increased the minimum version to a much larger number?

cmake_minimum_required(VERSION 2.8...3.13)

Thanks, this seems like a good solution for my issue.

No. It declares that the project is aware of 3.13 behavior and CMake “sees” this as having done the work to upgrade to it.