summarylogtreecommitdiffstats
path: root/phonmize-0002-Link-against-system-onnxruntime.patch
blob: 9b11be0258333d7fddf91e7a49e74a3b725c3293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
From d39a17bb83317047dbc81ce0f73e2730dbf736bd Mon Sep 17 00:00:00 2001
From: memchr <memchr@proton.me>
Date: Mon, 21 Oct 2024 04:25:22 +0000
Subject: [PATCH 2/4] Link against system onnxruntime

---
 CMakeLists.txt | 80 ++++++++------------------------------------------
 1 file changed, 12 insertions(+), 68 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bd809cc..f41b282 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,66 +35,8 @@ set_target_properties(piper_phonemize PROPERTIES
     SOVERSION ${PROJECT_VERSION_MAJOR}
 )
 
-# ---- onnxruntime ---
-
-# Look for onnxruntime files in <root>/lib
-if(NOT DEFINED ONNXRUNTIME_DIR)
-    if(NOT DEFINED ONNXRUNTIME_VERSION)
-        set(ONNXRUNTIME_VERSION "1.14.1")
-    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.14.1/
-        file(ARCHIVE_EXTRACT INPUT "download/${ONNXRUNTIME_FILENAME}" DESTINATION "${CMAKE_CURRENT_LIST_DIR}/lib")
-    endif()
-endif()
+find_package(PkgConfig)
+pkg_check_modules(ONNXRUNTIME REQUIRED libonnxruntime)
 
 # ---- espeak-ng ---
 
@@ -128,13 +70,13 @@ target_include_directories(
     piper_phonemize PUBLIC
     "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
     ${ESPEAK_NG_DIR}/include
-    ${ONNXRUNTIME_DIR}/include
+    ${ONNXRUNTIME_INCLUDE_DIRS}
 )
 
 target_link_directories(
     piper_phonemize PUBLIC
     ${ESPEAK_NG_DIR}/lib
-    ${ONNXRUNTIME_DIR}/lib
+    ${ONNXRUNTIME_LIBRARY_DIRS}
 )
 
 target_link_libraries(
@@ -227,10 +169,12 @@ install(
     DIRECTORY ${ESPEAK_NG_DIR}/
     DESTINATION ${CMAKE_INSTALL_PREFIX})
 
-install(
-    DIRECTORY ${ONNXRUNTIME_DIR}/include/
-    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+if(NOT USE_SYSTEM_ONNXRUNTIME)
+    install(
+        DIRECTORY ${ONNXRUNTIME_DIR}/include/
+        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
 
-install(
-    DIRECTORY ${ONNXRUNTIME_DIR}/lib/
-    DESTINATION ${CMAKE_INSTALL_LIBDIR})
+    install(
+        DIRECTORY ${ONNXRUNTIME_DIR}/lib/
+        DESTINATION ${CMAKE_INSTALL_LIBDIR})
+endif()
-- 
2.47.0