2023-08-12 20:51:51 +00:00
|
|
|
include(ExternalProject)
|
2024-04-02 01:59:37 +00:00
|
|
|
include(FetchContent)
|
2023-11-15 23:49:25 +00:00
|
|
|
|
2024-07-31 04:40:36 +00:00
|
|
|
set(PREBUILT_WHISPERCPP_VERSION "0.0.5")
|
|
|
|
set(PREBUILT_WHISPERCPP_URL_BASE
|
|
|
|
"https://github.com/occ-ai/occ-ai-dep-whispercpp/releases/download/${PREBUILT_WHISPERCPP_VERSION}")
|
2023-08-12 20:51:51 +00:00
|
|
|
|
2023-11-15 23:49:25 +00:00
|
|
|
if(APPLE)
|
2024-03-22 17:33:07 +00:00
|
|
|
# check the "MACOS_ARCH" env var to figure out if this is x86 or arm64
|
|
|
|
if($ENV{MACOS_ARCH} STREQUAL "x86_64")
|
2024-07-31 04:40:36 +00:00
|
|
|
set(WHISPER_CPP_HASH "da61500b9a37f8630b9e4ed49bc3fe7858729d7a28a2e80bf6cfa4cb97523546")
|
2024-04-02 01:59:37 +00:00
|
|
|
elseif($ENV{MACOS_ARCH} STREQUAL "arm64")
|
2024-07-31 04:40:36 +00:00
|
|
|
set(WHISPER_CPP_HASH "ef1e2628ba09414c0848d58c471440f38b8393cb5d428edf82b9e78aeeecdd15")
|
2024-03-22 17:33:07 +00:00
|
|
|
else()
|
2024-04-02 01:59:37 +00:00
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"The MACOS_ARCH environment variable is not set to a valid value. Please set it to either `x86_64` or `arm64`")
|
2024-03-22 17:33:07 +00:00
|
|
|
endif()
|
2024-07-31 04:40:36 +00:00
|
|
|
set(WHISPER_CPP_URL
|
|
|
|
"${PREBUILT_WHISPERCPP_URL_BASE}/whispercpp-macos-$ENV{MACOS_ARCH}-${PREBUILT_WHISPERCPP_VERSION}.tar.gz")
|
2023-08-12 20:51:51 +00:00
|
|
|
|
2024-04-02 01:59:37 +00:00
|
|
|
FetchContent_Declare(
|
|
|
|
whispercpp_fetch
|
|
|
|
URL ${WHISPER_CPP_URL}
|
|
|
|
URL_HASH SHA256=${WHISPER_CPP_HASH})
|
|
|
|
FetchContent_MakeAvailable(whispercpp_fetch)
|
|
|
|
|
|
|
|
add_library(Whispercpp::Whisper STATIC IMPORTED)
|
|
|
|
set_target_properties(
|
|
|
|
Whispercpp::Whisper
|
2024-07-31 04:40:36 +00:00
|
|
|
PROPERTIES IMPORTED_LOCATION
|
|
|
|
${whispercpp_fetch_SOURCE_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX})
|
2024-04-02 01:59:37 +00:00
|
|
|
set_target_properties(Whispercpp::Whisper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
|
|
|
|
${whispercpp_fetch_SOURCE_DIR}/include)
|
2024-07-31 04:40:36 +00:00
|
|
|
add_library(Whispercpp::GGML STATIC IMPORTED)
|
|
|
|
set_target_properties(
|
|
|
|
Whispercpp::GGML
|
|
|
|
PROPERTIES IMPORTED_LOCATION
|
|
|
|
${whispercpp_fetch_SOURCE_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}ggml${CMAKE_STATIC_LIBRARY_SUFFIX})
|
|
|
|
|
|
|
|
add_library(Whispercpp::CoreML STATIC IMPORTED)
|
|
|
|
set_target_properties(
|
|
|
|
Whispercpp::CoreML
|
|
|
|
PROPERTIES
|
|
|
|
IMPORTED_LOCATION
|
|
|
|
${whispercpp_fetch_SOURCE_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}whisper.coreml${CMAKE_STATIC_LIBRARY_SUFFIX})
|
2024-04-02 01:59:37 +00:00
|
|
|
|
|
|
|
elseif(WIN32)
|
2024-08-09 17:44:15 +00:00
|
|
|
if(NOT DEFINED ACCELERATION)
|
|
|
|
message(FATAL_ERROR "ACCELERATION is not set. Please set it to either `cpu`, `cuda` or `hipblas`")
|
|
|
|
endif()
|
2024-04-02 01:59:37 +00:00
|
|
|
|
2024-08-09 17:44:15 +00:00
|
|
|
set(ARCH_PREFIX ${ACCELERATION})
|
2024-04-02 01:59:37 +00:00
|
|
|
set(WHISPER_CPP_URL
|
2024-07-31 04:40:36 +00:00
|
|
|
"${PREBUILT_WHISPERCPP_URL_BASE}/whispercpp-windows-${ARCH_PREFIX}-${PREBUILT_WHISPERCPP_VERSION}.zip")
|
2024-08-09 17:44:15 +00:00
|
|
|
if(${ACCELERATION} STREQUAL "cpu")
|
2024-07-31 04:40:36 +00:00
|
|
|
set(WHISPER_CPP_HASH "2b1cfa0dd764132c4cde60e112a8e6328d28d158d91a8845080baa3e9d2dcdcd")
|
|
|
|
add_compile_definitions("LOCALVOCAL_WITH_CPU")
|
2024-08-09 17:44:15 +00:00
|
|
|
elseif(${ACCELERATION} STREQUAL "cuda")
|
2024-07-31 04:40:36 +00:00
|
|
|
set(WHISPER_CPP_HASH "011e813742fddf0911c4a36d2080d7a388cf78738081297088e7d50023e4f9bc")
|
|
|
|
add_compile_definitions("LOCALVOCAL_WITH_CUDA")
|
2024-08-09 17:44:15 +00:00
|
|
|
elseif(${ACCELERATION} STREQUAL "hipblas")
|
2024-07-31 04:40:36 +00:00
|
|
|
set(WHISPER_CPP_HASH "f2980d6cd3df9cac464378d26d2c19d827bcac995c8d0398a39230a9be936013")
|
|
|
|
add_compile_definitions("LOCALVOCAL_WITH_HIPBLAS")
|
2023-09-26 03:55:32 +00:00
|
|
|
else()
|
2024-04-02 01:59:37 +00:00
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
2024-07-31 04:40:36 +00:00
|
|
|
"The ACCELERATION environment variable is not set to a valid value. Please set it to either `cpu` or `cuda` or `hipblas`"
|
2024-04-02 01:59:37 +00:00
|
|
|
)
|
2023-09-26 03:55:32 +00:00
|
|
|
endif()
|
2023-09-11 04:48:49 +00:00
|
|
|
|
2024-04-02 01:59:37 +00:00
|
|
|
FetchContent_Declare(
|
|
|
|
whispercpp_fetch
|
|
|
|
URL ${WHISPER_CPP_URL}
|
2024-07-19 18:02:24 +00:00
|
|
|
URL_HASH SHA256=${WHISPER_CPP_HASH}
|
|
|
|
DOWNLOAD_EXTRACT_TIMESTAMP TRUE)
|
2024-04-02 01:59:37 +00:00
|
|
|
FetchContent_MakeAvailable(whispercpp_fetch)
|
|
|
|
|
|
|
|
add_library(Whispercpp::Whisper SHARED IMPORTED)
|
|
|
|
set_target_properties(
|
|
|
|
Whispercpp::Whisper
|
|
|
|
PROPERTIES IMPORTED_LOCATION
|
|
|
|
${whispercpp_fetch_SOURCE_DIR}/bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX})
|
|
|
|
set_target_properties(
|
|
|
|
Whispercpp::Whisper
|
|
|
|
PROPERTIES IMPORTED_IMPLIB
|
|
|
|
${whispercpp_fetch_SOURCE_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX})
|
|
|
|
set_target_properties(Whispercpp::Whisper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
|
|
|
|
${whispercpp_fetch_SOURCE_DIR}/include)
|
|
|
|
|
2024-08-09 17:44:15 +00:00
|
|
|
if(${ACCELERATION} STREQUAL "cpu")
|
2024-04-02 01:59:37 +00:00
|
|
|
# add openblas to the link line
|
|
|
|
add_library(Whispercpp::OpenBLAS STATIC IMPORTED)
|
|
|
|
set_target_properties(Whispercpp::OpenBLAS PROPERTIES IMPORTED_LOCATION
|
|
|
|
${whispercpp_fetch_SOURCE_DIR}/lib/libopenblas.dll.a)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# glob all dlls in the bin directory and install them
|
|
|
|
file(GLOB WHISPER_DLLS ${whispercpp_fetch_SOURCE_DIR}/bin/*.dll)
|
2024-07-20 00:59:55 +00:00
|
|
|
install(FILES ${WHISPER_DLLS} DESTINATION "obs-plugins/64bit")
|
2023-09-11 05:14:44 +00:00
|
|
|
else()
|
2024-07-31 04:40:36 +00:00
|
|
|
if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo)
|
|
|
|
set(Whispercpp_BUILD_TYPE Release)
|
|
|
|
else()
|
|
|
|
set(Whispercpp_BUILD_TYPE Debug)
|
|
|
|
endif()
|
2024-05-31 03:00:04 +00:00
|
|
|
set(Whispercpp_Build_GIT_TAG "v1.6.2")
|
2024-04-02 01:59:37 +00:00
|
|
|
set(WHISPER_EXTRA_CXX_FLAGS "-fPIC")
|
2024-05-31 03:00:04 +00:00
|
|
|
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=OFF -DWHISPER_CUBLAS=OFF -DWHISPER_OPENBLAS=OFF)
|
2024-04-02 01:59:37 +00:00
|
|
|
|
2024-04-25 21:14:13 +00:00
|
|
|
# On Linux build a static Whisper library
|
2023-09-11 05:14:44 +00:00
|
|
|
ExternalProject_Add(
|
|
|
|
Whispercpp_Build
|
|
|
|
DOWNLOAD_EXTRACT_TIMESTAMP true
|
|
|
|
GIT_REPOSITORY https://github.com/ggerganov/whisper.cpp.git
|
2023-11-15 23:49:25 +00:00
|
|
|
GIT_TAG ${Whispercpp_Build_GIT_TAG}
|
2023-09-11 05:14:44 +00:00
|
|
|
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE}
|
|
|
|
BUILD_BYPRODUCTS <INSTALL_DIR>/lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX}
|
|
|
|
CMAKE_GENERATOR ${CMAKE_GENERATOR}
|
2023-11-15 23:49:25 +00:00
|
|
|
INSTALL_COMMAND ${CMAKE_COMMAND} --install <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E
|
|
|
|
copy <SOURCE_DIR>/ggml.h <INSTALL_DIR>/include
|
2023-09-11 05:14:44 +00:00
|
|
|
CONFIGURE_COMMAND
|
2023-09-26 03:55:32 +00:00
|
|
|
${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} <SOURCE_DIR> -B <BINARY_DIR> -G
|
2023-09-11 05:14:44 +00:00
|
|
|
${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE}
|
|
|
|
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13
|
|
|
|
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS}
|
|
|
|
-DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=OFF -DWHISPER_BUILD_TESTS=OFF
|
2023-09-26 03:55:32 +00:00
|
|
|
-DWHISPER_BUILD_EXAMPLES=OFF ${WHISPER_ADDITIONAL_CMAKE_ARGS})
|
2023-09-11 04:48:49 +00:00
|
|
|
|
2024-04-02 01:59:37 +00:00
|
|
|
ExternalProject_Get_Property(Whispercpp_Build INSTALL_DIR)
|
2023-09-11 04:48:49 +00:00
|
|
|
|
2024-04-25 21:14:13 +00:00
|
|
|
# add the static Whisper library to the link line
|
2023-09-11 05:14:44 +00:00
|
|
|
add_library(Whispercpp::Whisper STATIC IMPORTED)
|
|
|
|
set_target_properties(
|
|
|
|
Whispercpp::Whisper
|
|
|
|
PROPERTIES IMPORTED_LOCATION
|
|
|
|
${INSTALL_DIR}/lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX})
|
2024-04-02 01:59:37 +00:00
|
|
|
set_target_properties(Whispercpp::Whisper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)
|
|
|
|
endif()
|
2023-08-12 20:51:51 +00:00
|
|
|
|
|
|
|
add_library(Whispercpp INTERFACE)
|
|
|
|
add_dependencies(Whispercpp Whispercpp_Build)
|
2023-09-11 05:14:44 +00:00
|
|
|
target_link_libraries(Whispercpp INTERFACE Whispercpp::Whisper)
|
2024-08-09 17:44:15 +00:00
|
|
|
if(WIN32 AND "${ACCELERATION}" STREQUAL "cpu")
|
2023-09-11 05:14:44 +00:00
|
|
|
target_link_libraries(Whispercpp INTERFACE Whispercpp::OpenBLAS)
|
2023-09-12 05:03:05 +00:00
|
|
|
endif()
|
2023-08-12 20:51:51 +00:00
|
|
|
if(APPLE)
|
2024-07-31 04:40:36 +00:00
|
|
|
target_link_libraries(Whispercpp INTERFACE "-framework Accelerate -framework CoreML -framework Metal")
|
|
|
|
target_link_libraries(Whispercpp INTERFACE Whispercpp::GGML Whispercpp::CoreML)
|
2023-08-12 20:51:51 +00:00
|
|
|
endif(APPLE)
|