最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

I want to clone and build the following example repository:

This is what I did:

git clone .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?

I want to clone and build the following example repository:

https://github/bewagner/fetchContent_example

This is what I did:

git clone https://github/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?

Share Improve this question asked Mar 25 at 20:56 kabakaba 7396 silver badges23 bronze badges 4
  • The error gave you a possible solution (-DCMAKE_POLICY_VERSION_MINIMUM=3.5). If that doesn't work, file a bug upstream and tell them to update their project to work with modern cmake. – Stephen Newell Commented Mar 25 at 21:21
  • @StephenNewell As I understand it, setting the version on the command-line potentially changes the meaning of things in CMake files, so then you just hope for the best. In this case it does work. In general, it probably doesn't. I'm wondering how this break in backwards compatibility should in general be navigated. Perhaps installing a previous version of CMake is the only way that always works? That would mean that each project in the future should specify the CMake version on which it should be built. – kaba Commented Mar 25 at 21:46
  • Projects do specify what cmake version they build with using cmake_minimum_required and cmake_policy. If you truly want a reproducible build then the exact version of cmake is required of course, but so are your compiler, libc, binutils, and so on. I'm not sure this is an issue unique to cmake. – Stephen Newell Commented Mar 25 at 21:50
  • @StephenNewell I think it is confusing to me because up to this point if I needed CMake, I could just install the latest CMake, and that would work on all CMake projects, old or new. But starting from 4.0.0 one now needs a specific version of CMake to build a specific project. – kaba Commented Mar 25 at 21:53
Add a comment  | 

2 Answers 2

Reset to default 1

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?

Yes, this is the exact meaning of the error message: CMake 4.0.0 no longer supports features deprecated in CMake 3.5 or earlier.

If a project actually uses such deprecated features, then you need to build the project with CMake 3.31 or older.

If a project doesn't use such deprecated features, but is written with

cmake_minimum_required(VERSION 3.4) # or lower CMake version

then you could redefine a project's VERSION specification via setting CMAKE_POLICY_VERSION_MINIMUM parameter.

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?

If your project's dependencies can be expressed as pre-installed libraries, then you could just build (and install) the first one with older CMake, build (and install) the other one with newer CMake, and then build your project with CMake suitable for it.

If your project's dependencies are added with add_subdirectory calls (or via FetchContent mechanism), then they will co-exist in a single CMake "environment". If these dependencies require incompatible CMake versions, then your project simply won't work.

Cmake 4.0.0 is a release candidate and not finally released. Did you try the latest official Release 3.31.6 or earlier?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论