2023-01-06 17:32:53 +00:00
|
|
|
cmake_minimum_required (VERSION 3.0)
|
2022-12-17 17:52:42 +00:00
|
|
|
|
2023-05-14 16:06:45 +00:00
|
|
|
project(whisper.cpp VERSION 1.4.2)
|
2022-10-07 20:53:12 +00:00
|
|
|
|
2023-01-05 19:22:48 +00:00
|
|
|
# Add path to modules
|
2023-01-05 19:40:59 +00:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
|
|
|
|
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
2022-10-07 20:53:12 +00:00
|
|
|
|
|
|
|
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|
|
|
set(WHISPER_STANDALONE ON)
|
2023-01-05 19:22:48 +00:00
|
|
|
include(GitVars)
|
|
|
|
include(BuildTypes)
|
2022-11-07 18:50:24 +00:00
|
|
|
|
|
|
|
# configure project version
|
|
|
|
if (EXISTS "${CMAKE_SOURCE_DIR}/bindings/ios/Makefile-tmpl")
|
|
|
|
configure_file(${CMAKE_SOURCE_DIR}/bindings/ios/Makefile-tmpl ${CMAKE_SOURCE_DIR}/bindings/ios/Makefile @ONLY)
|
|
|
|
endif()
|
2022-12-12 18:17:27 +00:00
|
|
|
configure_file(${CMAKE_SOURCE_DIR}/bindings/javascript/package-tmpl.json ${CMAKE_SOURCE_DIR}/bindings/javascript/package.json @ONLY)
|
2022-10-07 20:53:12 +00:00
|
|
|
else()
|
|
|
|
set(WHISPER_STANDALONE OFF)
|
|
|
|
endif()
|
|
|
|
|
2022-10-22 10:07:59 +00:00
|
|
|
if (EMSCRIPTEN)
|
|
|
|
set(BUILD_SHARED_LIBS_DEFAULT OFF)
|
|
|
|
|
|
|
|
option(WHISPER_WASM_SINGLE_FILE "whisper: embed WASM inside the generated whisper.js" ON)
|
|
|
|
else()
|
|
|
|
if (MINGW)
|
|
|
|
set(BUILD_SHARED_LIBS_DEFAULT OFF)
|
|
|
|
else()
|
|
|
|
set(BUILD_SHARED_LIBS_DEFAULT ON)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2022-10-07 20:53:12 +00:00
|
|
|
# options
|
|
|
|
|
2023-04-29 07:55:24 +00:00
|
|
|
option(BUILD_SHARED_LIBS "whisper: build shared libs" ${BUILD_SHARED_LIBS_DEFAULT})
|
2022-10-22 10:07:59 +00:00
|
|
|
|
2023-04-29 07:55:24 +00:00
|
|
|
option(WHISPER_ALL_WARNINGS "whisper: enable all compiler warnings" ON)
|
|
|
|
option(WHISPER_ALL_WARNINGS_3RD_PARTY "whisper: enable all compiler warnings in 3rd party libs" OFF)
|
2022-10-07 20:53:12 +00:00
|
|
|
|
2023-04-29 07:55:24 +00:00
|
|
|
option(WHISPER_SANITIZE_THREAD "whisper: enable thread sanitizer" OFF)
|
|
|
|
option(WHISPER_SANITIZE_ADDRESS "whisper: enable address sanitizer" OFF)
|
|
|
|
option(WHISPER_SANITIZE_UNDEFINED "whisper: enable undefined sanitizer" OFF)
|
2022-10-07 20:53:12 +00:00
|
|
|
|
2023-04-29 07:55:24 +00:00
|
|
|
option(WHISPER_BUILD_TESTS "whisper: build tests" ${WHISPER_STANDALONE})
|
|
|
|
option(WHISPER_BUILD_EXAMPLES "whisper: build examples" ${WHISPER_STANDALONE})
|
2022-10-07 20:53:12 +00:00
|
|
|
|
2023-04-30 09:14:33 +00:00
|
|
|
option(WHISPER_SDL2 "whisper: support for libSDL2" OFF)
|
2022-10-07 20:53:12 +00:00
|
|
|
|
2023-05-04 16:31:04 +00:00
|
|
|
option(WHISPER_NO_AVX "whisper: disable AVX" OFF)
|
|
|
|
option(WHISPER_NO_AVX2 "whisper: disable AVX2" OFF)
|
|
|
|
option(WHISPER_NO_FMA "whisper: disable FMA" OFF)
|
|
|
|
option(WHISPER_NO_F16C "whisper: disable F16c" OFF)
|
|
|
|
|
2023-07-04 12:56:11 +00:00
|
|
|
option(WHISPER_OPENVINO "whisper: support for OpenVINO" OFF)
|
|
|
|
|
2022-10-27 15:31:49 +00:00
|
|
|
if (APPLE)
|
2023-04-29 07:55:24 +00:00
|
|
|
option(WHISPER_NO_ACCELERATE "whisper: disable Accelerate framework" OFF)
|
2023-05-04 16:31:04 +00:00
|
|
|
option(WHISPER_COREML "whisper: enable Core ML framework" OFF)
|
|
|
|
option(WHISPER_COREML_ALLOW_FALLBACK "whisper: allow non-CoreML fallback" OFF)
|
2022-10-27 15:31:49 +00:00
|
|
|
else()
|
2023-05-20 18:23:45 +00:00
|
|
|
option(WHISPER_BLAS "whisper: use BLAS libraries" OFF)
|
|
|
|
option(WHISPER_BLAS_VENDOR "whisper: BLAS library vendor" Generic)
|
|
|
|
option(WHISPER_OPENBLAS "whisper: prefer OpenBLAS" OFF)
|
|
|
|
option(WHISPER_CUBLAS "whisper: support for cuBLAS" OFF)
|
2023-08-27 17:03:58 +00:00
|
|
|
option(WHISPER_HIPBLAS "whisper: support for hipBLAS" OFF)
|
2023-05-20 18:23:45 +00:00
|
|
|
option(WHISPER_CLBLAST "whisper: use CLBlast" OFF)
|
2022-10-27 15:31:49 +00:00
|
|
|
endif()
|
|
|
|
|
2023-04-29 07:55:24 +00:00
|
|
|
option(WHISPER_PERF "whisper: enable perf timings" OFF)
|
2022-10-18 15:51:59 +00:00
|
|
|
|
2022-10-07 20:53:12 +00:00
|
|
|
# sanitizers
|
|
|
|
|
2022-10-11 17:57:52 +00:00
|
|
|
if (NOT MSVC)
|
|
|
|
if (WHISPER_SANITIZE_THREAD)
|
2022-10-25 16:13:08 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
|
2022-10-11 17:57:52 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
|
|
|
|
endif()
|
2022-10-07 20:53:12 +00:00
|
|
|
|
2022-10-11 17:57:52 +00:00
|
|
|
if (WHISPER_SANITIZE_ADDRESS)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
|
|
|
|
endif()
|
2022-10-07 20:53:12 +00:00
|
|
|
|
2022-10-11 17:57:52 +00:00
|
|
|
if (WHISPER_SANITIZE_UNDEFINED)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
|
|
|
|
endif()
|
2022-10-07 20:53:12 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math")
|
|
|
|
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
|
|
|
|
|
|
|
|
# dependencies
|
|
|
|
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
2023-04-15 10:21:27 +00:00
|
|
|
# on APPLE
|
|
|
|
if (APPLE)
|
|
|
|
# include Accelerate framework
|
|
|
|
if (NOT WHISPER_NO_ACCELERATE)
|
|
|
|
find_library(ACCELERATE_FRAMEWORK Accelerate)
|
|
|
|
|
|
|
|
if (ACCELERATE_FRAMEWORK)
|
|
|
|
message(STATUS "Accelerate framework found")
|
2022-10-18 15:51:59 +00:00
|
|
|
|
2023-04-15 10:21:27 +00:00
|
|
|
set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} ${ACCELERATE_FRAMEWORK})
|
|
|
|
set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DGGML_USE_ACCELERATE)
|
|
|
|
else()
|
|
|
|
message(WARNING "Accelerate framework not found")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (WHISPER_COREML)
|
|
|
|
find_library(FOUNDATION_FRAMEWORK Foundation)
|
|
|
|
find_library(COREML_FRAMEWORK CoreML)
|
|
|
|
|
|
|
|
if (COREML_FRAMEWORK)
|
|
|
|
message(STATUS "CoreML framework found")
|
|
|
|
|
|
|
|
set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DWHISPER_USE_COREML)
|
|
|
|
else()
|
|
|
|
message(WARNING "CoreML framework not found")
|
|
|
|
endif()
|
2023-04-29 07:55:24 +00:00
|
|
|
|
|
|
|
if (WHISPER_COREML_ALLOW_FALLBACK)
|
2023-05-08 18:08:09 +00:00
|
|
|
set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DWHISPER_COREML_ALLOW_FALLBACK)
|
2023-04-29 07:55:24 +00:00
|
|
|
endif()
|
2022-10-18 15:51:59 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2023-04-30 09:14:33 +00:00
|
|
|
if (WHISPER_OPENBLAS)
|
2023-05-20 18:23:45 +00:00
|
|
|
set(WHISPER_BLAS_VENDOR "OpenBLAS")
|
|
|
|
set(WHISPER_BLAS ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (WHISPER_BLAS)
|
2023-07-25 16:15:08 +00:00
|
|
|
if (WIN32)
|
|
|
|
if(DEFINED ENV{OPENBLAS_PATH})
|
|
|
|
set(BLAS_LIBRARIES $ENV{OPENBLAS_PATH}/lib/libopenblas.dll.a)
|
|
|
|
message(STATUS "Libraries ${BLAS_LIBRARIES}")
|
|
|
|
set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DGGML_USE_OPENBLAS)
|
|
|
|
include_directories($ENV{OPENBLAS_PATH}/include)
|
|
|
|
set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} ${BLAS_LIBRARIES})
|
|
|
|
else ()
|
|
|
|
message(WARNING "BLAS library was not found. Environment variable OPENBLAS_PATH not defined.")
|
|
|
|
endif ()
|
|
|
|
else ()
|
|
|
|
set(BLA_STATIC 1)
|
|
|
|
set(BLA_VENDOR ${WHISPER_BLAS_VENDOR})
|
|
|
|
# set(BLA_PREFER_PKGCONFIG 1)
|
|
|
|
set(BLA_SIZEOF_INTEGER 8)
|
|
|
|
find_package(BLAS)
|
|
|
|
|
|
|
|
if(BLAS_FOUND)
|
|
|
|
message(STATUS "BLAS compatible library found")
|
|
|
|
message(STATUS "Libraries ${BLAS_LIBRARIES}")
|
2023-08-25 16:26:34 +00:00
|
|
|
find_path(BLAS_INCLUDE_DIRS cblas.h /usr/include/openblas /usr/local/include/openblas $ENV{BLAS_HOME}/include)
|
2023-07-25 16:15:08 +00:00
|
|
|
set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DGGML_USE_OPENBLAS)
|
|
|
|
include_directories(${BLAS_INCLUDE_DIRS})
|
|
|
|
set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} ${BLAS_LIBRARIES})
|
|
|
|
else()
|
|
|
|
message(WARNING "BLAS library was not found")
|
|
|
|
endif()
|
|
|
|
endif ()
|
2023-05-20 18:23:45 +00:00
|
|
|
endif ()
|
2022-10-27 15:31:49 +00:00
|
|
|
|
2023-04-30 09:14:33 +00:00
|
|
|
if (WHISPER_CUBLAS)
|
|
|
|
cmake_minimum_required(VERSION 3.17)
|
|
|
|
|
|
|
|
find_package(CUDAToolkit)
|
|
|
|
|
|
|
|
if (CUDAToolkit_FOUND)
|
|
|
|
message(STATUS "cuBLAS found")
|
|
|
|
|
|
|
|
enable_language(CUDA)
|
|
|
|
|
|
|
|
set(GGML_CUDA_SOURCES ggml-cuda.cu ggml-cuda.h)
|
|
|
|
|
|
|
|
add_compile_definitions(GGML_USE_CUBLAS)
|
|
|
|
|
|
|
|
if (WHISPER_STATIC)
|
|
|
|
set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} CUDA::cudart_static CUDA::cublas_static CUDA::cublasLt_static)
|
|
|
|
else()
|
|
|
|
set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} CUDA::cudart CUDA::cublas CUDA::cublasLt)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
else()
|
|
|
|
message(WARNING "cuBLAS not found")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2023-08-27 17:03:58 +00:00
|
|
|
|
|
|
|
if (WHISPER_HIPBLAS)
|
|
|
|
list(APPEND CMAKE_PREFIX_PATH /opt/rocm)
|
|
|
|
if (NOT ${CMAKE_C_COMPILER_ID} MATCHES "Clang")
|
|
|
|
message(WARNING "Only LLVM is supported for HIP, hint: CC=/opt/rocm/llvm/bin/clang")
|
|
|
|
endif()
|
|
|
|
if (NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
|
|
|
message(WARNING "Only LLVM is supported for HIP, hint: CXX=/opt/rocm/llvm/bin/clang++")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_package(hip)
|
|
|
|
find_package(hipblas)
|
|
|
|
find_package(rocblas)
|
|
|
|
|
|
|
|
if (${hipblas_FOUND} AND ${hip_FOUND})
|
|
|
|
message(STATUS "HIP and hipBLAS found")
|
|
|
|
add_compile_definitions(GGML_USE_HIPBLAS GGML_USE_CUBLAS)
|
|
|
|
add_library(ggml-rocm OBJECT ggml-cuda.cu ggml-cuda.h)
|
|
|
|
set_property(TARGET ggml-rocm PROPERTY POSITION_INDEPENDENT_CODE ON)
|
|
|
|
set_source_files_properties(ggml-cuda.cu PROPERTIES LANGUAGE CXX)
|
|
|
|
target_link_libraries(ggml-rocm PRIVATE hip::device PUBLIC hip::host roc::rocblas roc::hipblas)
|
|
|
|
|
|
|
|
if (WHISPER_STATIC)
|
|
|
|
message(FATAL_ERROR "Static linking not supported for HIP/ROCm")
|
|
|
|
endif()
|
|
|
|
set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} ggml-rocm)
|
|
|
|
else()
|
|
|
|
message(WARNING "hipBLAS or HIP not found. Try setting CMAKE_PREFIX_PATH=/opt/rocm")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2023-05-02 19:50:32 +00:00
|
|
|
if (WHISPER_CLBLAST)
|
|
|
|
find_package(CLBlast)
|
|
|
|
if (CLBlast_FOUND)
|
|
|
|
message(STATUS "CLBlast found")
|
|
|
|
|
2023-06-25 12:38:12 +00:00
|
|
|
set(GGML_OPENCL_SOURCES ggml-opencl.cpp ggml-opencl.h)
|
2023-05-02 19:50:32 +00:00
|
|
|
|
|
|
|
add_compile_definitions(GGML_USE_CLBLAST)
|
|
|
|
|
|
|
|
set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} clblast)
|
|
|
|
else()
|
|
|
|
message(WARNING "CLBlast not found")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2023-07-04 12:56:11 +00:00
|
|
|
if( WHISPER_OPENVINO )
|
|
|
|
find_package(OpenVINO REQUIRED COMPONENTS Runtime)
|
|
|
|
endif()
|
|
|
|
|
2022-10-08 06:00:59 +00:00
|
|
|
# compiler flags
|
2022-10-07 20:53:12 +00:00
|
|
|
|
|
|
|
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
|
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (WHISPER_ALL_WARNINGS)
|
2022-10-11 17:57:52 +00:00
|
|
|
if (NOT MSVC)
|
2022-10-07 20:53:12 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
|
|
|
|
-Wall \
|
|
|
|
-Wextra \
|
|
|
|
-Wpedantic \
|
|
|
|
-Wshadow \
|
|
|
|
-Wcast-qual \
|
|
|
|
-Wstrict-prototypes \
|
|
|
|
-Wpointer-arith \
|
2023-01-07 18:18:34 +00:00
|
|
|
-Wno-unused-function \
|
2022-10-07 20:53:12 +00:00
|
|
|
")
|
2022-12-19 18:45:08 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
|
|
|
|
-Wall \
|
|
|
|
-Wextra \
|
|
|
|
-Wpedantic \
|
|
|
|
-Wcast-qual \
|
|
|
|
")
|
2022-10-07 20:53:12 +00:00
|
|
|
else()
|
2022-10-11 17:57:52 +00:00
|
|
|
# todo : msvc
|
2022-10-07 20:53:12 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2022-10-11 17:57:52 +00:00
|
|
|
if (NOT MSVC)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=vla")
|
|
|
|
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-math-errno -ffinite-math-only -funsafe-math-optimizations")
|
|
|
|
endif()
|
2022-10-07 20:53:12 +00:00
|
|
|
|
|
|
|
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
|
|
|
|
|
|
|
|
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
|
|
|
|
message(STATUS "ARM detected")
|
2023-08-25 12:19:48 +00:00
|
|
|
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64le")
|
|
|
|
message(STATUS "PowerPC detected")
|
2022-10-07 20:53:12 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "x86 detected")
|
2022-10-11 17:57:52 +00:00
|
|
|
if (MSVC)
|
2023-07-26 15:57:25 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /utf-8")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8")
|
|
|
|
if(NOT WHISPER_NO_AVX2)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:AVX2")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX2")
|
|
|
|
else()
|
|
|
|
if(NOT WHISPER_NO_AVX)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:AVX")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:AVX")
|
2023-05-08 17:45:53 +00:00
|
|
|
endif()
|
2023-07-26 15:57:25 +00:00
|
|
|
endif()
|
2022-10-11 17:57:52 +00:00
|
|
|
else()
|
2022-10-22 10:45:43 +00:00
|
|
|
if (EMSCRIPTEN)
|
2022-12-12 18:17:27 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
|
2022-10-22 10:45:43 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
|
|
|
else()
|
2023-08-19 18:39:03 +00:00
|
|
|
if(NOT WHISPER_NO_AVX)
|
2022-11-11 16:10:01 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx")
|
|
|
|
endif()
|
2023-08-19 18:39:03 +00:00
|
|
|
if(NOT WHISPER_NO_AVX2)
|
2022-11-11 16:10:01 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2")
|
|
|
|
endif()
|
2023-08-19 18:39:03 +00:00
|
|
|
if(NOT WHISPER_NO_FMA)
|
2023-01-06 17:32:28 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma")
|
|
|
|
endif()
|
2023-08-19 18:39:03 +00:00
|
|
|
if(NOT WHISPER_NO_F16C)
|
2023-03-22 20:30:40 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mf16c")
|
|
|
|
endif()
|
2022-10-22 10:45:43 +00:00
|
|
|
endif()
|
2022-10-11 17:57:52 +00:00
|
|
|
endif()
|
2022-10-07 20:53:12 +00:00
|
|
|
endif()
|
|
|
|
|
2023-09-07 09:36:14 +00:00
|
|
|
# clock_gettime came in POSIX.1b (1993)
|
|
|
|
# CLOCK_MONOTONIC came in POSIX.1-2001 / SUSv3 as optional
|
|
|
|
# posix_memalign came in POSIX.1-2001 / SUSv3
|
|
|
|
# M_PI is an XSI extension since POSIX.1-2001 / SUSv3, came in XPG1 (1985)
|
|
|
|
add_compile_definitions(_XOPEN_SOURCE=600)
|
|
|
|
|
|
|
|
# Somehow in OpenBSD whenever POSIX conformance is specified
|
|
|
|
# some string functions rely on locale_t availability,
|
|
|
|
# which was introduced in POSIX.1-2008, forcing us to go higher
|
2023-09-08 11:50:03 +00:00
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
2023-09-07 09:36:14 +00:00
|
|
|
remove_definitions(-D_XOPEN_SOURCE=600)
|
|
|
|
add_compile_definitions(_XOPEN_SOURCE=700)
|
2023-09-08 11:50:03 +00:00
|
|
|
endif()
|
2023-09-07 09:36:14 +00:00
|
|
|
|
|
|
|
# Data types, macros and functions related to controlling CPU affinity
|
|
|
|
# are available on Linux through GNU extensions in libc
|
2023-09-08 11:50:03 +00:00
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
2023-09-07 09:36:14 +00:00
|
|
|
add_compile_definitions(_GNU_SOURCE)
|
2023-09-08 11:50:03 +00:00
|
|
|
endif()
|
2023-09-07 09:36:14 +00:00
|
|
|
|
|
|
|
# RLIMIT_MEMLOCK came in BSD, is not specified in POSIX.1,
|
|
|
|
# and on macOS its availability depends on enabling Darwin extensions
|
|
|
|
# similarly on DragonFly, enabling BSD extensions is necessary
|
2023-09-08 11:50:03 +00:00
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
2023-09-07 09:36:14 +00:00
|
|
|
add_compile_definitions(_DARWIN_C_SOURCE)
|
2023-09-08 11:50:03 +00:00
|
|
|
endif()
|
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "DragonFly")
|
2023-09-07 09:36:14 +00:00
|
|
|
add_compile_definitions(_DARWIN_C_SOURCE)
|
2023-09-08 11:50:03 +00:00
|
|
|
endif()
|
2023-09-07 09:36:14 +00:00
|
|
|
|
|
|
|
# alloca is a non-standard interface that is not visible on BSDs when
|
|
|
|
# POSIX conformance is specified, but not all of them provide a clean way
|
|
|
|
# to enable it in such cases
|
2023-09-08 11:50:03 +00:00
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
2023-09-07 09:36:14 +00:00
|
|
|
add_compile_definitions(__BSD_VISIBLE)
|
2023-09-08 11:50:03 +00:00
|
|
|
endif()
|
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
|
2023-09-07 09:36:14 +00:00
|
|
|
add_compile_definitions(_NETBSD_SOURCE)
|
2023-09-08 11:50:03 +00:00
|
|
|
endif()
|
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
|
2023-09-07 09:36:14 +00:00
|
|
|
add_compile_definitions(_BSD_SOURCE)
|
2023-09-08 11:50:03 +00:00
|
|
|
endif()
|
2023-09-07 09:36:14 +00:00
|
|
|
|
2022-11-03 18:18:57 +00:00
|
|
|
if (WHISPER_PERF)
|
|
|
|
set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DGGML_PERF)
|
|
|
|
endif()
|
|
|
|
|
2023-04-15 10:21:27 +00:00
|
|
|
#
|
|
|
|
# whisper.coreml - Core ML support
|
|
|
|
#
|
|
|
|
|
|
|
|
if (WHISPER_COREML)
|
|
|
|
set(TARGET whisper.coreml)
|
|
|
|
|
|
|
|
add_library(${TARGET}
|
|
|
|
coreml/whisper-encoder.h
|
|
|
|
coreml/whisper-encoder.mm
|
|
|
|
coreml/whisper-encoder-impl.h
|
|
|
|
coreml/whisper-encoder-impl.m
|
|
|
|
)
|
|
|
|
|
|
|
|
include(DefaultTargetOptions)
|
|
|
|
|
|
|
|
target_include_directories(${TARGET} PUBLIC
|
|
|
|
.
|
|
|
|
)
|
|
|
|
|
|
|
|
target_link_libraries(${TARGET} PRIVATE ${FOUNDATION_FRAMEWORK} ${COREML_FRAMEWORK})
|
|
|
|
|
|
|
|
set_target_properties(${TARGET} PROPERTIES
|
|
|
|
COMPILE_FLAGS "-fobjc-arc"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2023-07-04 12:56:11 +00:00
|
|
|
if (WHISPER_OPENVINO)
|
|
|
|
set(TARGET whisper.openvino)
|
|
|
|
|
|
|
|
add_library(${TARGET} OBJECT
|
|
|
|
openvino/whisper-openvino-encoder.h
|
|
|
|
openvino/whisper-openvino-encoder.cpp
|
|
|
|
)
|
|
|
|
|
|
|
|
target_include_directories(${TARGET} PUBLIC
|
|
|
|
.
|
|
|
|
)
|
|
|
|
|
|
|
|
set_property(TARGET ${TARGET} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
|
|
|
set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DWHISPER_USE_OPENVINO)
|
|
|
|
|
|
|
|
target_link_libraries(${TARGET} PRIVATE openvino::runtime)
|
|
|
|
endif()
|
|
|
|
|
2022-10-25 16:13:08 +00:00
|
|
|
#
|
2022-10-08 06:00:59 +00:00
|
|
|
# whisper - this is the main library of the project
|
2022-10-25 16:13:08 +00:00
|
|
|
#
|
2022-10-07 20:53:12 +00:00
|
|
|
|
|
|
|
set(TARGET whisper)
|
|
|
|
|
2022-10-08 06:00:59 +00:00
|
|
|
add_library(${TARGET}
|
2022-12-22 14:34:47 +00:00
|
|
|
ggml.h
|
2022-10-07 21:21:16 +00:00
|
|
|
ggml.c
|
2023-04-30 09:14:33 +00:00
|
|
|
${GGML_CUDA_SOURCES}
|
2023-05-02 19:50:32 +00:00
|
|
|
${GGML_OPENCL_SOURCES}
|
2022-12-22 14:34:47 +00:00
|
|
|
whisper.h
|
2022-10-07 20:53:12 +00:00
|
|
|
whisper.cpp
|
|
|
|
)
|
|
|
|
|
2023-01-05 19:22:48 +00:00
|
|
|
include(DefaultTargetOptions)
|
|
|
|
|
2022-10-07 20:53:12 +00:00
|
|
|
target_include_directories(${TARGET} PUBLIC
|
|
|
|
.
|
|
|
|
)
|
|
|
|
|
2023-04-15 10:21:27 +00:00
|
|
|
if (WHISPER_COREML)
|
|
|
|
target_link_libraries(${TARGET} PRIVATE whisper.coreml)
|
|
|
|
endif()
|
|
|
|
|
2023-07-04 12:56:11 +00:00
|
|
|
if (WHISPER_OPENVINO)
|
|
|
|
target_link_libraries(${TARGET} PRIVATE whisper.openvino)
|
|
|
|
endif()
|
|
|
|
|
2022-10-27 09:59:02 +00:00
|
|
|
if (MSVC)
|
2022-10-29 16:41:50 +00:00
|
|
|
target_link_libraries(${TARGET} PRIVATE ${WHISPER_EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
|
|
|
|
|
|
|
set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -D_CRT_SECURE_NO_WARNINGS)
|
2022-10-27 09:59:02 +00:00
|
|
|
else()
|
2022-10-29 16:41:50 +00:00
|
|
|
target_link_libraries(${TARGET} PRIVATE m ${WHISPER_EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
2022-10-27 09:59:02 +00:00
|
|
|
endif()
|
2022-10-07 20:53:12 +00:00
|
|
|
|
|
|
|
if (BUILD_SHARED_LIBS)
|
|
|
|
target_link_libraries(${TARGET} PUBLIC
|
|
|
|
${CMAKE_DL_LIBS}
|
|
|
|
)
|
|
|
|
|
|
|
|
target_compile_definitions(${TARGET} PUBLIC
|
|
|
|
WHISPER_SHARED
|
2023-04-30 15:51:57 +00:00
|
|
|
GGML_SHARED
|
|
|
|
)
|
|
|
|
|
|
|
|
target_compile_definitions(${TARGET} PRIVATE
|
|
|
|
WHISPER_BUILD
|
|
|
|
GGML_BUILD
|
2022-10-07 20:53:12 +00:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2023-04-30 09:14:33 +00:00
|
|
|
if (GGML_CUDA_SOURCES)
|
|
|
|
message(STATUS "GGML CUDA sources found, configuring CUDA architecture")
|
|
|
|
set_property(TARGET whisper PROPERTY CUDA_ARCHITECTURES OFF)
|
|
|
|
set_property(TARGET whisper PROPERTY CUDA_SELECT_NVCC_ARCH_FLAGS "Auto")
|
|
|
|
endif()
|
|
|
|
|
2022-12-12 18:17:27 +00:00
|
|
|
if (EMSCRIPTEN)
|
|
|
|
set_target_properties(${TARGET} PROPERTIES COMPILE_FLAGS "-msimd128")
|
|
|
|
endif()
|
|
|
|
|
2022-10-07 20:53:12 +00:00
|
|
|
target_compile_definitions(${TARGET} PUBLIC
|
|
|
|
${WHISPER_EXTRA_FLAGS}
|
|
|
|
)
|
|
|
|
|
2023-02-11 07:13:32 +00:00
|
|
|
set_target_properties(${TARGET} PROPERTIES PUBLIC_HEADER "whisper.h")
|
|
|
|
|
2022-10-07 20:53:12 +00:00
|
|
|
install(TARGETS ${TARGET}
|
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
ARCHIVE DESTINATION lib/static
|
2022-12-31 07:48:00 +00:00
|
|
|
RUNTIME DESTINATION bin
|
2023-02-11 07:13:32 +00:00
|
|
|
PUBLIC_HEADER DESTINATION include
|
2022-10-07 20:53:12 +00:00
|
|
|
)
|
|
|
|
|
2022-10-25 16:13:08 +00:00
|
|
|
#
|
2022-10-22 10:07:59 +00:00
|
|
|
# bindings
|
2022-10-25 16:13:08 +00:00
|
|
|
#
|
2022-10-22 10:07:59 +00:00
|
|
|
|
|
|
|
add_subdirectory(bindings)
|
|
|
|
|
2022-10-25 16:13:08 +00:00
|
|
|
#
|
2022-10-08 06:00:59 +00:00
|
|
|
# programs, examples and tests
|
2022-10-25 16:13:08 +00:00
|
|
|
#
|
2022-10-08 06:00:59 +00:00
|
|
|
|
2023-02-05 13:02:08 +00:00
|
|
|
if (WHISPER_BUILD_TESTS AND NOT CMAKE_JS_VERSION)
|
2022-12-12 18:17:27 +00:00
|
|
|
enable_testing()
|
|
|
|
add_subdirectory(tests)
|
2022-10-07 20:53:12 +00:00
|
|
|
endif ()
|
2022-12-12 18:17:27 +00:00
|
|
|
|
|
|
|
if (WHISPER_BUILD_EXAMPLES)
|
|
|
|
add_subdirectory(examples)
|
|
|
|
endif()
|