cmakeminimum-requirements

How can I tell which minimum CMake version to require in CMakeLists.txt?


In CMakeLists.txt scripts, it is customary to have a:

cmake_minimum_required(VERSION x.y)

for the appropriate x.y version number. But how can I tell what that minimum version is? I don't work with older versions; and as my distribution gets updated, so does CMake, so I may have even introduced commands requiring newer versions over time and I just don't know it.

I could theoretically require the versions I've tested this CMakeLists.txt with, but they're pretty new, and I don't want to restrict users of my code to just that.


Solution

  • tl;dr: Try building with different CMake versions.

    Download the CMake binary from https://cmake.org/files/ according to the claimed minimal required version. You can unpack them in some directory and use this CMake to ensure it is still the minimal required version. You can have as many versions as you wish in parallel. Don't forget to delete the build directory.

    A problem you did not mention, but is also important: Check your code with newer version. New policies can lead to dozens of warnings, many projects try avoiding warnings in releases. So it might be good to have the latest version with the same procedure.