miTTenS/CMakeLists.txt
2024-10-06 23:39:04 -04:00

173 lines
4.6 KiB
CMake

cmake_minimum_required(VERSION 3.13)
project(miTTenS C CXX)
file(READ "${CMAKE_CURRENT_LIST_DIR}/VERSION" piper_version)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
file(GLOB_RECURSE SOURCES "src/cpp/*.c*")
file(GLOB_RECURSE HEADERS "src/cpp/include/*.h*")
add_executable(miTTenS ${SOURCES} ${HEADERS})
find_package(SQLite3 REQUIRED)
# NOTE: external project prefix are shortened because of path length restrictions on Windows
# NOTE: onnxruntime is pulled from piper-phonemize
# ---- fmt ---
if(NOT DEFINED FMT_DIR)
set(FMT_VERSION "10.0.0")
set(FMT_DIR "${CMAKE_CURRENT_BINARY_DIR}/deps/fi")
include(ExternalProject)
ExternalProject_Add(
fmt_external
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/deps/f"
URL "https://github.com/fmtlib/fmt/archive/refs/tags/${FMT_VERSION}.zip"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${FMT_DIR}
CMAKE_ARGS -DFMT_TEST:BOOL=OFF # Don't build all the tests
)
add_dependencies(miTTenS fmt_external)
endif()
# ---- spdlog ---
if(NOT DEFINED SPDLOG_DIR)
set(SPDLOG_DIR "${CMAKE_CURRENT_BINARY_DIR}/deps/si")
set(SPDLOG_VERSION "1.12.0")
ExternalProject_Add(
spdlog_external
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/deps/s"
URL "https://github.com/gabime/spdlog/archive/refs/tags/v${SPDLOG_VERSION}.zip"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${SPDLOG_DIR}
)
add_dependencies(miTTenS spdlog_external)
endif()
# ---- piper-phonemize ---
if(NOT DEFINED PIPER_PHONEMIZE_DIR)
set(PIPER_PHONEMIZE_DIR "${CMAKE_CURRENT_BINARY_DIR}/deps/pi")
ExternalProject_Add(
piper_phonemize_external
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/deps/p"
URL "https://github.com/rhasspy/piper-phonemize/archive/refs/heads/master.zip"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${PIPER_PHONEMIZE_DIR}
)
add_dependencies(miTTenS piper_phonemize_external)
endif()
add_custom_target(helper ALL
COMMAND "./helper.sh"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Building zipfs in the specified directory"
)
add_dependencies(miTTenS helper)
set(OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/gitdeps/zipfs/build/libzipfs-ld.a")
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND nim c -d:useMalloc --mm:arc -d:debug --maxLoopIterationsVM:20000000 --app:staticlib --o:${OUTPUT_FILE} nim/main
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gitdeps/zipfs/
COMMENT "Building zipfs static library using Nim"
)
add_custom_target(
zipfs ALL
DEPENDS ${OUTPUT_FILE}
)
add_dependencies(miTTenS zipfs)
target_include_directories(miTTenS PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/gitdeps/zipfs/build/
${FMT_DIR}/include
${SPDLOG_DIR}/include
${PIPER_PHONEMIZE_DIR}/include
)
target_link_directories(miTTenS PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/gitdeps/zipfs/build/
${FMT_DIR}/lib
${SPDLOG_DIR}/lib
${PIPER_PHONEMIZE_DIR}/lib
)
target_link_options(miTTenS PUBLIC
-Wl,--no-undefined -u zipfs_language_detector
)
target_link_libraries(miTTenS
-Wl,--start-group
:libzipfs-ld.a
fmt
spdlog
espeak-ng
piper_phonemize
onnxruntime
sqlite3
sfml-audio
sfml-system
-Wl,--end-group
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/deps/miTTenSControlPanel
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/deps/miTTenSKeyboardDaemon
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/src/nim/Controller/keybinds.kbnd
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
target_compile_definitions(miTTenS PUBLIC _PIPER_VERSION=${piper_version})
# ---- Declare install targets ----
install(
TARGETS miTTenS
DESTINATION ${CMAKE_INSTALL_PREFIX})
# Dependencies
install(
DIRECTORY ${PIPER_PHONEMIZE_DIR}/bin/
DESTINATION ${CMAKE_INSTALL_PREFIX}
USE_SOURCE_PERMISSIONS # keep +x
FILES_MATCHING
PATTERN "piper_phonemize"
PATTERN "espeak-ng"
PATTERN "*.dll"
)
install(
DIRECTORY ${PIPER_PHONEMIZE_DIR}/lib/
DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING
PATTERN "*.dll"
PATTERN "*.so*"
)
install(
DIRECTORY ${PIPER_PHONEMIZE_DIR}/share/espeak-ng-data
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/shared/config.ini DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/nim/ControlPannel/page.html DESTINATION ${CMAKE_INSTALL_PREFIX})
target_compile_options(miTTenS PUBLIC
-pedantic
-Wall
-Wextra
)