|
46 | 46 | # |
47 | 47 |
|
48 | 48 | cmake_minimum_required(VERSION 3.24) |
49 | | -project(executorch) |
50 | 49 |
|
51 | 50 | set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) |
52 | 51 |
|
@@ -87,6 +86,10 @@ if("${ET_VERSION_MAJOR}" STREQUAL "" |
87 | 86 | ) |
88 | 87 | endif() |
89 | 88 |
|
| 89 | +project(executorch |
| 90 | + VERSION "${ET_VERSION_MAJOR}.${ET_VERSION_MINOR}.${ET_VERSION_PATCH}" |
| 91 | +) |
| 92 | + |
90 | 93 | message( |
91 | 94 | STATUS |
92 | 95 | "ExecuTorch version: ${ET_VERSION_MAJOR}.${ET_VERSION_MINOR}.${ET_VERSION_PATCH}" |
@@ -177,6 +180,10 @@ if(DEFINED EXECUTORCH_BAREMETAL_SKIP_INSTALL |
177 | 180 | ) |
178 | 181 | endif() |
179 | 182 |
|
| 183 | +if(EXECUTORCH_BUILD_SHARED) |
| 184 | + set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 185 | +endif() |
| 186 | + |
180 | 187 | # Enable ccache if available |
181 | 188 | find_program(CCACHE_PROGRAM ccache) |
182 | 189 | if(CCACHE_PROGRAM) |
@@ -1165,6 +1172,49 @@ if(EXECUTORCH_BUILD_KERNELS_LLM) |
1165 | 1172 | list(APPEND _executorch_kernels custom_ops_aot_lib) |
1166 | 1173 | endif() |
1167 | 1174 |
|
| 1175 | +# Consolidated shared library: bundles executorch_core plus commonly used |
| 1176 | +# extensions into a single libexecutorch.so. |
| 1177 | +if(EXECUTORCH_BUILD_SHARED) |
| 1178 | + executorch_add_shared_library(executorch_shared) |
| 1179 | + set_target_properties( |
| 1180 | + executorch_shared |
| 1181 | + PROPERTIES OUTPUT_NAME executorch |
| 1182 | + ARCHIVE_OUTPUT_NAME executorch_shared |
| 1183 | + EXPORT_NAME executorch-shared |
| 1184 | + ) |
| 1185 | + target_include_directories( |
| 1186 | + executorch_shared PUBLIC ${_common_include_directories} |
| 1187 | + ) |
| 1188 | + target_compile_definitions( |
| 1189 | + executorch_shared PUBLIC C10_USING_CUSTOM_GENERATED_MACROS |
| 1190 | + ) |
| 1191 | + # Link executorch without WHOLE_ARCHIVE because its INTERFACE link options |
| 1192 | + # (from executorch_target_link_options_shared_lib) already force |
| 1193 | + # whole-archive. Link executorch_core explicitly since executorch only has a |
| 1194 | + # PRIVATE dep on it (symbols wouldn't propagate otherwise). |
| 1195 | + target_link_libraries( |
| 1196 | + executorch_shared PRIVATE executorch |
| 1197 | + $<LINK_LIBRARY:WHOLE_ARCHIVE,executorch_core> |
| 1198 | + ) |
| 1199 | + foreach(_ext_target |
| 1200 | + extension_data_loader extension_flat_tensor extension_named_data_map |
| 1201 | + extension_module_static extension_tensor |
| 1202 | + ) |
| 1203 | + if(TARGET ${_ext_target}) |
| 1204 | + target_link_libraries( |
| 1205 | + executorch_shared PRIVATE $<LINK_LIBRARY:WHOLE_ARCHIVE,${_ext_target}> |
| 1206 | + ) |
| 1207 | + endif() |
| 1208 | + endforeach() |
| 1209 | + configure_file( |
| 1210 | + tools/cmake/executorch.pc.in ${CMAKE_CURRENT_BINARY_DIR}/executorch.pc |
| 1211 | + @ONLY |
| 1212 | + ) |
| 1213 | + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/executorch.pc |
| 1214 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig |
| 1215 | + ) |
| 1216 | +endif() |
| 1217 | + |
1168 | 1218 | if(EXECUTORCH_BUILD_KERNELS_QUANTIZED) |
1169 | 1219 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/quantized) |
1170 | 1220 | executorch_target_link_options_shared_lib(quantized_ops_lib) |
|
0 commit comments