Skip to content

Commit 510ecbc

Browse files
committed
Fix build with CMake 4
1 parent 4b6b2d4 commit 510ecbc

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ option(ENABLE_FRONTEND_API "Use obs-frontend-api for UI functionality" ON)
88
option(ENABLE_QT "Use Qt functionality" ON)
99
option(ENABLE_TESTS "Enable tests" OFF)
1010

11+
if(CMAKE_MAJOR_VERSION EQUAL 4)
12+
message(STATUS "CMake 4 detected")
13+
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
14+
endif()
15+
1116
include(compilerconfig)
1217
include(defaults)
1318
include(helpers)

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ For other distros where you can't use the CI build script, you can build the plu
156156
cmake -B build-dir --preset linux-x86_64 -DUSE_SYSTEM_CURL=ON -DUSE_SYSTEM_ICU=ON -DCMAKE_INSTALL_PREFIX=./output_dir
157157
```
158158

159-
Note: if using CMake 4.0.0 or higher you may also need to add `-DCMAKE_POLICY_VERSION_MINIMUM=3.5`. If possible, please use a version of CMake that is older than 4.0.0, as many of the dependencies used by this plugin still have their minimum versions set to very old versions of CMake.
160-
161159
1. Build the plugin and copy the files to the output directory
162160

163161
```sh

cmake/BuildCTranslate2.cmake

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ else()
6262
# build cpu_features from source
6363
set(CPU_FEATURES_VERSION "0.9.0")
6464
set(CPU_FEATURES_URL "https://github.com/google/cpu_features.git")
65-
set(CPU_FEATURES_CMAKE_ARGS -DBUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF)
65+
if(CMAKE_MAJOR_VERSION EQUAL 4)
66+
set(CPU_FEATURES_CMAKE_ARGS -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5)
67+
else()
68+
set(CPU_FEATURES_CMAKE_ARGS -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF)
69+
endif()
6670
ExternalProject_Add(
6771
cpu_features_build
6872
GIT_REPOSITORY ${CPU_FEATURES_URL}
@@ -95,7 +99,12 @@ else()
9599
set(CT2_URL "https://github.com/OpenNMT/CTranslate2.git")
96100
set(CT2_OPENBLAS_CMAKE_ARGS -DWITH_OPENBLAS=OFF)
97101

98-
set(CT2_CMAKE_PLATFORM_OPTIONS -DBUILD_SHARED_LIBS=OFF -DOPENMP_RUNTIME=NONE -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
102+
if(CMAKE_MAJOR_VERSION EQUAL 4)
103+
set(CT2_CMAKE_PLATFORM_OPTIONS -DBUILD_SHARED_LIBS=OFF -DOPENMP_RUNTIME=NONE -DCMAKE_POSITION_INDEPENDENT_CODE=ON
104+
-DCMAKE_POLICY_VERSION_MINIMUM=3.5)
105+
else()
106+
set(CT2_CMAKE_PLATFORM_OPTIONS -DBUILD_SHARED_LIBS=OFF -DOPENMP_RUNTIME=NONE -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
107+
endif()
99108
set(CT2_LIB_INSTALL_LOCATION
100109
${CMAKE_INSTALL_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}ctranslate2${CMAKE_STATIC_LIBRARY_SUFFIX})
101110

@@ -123,6 +132,7 @@ else()
123132
-DWITH_COVERAGE=OFF
124133
-DWITH_PROFILING=OFF
125134
-DBUILD_CLI=OFF
135+
-DBUILD_TESTS=OFF
126136
${CT2_OPENBLAS_CMAKE_ARGS}
127137
${CT2_CMAKE_PLATFORM_OPTIONS}
128138
LOG_CONFIGURE ON

cmake/BuildSentencepiece.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ else()
4848
ExternalProject_Add(
4949
sentencepiece_build
5050
GIT_REPOSITORY ${SP_URL}
51-
GIT_TAG v0.1.99
51+
GIT_TAG v0.2.1
5252
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${CMAKE_BUILD_TYPE}
5353
CMAKE_GENERATOR ${CMAKE_GENERATOR}
5454
INSTALL_COMMAND ${CMAKE_COMMAND} --install <BINARY_DIR> --config ${CMAKE_BUILD_TYPE}

0 commit comments

Comments
 (0)