Skip to content

Commit 2bdc592

Browse files
committed
Fix Linux full source build
1 parent 323b6b1 commit 2bdc592

3 files changed

Lines changed: 42 additions & 11 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ option(USE_SYSTEM_ICU "Use system ICU" OFF)
1414
option(USE_SYSTEM_ONNXRUNTIME "Use system ONNX Runtime" OFF)
1515
option(LINUX_SOURCE_BUILD
1616
"Build Whispercpp dependency from source on Linux instead of using one of the precompiled variants" OFF)
17+
option(
18+
WHISPER_DYNAMIC_BACKENDS
19+
"Build backends for all CPU variants when building Whispercpp from source, instead of only building one CPU backend optimised for the host system"
20+
OFF)
21+
option(
22+
WHISPER_BUILD_ALL_CUDA_ARCHITECTURES
23+
"Build CUDA backend for all NVidia architectures when building Whispercpp from source, instead of only building for the host system's GPU"
24+
OFF)
1725

1826
# Doesn't seem to do anything set(DISABLE_ONNXRUNTIME_GPU OFF CACHE STRING "Disables GPU support of ONNX Runtime (Only
1927
# valid on Linux)")

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ cmake --build build_x86_64 --target install
237237

238238
When building from source, the Vulkan and OpenCL development libraries are optional and will only be used in the build if they are installed. Similarly if the CUDA or ROCm toolkits are found, they will also be used and the relevant Whisper backends will be enabled.
239239

240+
The default for a full source build is to build both Whisper and the plugin optimized for the host system. To change this behaviour add one or both of the following options to the CMake configure command (the first of the two):
241+
242+
* to build all CPU backends add `-DWHISPER_DYNAMIC_BACKENDS=ON`
243+
* to build all CUDA kernels add `-DWHISPER_BUILD_ALL_CUDA_ARCHITECTURES=ON`
244+
240245
### Windows
241246

242247
Use the CI scripts again, for example:

