Files
voice-cat/core/CMakeLists.txt
Talon 575e2907d0
Some checks failed
Build Linux Binaries / linux/amd64 (push) Has been cancelled
Build Linux Binaries / linux/arm64 (push) Has been cancelled
Cleanup root cmakelists
2026-07-03 15:59:12 +01:00

127 lines
5.8 KiB
CMake

# libvoicecat — the shared C++ core
# Sources are globbed so adding a stub under src/<subsystem>/ needs no CMake edit.
file(GLOB_RECURSE VOICECAT_SOURCES CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
if(VOICECAT_BUILD_SHARED)
add_library(voicecat SHARED ${VOICECAT_SOURCES})
if(WIN32 AND MINGW)
# The C# client only ships voicecat.dll itself, no MinGW runtime DLLs alongside
# it. x64-mingw-static only statically links vcpkg's OWN library deps (protobuf,
# sodium, mbedTLS, ...); the GCC/MinGW runtime stays dynamic by default
# (libgcc_s_seh-1.dll/libwinpthread-1.dll/libstdc++-6.dll — confirmed via `objdump -p`
# on the existing vccli.exe). These flags are the standard fully-static-MinGW
# recipe. Verify after building (see clients/windows/README.md):
# objdump -p build/windows-client/bin/voicecat.dll | grep "DLL Name"
# should show only Windows system DLLs.
target_link_options(voicecat PRIVATE
-static-libgcc -static-libstdc++ -static -lwinpthread)
endif()
if(WIN32)
# CMake's default SHARED naming on MinGW adds a "lib" prefix (libvoicecat.dll) —
# drop it so the output is exactly voicecat.dll, matching the C ABI/library name the
# C# [LibraryImport] surface and docs use everywhere else.
set_target_properties(voicecat PROPERTIES PREFIX "")
endif()
else()
add_library(voicecat STATIC ${VOICECAT_SOURCES})
# Static consumers must see VC_API as empty (no dllimport).
target_compile_definitions(voicecat PUBLIC VOICECAT_STATIC)
endif()
add_library(voicecat::voicecat ALIAS voicecat)
target_include_directories(voicecat
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_compile_definitions(voicecat PRIVATE VOICECAT_BUILDING)
target_compile_features(voicecat PUBLIC cxx_std_20)
set_target_properties(voicecat PROPERTIES
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON)
find_package(protobuf CONFIG REQUIRED)
find_package(unofficial-sodium CONFIG REQUIRED)
find_package(MbedTLS CONFIG REQUIRED)
find_package(asio CONFIG REQUIRED)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(Opus CONFIG REQUIRED)
# miniaudio is header-only; vcpkg does not install a CMake config for it.
find_path(MINIAUDIO_INCLUDE_DIR "miniaudio.h" REQUIRED)
# Generate C++ from voicecat.proto into the build tree.
protobuf_generate(
TARGET voicecat
PROTOS proto/voicecat.proto
LANGUAGE cpp
IMPORT_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/proto
PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated/proto)
# Generated .pb.h files are included by protocol/envelope.h (consumed by tests and server),
# so the generated dir and protobuf itself must be PUBLIC.
target_include_directories(voicecat PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/generated)
target_link_libraries(voicecat
PUBLIC protobuf::libprotobuf
PRIVATE unofficial-sodium::sodium
MbedTLS::mbedtls MbedTLS::mbedcrypto MbedTLS::mbedx509
asio::asio unofficial::sqlite3::sqlite3 spdlog::spdlog
Opus::opus)
target_include_directories(voicecat PRIVATE ${MINIAUDIO_INCLUDE_DIR})
target_compile_definitions(voicecat PUBLIC VOICECAT_HAS_OPUS VOICECAT_HAS_AUDIO)
# ── RNNoise vendored noise-suppression DSP (third_party/rnnoise, BSD-3 + CC0). ──────────
# The real backend behind ApmProcessor . Built as a standalone C
# static lib with NO run-time CPU dispatch (RTCD off): portable scalar path on x86,
# auto-NEON on arm64. -DDISABLE_DEBUG_FLOAT selects the int8-quantized weights that match our
# shrunk model (third_party/README.md). The vcpkg port is !windows !arm, so we vendor it.
set(RNNOISE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/rnnoise)
add_library(rnnoise STATIC
${RNNOISE_DIR}/src/denoise.c
${RNNOISE_DIR}/src/rnn.c
${RNNOISE_DIR}/src/pitch.c
${RNNOISE_DIR}/src/kiss_fft.c
${RNNOISE_DIR}/src/celt_lpc.c
${RNNOISE_DIR}/src/nnet.c
${RNNOISE_DIR}/src/nnet_default.c
${RNNOISE_DIR}/src/parse_lpcnet_weights.c
${RNNOISE_DIR}/src/rnnoise_data.c
${RNNOISE_DIR}/src/rnnoise_tables.c)
target_include_directories(rnnoise
PUBLIC ${RNNOISE_DIR}/include
PRIVATE ${RNNOISE_DIR}/src)
target_compile_definitions(rnnoise PRIVATE DISABLE_DEBUG_FLOAT)
set_target_properties(rnnoise PROPERTIES
POSITION_INDEPENDENT_CODE ON # libvoicecat may be built SHARED (windows-client/apple)
C_VISIBILITY_PRESET hidden)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
# rnnoise is plain C; keep it compiling as C even though audio_engine.cpp is OBJCXX.
set_source_files_properties(${RNNOISE_DIR}/src/rnnoise_data.c PROPERTIES LANGUAGE C)
endif()
target_link_libraries(voicecat PRIVATE rnnoise)
target_compile_definitions(voicecat PRIVATE VOICECAT_HAS_NS)
# On iOS, miniaudio's AVFoundation backend includes Objective-C headers (AVFoundation.h
# Foundation.h). Compiling those as plain C++ fails; setting LANGUAGE OBJCXX for
# audio_engine.cpp (the only file that includes miniaudio.h directly) fixes this.
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/src/audio/audio_engine.cpp
PROPERTIES LANGUAGE OBJCXX
)
endif()
if(WIN32)
# AcceptEx / GetAcceptExSockaddrs live in mswsock; ws2_32 covers the base Winsock API.
target_link_libraries(voicecat PRIVATE ws2_32 mswsock)
target_compile_definitions(voicecat PUBLIC VOICECAT_HAS_LOOPBACK)
endif()
target_compile_definitions(voicecat PUBLIC VOICECAT_HAS_NET)