Skip to content

PyTorch cmake configuration fails with CMake 4.0.0 #150167

@WangYutao1995

Description

@WangYutao1995

🐛 Describe the bug

Error message

-- Found SYCL:  (found version "20250200")
-- Building using own protobuf under third_party per request.
-- Use custom protobuf build.
CMake Error at third_party/protobuf/cmake/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.
 
-- Configuring incomplete, errors occurred!
-- Building version 2.7.0a0+git504bc92

Root cause
CMake 4.0.0 is released to pypi.org today (March 28, 2025), but it is not compatible with cmake_minimum_required defined in many third_party project's CMakeLists.txt, such as protobuf.
https://github.com/protocolbuffers/protobuf/blob/d1eca4e4b421cd2997495c4b4e65cea6be4e9b8a/cmake/CMakeLists.txt
https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html

Changed in version 4.0: Compatibility with versions of CMake older than 3.5 is removed. 
Calls to cmake_minimum_required(VERSION) or cmake_policy(VERSION) that do not specify at least 3.5 as their policy version (optionally via ...<max>) will produce an error in CMake 4.0 and above.

Workaround
Stick to CMake 3.31

python -m pip install cmake==3.31

Versions

PyTorch: main branch
CMake: 4.0.0

cc @malfet @seemethere @chuanqi129

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: buildBuild system issuestriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions