Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot build CMake project because "Compatibility with CMake < 3.5 has been removed from CMake."

Tags:

cmake

I want to clone and build the following example repository:

https://github.com/bewagner/fetchContent_example

This is what I did:

git clone https://github.com/bewagner/fetchContent_example.git
cd fetchContent_example
mkdir build
cd build
cmake ..

But CMake gives me the following error:

CMake Error at build/_deps/doctest-src/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 has been removed from CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.

  Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.

Here doctest is a dependency of this project. If I open build/_deps/doctest-src/CMakeLists.txt, the first line reads:

cmake_minimum_required(VERSION 3.0)

On the other hand, if I run

cmake --version

then I get

cmake version 4.0.0-rc4

I'm confused. How can I build this project?

Is the error saying that my CMake version is too new to build this project? Do I need to install an older version of CMake?

Suppose then I have two dependencies: one that requires CMake 3.2 and one that requires CMake 4.0. Is it impossible to build the project without changing the code in the dependencies?

like image 391
kaba Avatar asked Jan 25 '26 00:01

kaba


1 Answers

There is now1 an environment variable (documentation2 | relevant merge request) you can use to pass the CMAKE_POLICY_VERSION_MINIMUM value mentioned in the other answer:

export CMAKE_POLICY_VERSION_MINIMUM=3.5

I think this is easier to use for users not familiar with CMake, to compile projects you don't have control on (and would rather not modify the files of), or for projects that are built by a complex toolchain (such as installing a project via pip).

Just export it to your environment before compilation, or set it while you are calling cmake:

CMAKE_POLICY_VERSION_MINIMUM=3.5 cmake ..

The caveat mentioned in the other answer still applies: this will not work if the project you are building relies on previously-deprecated features.


1 As of 2025-02-20, commit 33856b1d62e5311f456c458295ccc900eb9a38f0, should be in any CMAKE >= 4.0-rc2

2 Also mentioned on the variable page. The updated documentation was not live when this answer was first written.

like image 117
MayeulC Avatar answered Jan 27 '26 01:01

MayeulC