Skip to content

Make compatible with CMake 4.0 #935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mvieth
Copy link

@mvieth mvieth commented Mar 30, 2025

When trying to build with CMake 4.0, the following error is shown:

CMake Error at CMakeLists.txt:2 (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.

This change raises the minimum required CMake version to 3.5 and thus makes the project compatible with CMake 4.0

When trying to build with CMake 4.0, the following error is shown:

CMake Error at CMakeLists.txt:2 (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.

This change raises the minimum required CMake version to 3.5 and thus makes the project compatible with CMake 4.0
@jwhui
Copy link

jwhui commented Mar 31, 2025

We are running into this issue as well in our projects.

@XavierChanth
Copy link

Same here, it seems some GHA runners are using cmake v3.31.6, some are using 4.0.0 (ubuntu-latest).

@joelguittet
Copy link

Confirming this issue on my side 👍

@benbuck
Copy link

benbuck commented Apr 7, 2025

In case it helps anyone else that is using cJSON in their project from CMake, you can work around this issue using a CMake file plus a patch file, something like this:

CMake file:

include(FetchContent)
find_package(Patch REQUIRED)

FetchContent_Declare(
    cJSON
    GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git
    GIT_TAG v1.7.18
    PATCH_COMMAND "${Patch_EXECUTABLE}" -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/cJSON.patch
    UPDATE_DISCONNECTED 1
    EXCLUDE_FROM_ALL
)

FetchContent_MakeAvailable(cJSON)

Patch file:

diff --git i/CMakeLists.txt w/CMakeLists.txt
index 36a6cb5..9428da5 100644
--- i/CMakeLists.txt
+++ w/CMakeLists.txt
@@ -1,2 +1,2 @@
 set(CMAKE_LEGACY_CYGWIN_WIN32 0)
-cmake_minimum_required(VERSION 3.0)
+cmake_minimum_required(VERSION 3.10)

And of course you can customize the CMake file and patch file to suit your project needs.

-Benbuck

@hhoffstaette
Copy link

I just saw that this PR only updates to 3.5 - it should probably be 3.10, otherwise cmake-4 will complain about more pending deprecation. It did for me when I reported what became our fix in Gentoo :)

@mvieth
Copy link
Author

mvieth commented Apr 30, 2025

I just saw that this PR only updates to 3.5 - it should probably be 3.10, otherwise cmake-4 will complain about more pending deprecation. It did for me when I reported what became our fix in Gentoo :)

That is a valid point, and I am happy to change this pull request to make 3.10 the minimum required version if a maintainer of this repo requests it. I originally chose 3.5 because it is the lowest version that makes CMake 4.0 work, and building with CMake 3.5-3.9 is still possible. So in a sense, 3.5 is the more careful, conservative choice, and I thought it had more chance at getting accepted 🙂

@joelguittet
Copy link

Agree with @mvieth and 3.5 is also common choice if you look at other libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants