Skip to content

Commit 5164027

Browse files
committed
ctranslate2: fix CMake 4 compatibility with patch file
Adds a patch file to update cmake_minimum_required from 3.7 to 3.10 in the main CMakeLists.txt files. Keeps the existing postPatch for vendored dependencies since those are git submodules that can't be easily patched with patch files. CMake 4 doesn't support versions older than 3.5, and versions between 3.5-3.10 are deprecated. Upstream is working on a similar fix in OpenNMT/CTranslate2#1907 Fixes: NixOS#450258 Signed-off-by: Dave Walker <[email protected]>
1 parent 478466b commit 5164027

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
From 5aca1c2147825420dca2d69d0338a616755d38dc Mon Sep 17 00:00:00 2001
2+
From: Dave Walker <[email protected]>
3+
Date: Thu, 9 Oct 2025 15:14:54 +0100
4+
Subject: [PATCH] Update CMake minimum required version to 3.10
5+
6+
CMake 4 removed compatibility with CMake versions < 3.5, and versions
7+
between 3.5-3.10 are deprecated.
8+
9+
This change updates the minimum required version to 3.10 to ensure
10+
compatibility with modern CMake versions including CMake 4.x.
11+
12+
This issue is affecting NixOS users (see
13+
https://github.com/NixOS/nixpkgs/issues/450258) and will likely impact
14+
other distributions as they upgrade to CMake 4.x.
15+
16+
Inspired by: https://github.com/OpenNMT/CTranslate2/pull/1907
17+
---
18+
CMakeLists.txt | 2 +-
19+
examples/wngt2020/CMakeLists.txt | 2 +-
20+
2 files changed, 2 insertions(+), 2 deletions(-)
21+
22+
diff --git a/CMakeLists.txt b/CMakeLists.txt
23+
index 62b99d1..ecc085c 100644
24+
--- a/CMakeLists.txt
25+
+++ b/CMakeLists.txt
26+
@@ -1,4 +1,4 @@
27+
-cmake_minimum_required(VERSION 3.7)
28+
+cmake_minimum_required(VERSION 3.10)
29+
30+
# Set policy for setting the MSVC runtime library for static MSVC builds
31+
if(POLICY CMP0091)
32+
diff --git a/examples/wngt2020/CMakeLists.txt b/examples/wngt2020/CMakeLists.txt
33+
index d0a527d..da1e57d 100644
34+
--- a/examples/wngt2020/CMakeLists.txt
35+
+++ b/examples/wngt2020/CMakeLists.txt
36+
@@ -1,4 +1,4 @@
37+
-cmake_minimum_required(VERSION 3.7)
38+
+cmake_minimum_required(VERSION 3.10)
39+
project(wngt2020)
40+
set(CMAKE_CXX_STANDARD 11)
41+
set(CMAKE_BUILD_TYPE Release)
42+
--
43+
2.51.0
44+

pkgs/by-name/ct/ctranslate2/package.nix

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ stdenv'.mkDerivation (finalAttrs: {
3838
hash = "sha256-EM2kunqtxo0BTIzrEomfaRsdav7sx6QEOhjDtjjSoYY=";
3939
};
4040

41-
# Fix CMake 4 compatibility
41+
patches = [
42+
# Update CMake minimum required version for CMake 4 compatibility
43+
# https://github.com/NixOS/nixpkgs/issues/450258
44+
# Inspired by: https://github.com/OpenNMT/CTranslate2/pull/1907
45+
./cmake-3.10.patch
46+
];
47+
48+
# Fix CMake 4 compatibility in vendored dependencies (submodules)
4249
postPatch = ''
4350
substituteInPlace third_party/cpu_features/CMakeLists.txt \
4451
--replace-fail \

0 commit comments

Comments
 (0)