123 lines
3.6 KiB
CMake
123 lines
3.6 KiB
CMake
cmake_minimum_required(VERSION 3.5)
|
|
project(win-dictation C CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
# Path to modules
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
|
|
# Set output directory
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
|
|
|
# Options
|
|
option(BUILD_SHARED_LIBS "build shared libraries" OFF)
|
|
option(WHISPER_SDL2 "whisper: support for libSDL2" ON)
|
|
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)
|
|
|
|
# SDL2
|
|
if(NOT SDL2_DIR)
|
|
set(SDL2_DIR "${CMAKE_CURRENT_SOURCE_DIR}/SDL2-mingw/cmake")
|
|
endif()
|
|
find_package(SDL2 REQUIRED)
|
|
string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
|
|
include_directories(${SDL2_INCLUDE_DIRS})
|
|
|
|
# GGML
|
|
add_subdirectory(ggml)
|
|
|
|
# Whisper
|
|
# We need to handle include paths for whisper.
|
|
# whisper/src/CMakeLists.txt expects ../include/whisper.h
|
|
add_subdirectory(whisper/src)
|
|
|
|
# Common Library (needed by win-dictation) - optional if files don't exist
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/common/common.h")
|
|
set(COMMON_TARGET common)
|
|
add_library(${COMMON_TARGET} STATIC
|
|
common/common.h
|
|
common/common.cpp
|
|
common/common-ggml.h
|
|
common/common-ggml.cpp
|
|
common/common-whisper.h
|
|
common/common-whisper.cpp
|
|
common/grammar-parser.h
|
|
common/grammar-parser.cpp
|
|
)
|
|
target_include_directories(${COMMON_TARGET} PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/common
|
|
${CMAKE_CURRENT_SOURCE_DIR}/whisper/include
|
|
${CMAKE_CURRENT_SOURCE_DIR}/ggml/include
|
|
)
|
|
target_link_libraries(${COMMON_TARGET} PRIVATE whisper)
|
|
|
|
set(COMMON_SDL_TARGET common-sdl)
|
|
add_library(${COMMON_SDL_TARGET} STATIC
|
|
common/common-sdl.h
|
|
common/common-sdl.cpp
|
|
)
|
|
target_include_directories(${COMMON_SDL_TARGET} PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/common
|
|
${SDL2_INCLUDE_DIRS}
|
|
)
|
|
target_link_libraries(${COMMON_SDL_TARGET} PRIVATE ${SDL2_LIBRARIES})
|
|
else()
|
|
# Create empty common libraries if files don't exist
|
|
add_library(common INTERFACE)
|
|
add_library(common-sdl INTERFACE)
|
|
target_include_directories(common INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/whisper/include)
|
|
target_include_directories(common-sdl INTERFACE ${SDL2_INCLUDE_DIRS})
|
|
endif()
|
|
|
|
# Win Dictation Executable
|
|
add_executable(win-dictation WIN32
|
|
src/main.cpp
|
|
src/transcriber.cpp
|
|
src/transcriber.h
|
|
src/win-dictation.rc
|
|
)
|
|
|
|
target_link_libraries(win-dictation PRIVATE
|
|
whisper
|
|
${SDL2_LIBRARIES}
|
|
comctl32
|
|
dwmapi
|
|
)
|
|
|
|
target_include_directories(win-dictation PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
${CMAKE_CURRENT_SOURCE_DIR}/common
|
|
${CMAKE_CURRENT_SOURCE_DIR}/whisper/include
|
|
${CMAKE_CURRENT_SOURCE_DIR}/ggml/include
|
|
${SDL2_INCLUDE_DIR}
|
|
)
|
|
|
|
target_compile_definitions(win-dictation PRIVATE UNICODE _UNICODE)
|
|
|
|
if(MSVC)
|
|
target_compile_options(win-dictation PRIVATE
|
|
$<$<CONFIG:Release>:/O2 /GL>
|
|
)
|
|
target_link_options(win-dictation PRIVATE
|
|
$<$<CONFIG:Release>:/LTCG>
|
|
)
|
|
endif()
|
|
|
|
# Copy SDL2.dll to output directory
|
|
add_custom_command(TARGET win-dictation POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/release/WinDictation/SDL2.dll"
|
|
$<TARGET_FILE_DIR:win-dictation>
|
|
)
|
|
|
|
# Copy models directory to output
|
|
add_custom_command(TARGET win-dictation POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:win-dictation>/models
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/models"
|
|
$<TARGET_FILE_DIR:win-dictation>/models
|
|
)
|