cmake/BuildWhispercpp.cmake

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ function(WHISPER_LIB_PATHS COMPONENT SOURCE_DIR WHISPER_STATIC_LIB_PATH WHISPER_
3737
lib_name(${COMPONENT} WHISPER_COMPONENT_IMPORT_LIB)
3838

3939
if(UNIX AND NOT APPLE)
40-
set(STATIC_PATH ${SOURCE_DIR}/lib)
41-
set(SHARED_PATH ${SOURCE_DIR}/lib)
42-
set(SHARED_BIN_PATH ${SOURCE_DIR}/bin)
40+
if(${LINUX_SOURCE_BUILD})
41+
set(STATIC_PATH ${SOURCE_DIR})
42+
set(SHARED_PATH ${SOURCE_DIR})
43+
set(SHARED_BIN_PATH ${SOURCE_DIR})
44+
else()
45+
set(STATIC_PATH ${SOURCE_DIR}/lib)
46+
set(SHARED_PATH ${SOURCE_DIR}/lib)
47+
set(SHARED_BIN_PATH ${SOURCE_DIR}/bin)
48+
endif()
4349
else()
4450
set(STATIC_PATH ${SOURCE_DIR}/${CMAKE_INSTALL_LIBDIR})
4551
set(SHARED_PATH ${SOURCE_DIR}/${CMAKE_INSTALL_LIBDIR})
@@ -139,6 +145,8 @@ function(ADD_WHISPER_RUNTIME_MODULE COMPONENT SOURCE_DIR LIB_DIR)
139145
endfunction()
140146

141147
if(APPLE)
148+
add_compile_definitions(WHISPER_DYNAMIC_BACKENDS)
149+
142150
# check the "MACOS_ARCH" env var to figure out if this is x86 or arm64
143151
if($ENV{MACOS_ARCH} STREQUAL "x86_64")
144152
set(WHISPER_CPP_HASH "02446b1d508711b26cc778db48d5b8ef2dd7b0c98f5c9dfe39a1ad2ef9e3df07")
@@ -168,7 +176,6 @@ if(APPLE)
168176
list(APPEND WHISPER_RUNTIME_MODULES GGMLMetal GGMLBlas)
169177
set(WHISPER_DEPENDENCY_LIBRARIES "-framework Accelerate" "-framework CoreML" "-framework Metal" ${BLAS_LIBRARIES})
170178
set(WHISPER_LIBRARY_TYPE SHARED)
171-
add_compile_definitions(WHISPER_DYNAMIC_BACKENDS)
172179

173180
FetchContent_Declare(
174181
whispercpp_fetch
@@ -184,6 +191,8 @@ if(APPLE)
184191
file(GLOB WHISPER_DYLIBS ${whispercpp_fetch_SOURCE_DIR}/lib/*.dylib)
185192
install(FILES ${WHISPER_DYLIBS} DESTINATION "${CMAKE_PROJECT_NAME}.plugin/Contents/Frameworks")
186193
elseif(WIN32)
194+
add_compile_definitions(WHISPER_DYNAMIC_BACKENDS)
195+
187196
if(NOT DEFINED ACCELERATION)
188197
message(FATAL_ERROR "ACCELERATION is not set. Please set it to either `generic`, `nvidia`, or `amd`")
189198
endif()
@@ -231,7 +240,6 @@ elseif(WIN32)
231240
set(WHISPER_SOURCE_DIR ${whispercpp_fetch_SOURCE_DIR})
232241
set(WHISPER_LIB_DIR ${whispercpp_fetch_SOURCE_DIR})
233242
set(WHISPER_DEPENDENCY_LIBRARIES "${whispercpp_fetch_SOURCE_DIR}/lib/libopenblas.lib")
234-
add_compile_definitions(WHISPER_DYNAMIC_BACKENDS)
235243

236244
# glob all dlls in the bin directory and install them
237245
file(GLOB WHISPER_DLLS ${whispercpp_fetch_SOURCE_DIR}/bin/*.dll)
@@ -253,6 +261,7 @@ else()
253261
find_package(BLAS REQUIRED)
254262

255263
if(NOT LINUX_SOURCE_BUILD)
264+
add_compile_definitions(WHISPER_DYNAMIC_BACKENDS)
256265
set(WHISPER_LIBRARY_TYPE SHARED)
257266
set(WHISPER_LIBRARIES Whisper GGML GGMLBase)
258267
list(APPEND WHISPER_DEPENDENCY_LIBRARIES Vulkan::Vulkan BLAS::BLAS)
@@ -274,7 +283,6 @@ else()
274283
GGMLBlas
275284
GGMLVulkan
276285
GGMLOpenCL)
277-
add_compile_definitions(WHISPER_DYNAMIC_BACKENDS)
278286

279287
find_package(
280288
Vulkan
@@ -372,7 +380,7 @@ else()
372380
GGMLCPU-SAPPHIRERAPIDS)
373381
add_compile_definitions(WHISPER_DYNAMIC_BACKENDS)
374382
else()
375-
list(APPEND WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_NATIVE=ON)
383+
list(APPEND WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_NATIVE=ON -DGGML_BACKEND_DL=OFF)
376384
list(APPEND WHISPER_LIBRARIES GGMLBlas GGMLCPU)
377385
endif()
378386

@@ -428,7 +436,14 @@ else()
428436
find_package(CUDAToolkit QUIET)
429437
if(CUDAToolkit_FOUND)
430438
message(STATUS "CUDA found, Libraries: ${CUDAToolkit_LIBRARIES}")
431-
list(APPEND WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=native)
439+
list(APPEND WHISPER_ADDITIONAL_CMAKE_ARGS -DGGML_CUDA=ON)
440+
441+
if(WHISPER_BUILD_ALL_CUDA_ARCHITECTURES)
442+
list(APPEND WHISPER_ADDITIONAL_CMAKE_ARGS -DCMAKE_CUDA_ARCHITECTURES=all)
443+
else()
444+
list(APPEND WHISPER_ADDITIONAL_CMAKE_ARGS -DCMAKE_CUDA_ARCHITECTURES=native)
445+
endif()
446+
432447
if(WHISPER_DYNAMIC_BACKENDS)
433448
list(APPEND WHISPER_RUNTIME_MODULES GGMLCUDA)
434449
else()
@@ -438,9 +453,12 @@ else()
438453
endif()
439454

440455
foreach(component ${WHISPER_LIBRARIES})
441-
whisper_lib_paths(${component} ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/obs-plugins/${CMAKE_PROJECT_NAME}
442-
WHISPER_STATIC_LIB_PATH WHISPER_SHARED_LIB_PATH WHISPER_SHARED_MODULE_PATH)
443-
list(APPEND WHISPER_BYPRODUCTS ${WHISPER_SHARED_LIB_PATH})
456+
lib_name(${component} WHISPER_COMPONENT_IMPORT_LIB)
457+
list(
458+
APPEND
459+
WHISPER_BYPRODUCTS
460+
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/obs-plugins/${CMAKE_PROJECT_NAME}/${CMAKE_SHARED_LIBRARY_PREFIX}${WHISPER_COMPONENT_IMPORT_LIB}${CMAKE_SHARED_LIBRARY_SUFFIX}"
461+
)
444462
endforeach(component ${WHISPER_LIBRARIES})
445463

446464
# On Linux build a shared Whisper library

0 commit comments

Comments
 (0)