-
Notifications
You must be signed in to change notification settings - Fork 34
/
onnxruntime-1.19.2-monolithic-static-library.patch
213 lines (208 loc) · 8.25 KB
/
onnxruntime-1.19.2-monolithic-static-library.patch
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
diff -Nuarp onnxruntime-1.19.2.orig/cmake/bundle_static_library.cmake onnxruntime-1.19.2/cmake/bundle_static_library.cmake
--- onnxruntime-1.19.2.orig/cmake/bundle_static_library.cmake 1970-01-01 08:00:00.000000000 +0800
+++ onnxruntime-1.19.2/cmake/bundle_static_library.cmake 2024-10-18 16:25:09.945380582 +0800
@@ -0,0 +1,145 @@
+# References:
+# - https://github.com/microsoft/onnxruntime/blob/main/cmake/onnxruntime_webassembly.cmake
+# - https://cristianadam.eu/20190501/bundling-together-static-libraries-with-cmake
+
+function(bundle_static_library bundled_target_name)
+ set(extension_blocklist
+ .dylib
+ .so
+ .dll
+ .tbd
+ )
+
+ function(recursively_collect_dependencies input_target)
+ if(NOT TARGET ${input_target})
+ if(EXISTS ${input_target})
+ get_filename_component(extension "${input_target}" EXT)
+
+ if(NOT extension IN_LIST extension_blocklist)
+ list(APPEND static_libs "${input_target}")
+ set(static_libs ${static_libs} PARENT_SCOPE)
+ endif()
+ endif()
+
+ return()
+ endif()
+
+ get_target_property(alias ${input_target} ALIASED_TARGET)
+
+ if(TARGET ${alias})
+ set(input_target ${alias})
+ endif()
+
+ get_property(library_already_added GLOBAL PROPERTY ${target_name}_static_bundle_${input_target})
+
+ if(library_already_added)
+ return()
+ endif()
+
+ set_property(GLOBAL PROPERTY ${target_name}_static_bundle_${input_target} ON)
+
+ get_target_property(input_type ${input_target} TYPE)
+
+ if(${input_type} STREQUAL "STATIC_LIBRARY")
+ list(APPEND static_libs "$<TARGET_FILE:${input_target}>")
+ get_target_property(dependencies ${input_target} LINK_LIBRARIES)
+ elseif(${input_type} STREQUAL "INTERFACE_LIBRARY")
+ get_target_property(dependencies ${input_target} INTERFACE_LINK_LIBRARIES)
+ else()
+ get_target_property(dependencies ${input_target} LINK_LIBRARIES)
+ endif()
+
+ if(dependencies)
+ foreach(dependency IN LISTS dependencies)
+ recursively_collect_dependencies(${dependency})
+ endforeach()
+ endif()
+
+ set(static_libs ${static_libs} PARENT_SCOPE)
+ endfunction()
+
+ foreach(target_name IN ITEMS ${ARGN})
+ recursively_collect_dependencies(${target_name})
+ endforeach()
+
+ list(REMOVE_DUPLICATES static_libs)
+ set(static_libs ${static_libs} PARENT_SCOPE)
+
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/static_libs.txt.in)
+
+ foreach(static_lib IN LISTS static_libs)
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/static_libs.txt.in "${static_lib}\n")
+ endforeach()
+
+ file(GENERATE
+ OUTPUT static_libs.txt
+ INPUT ${CMAKE_CURRENT_BINARY_DIR}/static_libs.txt.in)
+
+ set(bundled_target_full_name
+ ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${bundled_target_name}${CMAKE_STATIC_LIBRARY_SUFFIX})
+
+ if(MSVC)
+ set(lib ${CMAKE_AR})
+ add_custom_command(
+ COMMAND ${lib} /NOLOGO /OUT:${bundled_target_full_name} ${static_libs}
+ OUTPUT ${bundled_target_full_name}
+ COMMENT "Bundling ${bundled_target_name}"
+ VERBATIM)
+ elseif(APPLE)
+ find_program(libtool libtool)
+ add_custom_command(
+ COMMAND ${libtool} -static -o ${bundled_target_full_name} ${static_libs}
+ OUTPUT ${bundled_target_full_name}
+ COMMENT "Bundling ${bundled_target_name}"
+ VERBATIM)
+ else()
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${bundled_target_name}.ar.in
+ "CREATE ${bundled_target_full_name}\n")
+
+ foreach(static_lib IN LISTS static_libs)
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/${bundled_target_name}.ar.in
+ "ADDLIB ${static_lib}\n")
+ endforeach()
+
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/${bundled_target_name}.ar.in "SAVE\n")
+ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/${bundled_target_name}.ar.in "END\n")
+
+ file(GENERATE
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${bundled_target_name}.ar
+ INPUT ${CMAKE_CURRENT_BINARY_DIR}/${bundled_target_name}.ar.in)
+
+ set(ar ${CMAKE_AR})
+
+ if(CMAKE_INTERPROCEDURAL_OPTIMIZATION)
+ set(ar ${CMAKE_CXX_COMPILER_AR})
+ endif()
+
+ add_custom_command(
+ COMMAND ${ar} -M < ${CMAKE_CURRENT_BINARY_DIR}/${bundled_target_name}.ar
+ OUTPUT ${bundled_target_full_name}
+ COMMENT "Bundling ${bundled_target_name}"
+ VERBATIM)
+ endif()
+
+ add_custom_target(bundling_${bundled_target_name} ALL DEPENDS ${bundled_target_full_name})
+
+ foreach(target_name IN ITEMS ${ARGN})
+ if(TARGET ${target_name})
+ add_dependencies(bundling_${bundled_target_name} ${target_name})
+ endif()
+ endforeach()
+
+ add_library(${bundled_target_name} STATIC IMPORTED GLOBAL)
+ set_target_properties(${bundled_target_name}
+ PROPERTIES
+ IMPORTED_LOCATION ${bundled_target_full_name})
+
+ foreach(target_name IN ITEMS ${ARGN})
+ set_property(TARGET ${bundled_target_name} APPEND
+ PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${target_name},INTERFACE_INCLUDE_DIRECTORIES>)
+ set_property(TARGET ${bundled_target_name} APPEND
+ PROPERTY INTERFACE_COMPILE_DEFINITIONS $<TARGET_PROPERTY:${target_name},INTERFACE_COMPILE_DEFINITIONS>)
+ endforeach()
+
+ add_dependencies(${bundled_target_name} bundling_${bundled_target_name})
+endfunction()
diff -Nuarp onnxruntime-1.19.2.orig/cmake/CMakeLists.txt onnxruntime-1.19.2/cmake/CMakeLists.txt
--- onnxruntime-1.19.2.orig/cmake/CMakeLists.txt 2024-08-31 06:02:31.000000000 +0800
+++ onnxruntime-1.19.2/cmake/CMakeLists.txt 2024-10-18 16:25:51.009382540 +0800
@@ -1829,7 +1829,7 @@ if (onnxruntime_ENABLE_EXTERNAL_CUSTOM_O
)
endif()
-if(TARGET onnxruntime)
+if(FALSE)
# Install
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
@@ -1861,3 +1861,19 @@ if(DEFINED BUILD_AS_ARM64X)
set(ARM64X_TARGETS onnxruntime)
include("${CMAKE_CURRENT_SOURCE_DIR}/arm64x.cmake")
endif()
+
+include(bundle_static_library.cmake)
+bundle_static_library(onnxruntime_static_lib onnxruntime)
+
+install(
+ DIRECTORY ${REPO_ROOT}/include/onnxruntime/core/session/
+ DESTINATION include/
+ FILES_MATCHING
+ PATTERN "*.h"
+)
+
+install(
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}onnxruntime_static_lib${CMAKE_STATIC_LIBRARY_SUFFIX}
+ RENAME ${CMAKE_STATIC_LIBRARY_PREFIX}onnxruntime${CMAKE_STATIC_LIBRARY_SUFFIX}
+ TYPE LIB
+)
diff -Nuarp onnxruntime-1.19.2.orig/cmake/onnxruntime.cmake onnxruntime-1.19.2/cmake/onnxruntime.cmake
--- onnxruntime-1.19.2.orig/cmake/onnxruntime.cmake 2024-08-31 06:02:31.000000000 +0800
+++ onnxruntime-1.19.2/cmake/onnxruntime.cmake 2024-10-18 16:44:42.067436473 +0800
@@ -259,13 +259,6 @@ else()
VERSION ${ORT_VERSION}
FOLDER "ONNXRuntime")
endif()
-install(TARGETS onnxruntime
- EXPORT ${PROJECT_NAME}Targets
- PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
if (WIN32 AND NOT CMAKE_CXX_STANDARD_LIBRARIES MATCHES kernel32.lib)
diff -Nuarp onnxruntime-1.19.2.orig/cmake/onnxruntime_providers_cpu.cmake onnxruntime-1.19.2/cmake/onnxruntime_providers_cpu.cmake
--- onnxruntime-1.19.2.orig/cmake/onnxruntime_providers_cpu.cmake 2024-08-31 06:02:31.000000000 +0800
+++ onnxruntime-1.19.2/cmake/onnxruntime_providers_cpu.cmake 2024-10-18 16:44:59.435437301 +0800
@@ -258,11 +258,6 @@ if (NOT onnxruntime_MINIMAL_BUILD AND NO
message(FATAL_ERROR "onnxruntime_providers_shared unknown platform, need to specify shared library exports for it")
endif()
- install(TARGETS onnxruntime_providers_shared
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- )
endif()
if (NOT onnxruntime_BUILD_SHARED_LIB)