Files
ports/audio/piper/files/patch-libpiper_CMakeLists.txt
T
2026-10-04 04:07:15 +00:00

199 lines
7.1 KiB
Plaintext

--- libpiper/CMakeLists.txt.orig 2026-09-04 16:40:50 UTC
+++ libpiper/CMakeLists.txt 2026-09-04 16:40:50 UTC
@@ -5,138 +5,15 @@
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
-include(ExternalProject)
+# ---- espeak-ng (system) ----
-# Install location for espeak-ng
-set(ESPEAKNG_BUILD_DIR ${CMAKE_BINARY_DIR}/espeak_ng)
-set(ESPEAKNG_INSTALL_DIR ${CMAKE_BINARY_DIR}/espeak_ng-install)
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(ESPEAKNG REQUIRED IMPORTED_TARGET espeak-ng)
-# ucd-tools is built (not installed) by espeak-ng, so we reference its static
-# library directly from the build tree. Multi-config generators (e.g. Visual
-# Studio) place the output in a per-config subdirectory whose name is only
-# known at build time, so resolve it with a $<CONFIG> generator expression.
-# Single-config generators (Unix Makefiles, Ninja) write directly into the
-# build directory with no subdirectory.
-get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
-if(IS_MULTI_CONFIG)
- set(UCD_CONFIG_SUBDIR "$<CONFIG>/")
-else()
- set(UCD_CONFIG_SUBDIR "")
-endif()
+# ---- onnxruntime (system) ----
-set(UCD_TOOLS_DIR ${ESPEAKNG_BUILD_DIR}/src/espeak_ng_external-build/src/ucd-tools)
+find_package(onnxruntime REQUIRED)
-if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
- # MSVC emits .lib files (espeak-ng is re-exported from piper.dll)
- set(ESPEAKNG_STATIC_LIB ${ESPEAKNG_INSTALL_DIR}/lib/espeak-ng.lib)
- set(UCD_STATIC_LIB ${UCD_TOOLS_DIR}/${UCD_CONFIG_SUBDIR}ucd.lib)
-else()
- set(ESPEAKNG_STATIC_LIB ${ESPEAKNG_INSTALL_DIR}/lib/libespeak-ng.a)
- set(UCD_STATIC_LIB ${UCD_TOOLS_DIR}/${UCD_CONFIG_SUBDIR}libucd.a)
-endif()
-
-ExternalProject_Add(espeak_ng_external
- GIT_REPOSITORY https://github.com/espeak-ng/espeak-ng.git
- GIT_TAG 212928b394a96e8fd2096616bfd54e17845c48f6 # 2025-Mar-22
- PREFIX ${ESPEAKNG_BUILD_DIR}
- CMAKE_ARGS
- -DCMAKE_INSTALL_PREFIX=${ESPEAKNG_INSTALL_DIR}
- -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
- -DBUILD_SHARED_LIBS:BOOL=OFF
- -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
- -DUSE_ASYNC:BOOL=OFF
- -DUSE_MBROLA:BOOL=OFF
- -DUSE_LIBSONIC:BOOL=OFF
- -DUSE_LIBPCAUDIO:BOOL=OFF
- -DUSE_KLATT:BOOL=OFF
- -DUSE_SPEECHPLAYER:BOOL=OFF
- -DEXTRA_cmn:BOOL=ON
- -DEXTRA_ru:BOOL=ON
- # Need to explicitly add ucd include directory for CI
- "-DCMAKE_C_FLAGS=-D_FILE_OFFSET_BITS=64 -I${ESPEAKNG_BUILD_DIR}/src/espeak_ng_external/src/ucd-tools/src/include"
- "-DCMAKE_CXX_FLAGS=-D_FILE_OFFSET_BITS=64 -I${ESPEAKNG_BUILD_DIR}/src/espeak_ng_external/src/ucd-tools/src/include"
- BUILD_BYPRODUCTS
- ${ESPEAKNG_STATIC_LIB}
- ${UCD_STATIC_LIB}
- UPDATE_DISCONNECTED TRUE
-)
-
-include_directories(
- ${ESPEAKNG_INSTALL_DIR}/include
-)
-
-# ---- onnxruntime ---
-
-find_package(onnxruntime QUIET)
-
-# Look for onnxruntime files in <root>/lib
-if(NOT TARGET onnxruntime::onnxruntime AND NOT DEFINED ONNXRUNTIME_DIR)
- if(NOT DEFINED ONNXRUNTIME_VERSION)
- set(ONNXRUNTIME_VERSION "1.22.0")
- endif()
-
- if(WIN32)
- # Windows x86-64
- set(ONNXRUNTIME_PREFIX "onnxruntime-win-x64-${ONNXRUNTIME_VERSION}")
- set(ONNXRUNTIME_EXT "zip")
- elseif (APPLE)
- if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
- # MacOS x86-64
- set(ONNXRUNTIME_PREFIX "onnxruntime-osx-x86_64-${ONNXRUNTIME_VERSION}")
- elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
- # MacOS Apple Silicon
- set(ONNXRUNTIME_PREFIX "onnxruntime-osx-arm64-${ONNXRUNTIME_VERSION}")
- else()
- message(FATAL_ERROR "Unsupported architecture for onnxruntime")
- endif()
-
- set(ONNXRUNTIME_EXT "tgz")
- else()
- if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
- # Linux x86-64
- set(ONNXRUNTIME_PREFIX "onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}")
- elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
- # Linux ARM 64-bit
- set(ONNXRUNTIME_PREFIX "onnxruntime-linux-aarch64-${ONNXRUNTIME_VERSION}")
- elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)
- # Linux ARM 32-bit
- set(ONNXRUNTIME_PREFIX "onnxruntime-linux-arm32-${ONNXRUNTIME_VERSION}")
- set(ONNXRUNTIME_URL "https://github.com/synesthesiam/prebuilt-apps/releases/download/v1.0/onnxruntime-linux-arm32-${ONNXRUNTIME_VERSION}.tgz")
- else()
- message(FATAL_ERROR "Unsupported architecture for onnxruntime")
- endif()
-
- set(ONNXRUNTIME_EXT "tgz")
- endif()
-
- if(NOT DEFINED ONNXRUNTIME_URL)
- set(ONNXRUNTIME_URL "https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/${ONNXRUNTIME_PREFIX}.${ONNXRUNTIME_EXT}")
- endif()
-
- set(ONNXRUNTIME_FILENAME "${ONNXRUNTIME_PREFIX}.${ONNXRUNTIME_EXT}")
- set(ONNXRUNTIME_DIR "${CMAKE_CURRENT_LIST_DIR}/lib/${ONNXRUNTIME_PREFIX}")
-
- if(NOT EXISTS "${ONNXRUNTIME_DIR}")
- if(NOT EXISTS "download/${ONNXRUNTIME_FILENAME}")
- # Download onnxruntime release
- message("Downloading ${ONNXRUNTIME_URL}")
- file(DOWNLOAD "${ONNXRUNTIME_URL}" "download/${ONNXRUNTIME_FILENAME}")
- endif()
-
- # Extract .zip or .tgz to a directory like lib/onnxruntime-linux-x64-1.22.0/
- file(ARCHIVE_EXTRACT INPUT "download/${ONNXRUNTIME_FILENAME}" DESTINATION "${CMAKE_CURRENT_LIST_DIR}/lib")
- endif()
-endif()
-
-if(DEFINED ONNXRUNTIME_DIR)
- find_library(ONNXRUNTIME_LIB NAMES onnxruntime PATHS ${ONNXRUNTIME_DIR}/lib REQUIRED)
- add_library(onnxruntime::onnxruntime UNKNOWN IMPORTED)
- set_target_properties(onnxruntime::onnxruntime PROPERTIES
- IMPORTED_LOCATION ${ONNXRUNTIME_LIB}
- INTERFACE_INCLUDE_DIRECTORIES ${ONNXRUNTIME_DIR}/include
- )
-endif()
-
# ---- linting ----
include(ClangTidy.cmake)
# ---- libpiper ---
@@ -147,14 +24,11 @@
)
enable_clang_tidy(piper)
-add_dependencies(piper espeak_ng_external)
target_include_directories(piper PUBLIC
- ${ESPEAKNG_INSTALL_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries(piper
- ${ESPEAKNG_STATIC_LIB}
- ${UCD_STATIC_LIB}
+ PkgConfig::ESPEAKNG
onnxruntime::onnxruntime
)
@@ -169,6 +43,11 @@
if(PIPER_VERSION)
message(STATUS "Parsed Piper Version: ${PIPER_VERSION}")
target_compile_definitions(piper PRIVATE PIPER_VERSION="${PIPER_VERSION}")
+
+ string(REGEX MATCH "^([0-9]+)" PIPER_SOVERSION "${PIPER_VERSION}")
+ set_target_properties(piper PROPERTIES
+ VERSION ${PIPER_VERSION}
+ SOVERSION ${PIPER_SOVERSION})
else()
message(WARNING "Could not parse version from setup.py")
endif()
@@ -190,23 +69,6 @@
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
-if(DEFINED ONNXRUNTIME_DIR)
- install(
- DIRECTORY ${ONNXRUNTIME_DIR}/lib/
- DESTINATION ${CMAKE_INSTALL_LIBDIR}
- PATTERN "cmake" EXCLUDE
- PATTERN "pkgconfig" EXCLUDE
- )
-endif()
-
-# Copy espeak-ng-data
-set(ESPEAKNG_DATA_SRC ${CMAKE_BINARY_DIR}/espeak_ng-install/share/espeak-ng-data)
-
-install(
- DIRECTORY ${ESPEAKNG_DATA_SRC}
- DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}
-)
-
# ----------------
# Testing
# ----------------