Skip to content

Commit a2ca107

Browse files
committed
cmake: add shared portable ops target and helper
Create libexecutorch_portable_ops.so under EXECUTORCH_BUILD_SHARED and add reusable CMake helper logic used to construct shared wrapper targets.
1 parent 881d420 commit a2ca107

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

kernels/portable/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ install(
106106
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/kernels/portable/
107107
)
108108

109+
if(EXECUTORCH_BUILD_SHARED)
110+
executorch_add_shared_library(
111+
executorch_portable_ops portable_ops_lib portable_kernels executorch_shared
112+
)
113+
endif()
114+
109115
# Build the portable custom ops AOT library for registering custom ops into
110116
# PyTorch. Requires find_package(Torch), which must be called at root scope
111117
# before this subdirectory is processed. Not targeting ARM_BAREMETAL as aot_lib

tools/cmake/Utils.cmake

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,29 @@ function(executorch_target_copy_mlx_metallib target)
211211
endif()
212212
endif()
213213
endfunction()
214+
215+
# Create and install a shared library composed from dependency libraries. The
216+
# target links the provided dependencies and carries VERSION/SOVERSION.
217+
function(executorch_add_shared_library target_name)
218+
set(_empty_source_name "${target_name}_empty.cpp")
219+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_empty_source_name}"
220+
"// intentionally empty"
221+
)
222+
add_library(
223+
${target_name} SHARED "${CMAKE_CURRENT_BINARY_DIR}/${_empty_source_name}"
224+
)
225+
target_link_libraries(${target_name} PRIVATE ${ARGN})
226+
set_target_properties(
227+
${target_name}
228+
PROPERTIES VERSION "${PROJECT_VERSION}"
229+
SOVERSION "${PROJECT_VERSION_MAJOR}"
230+
LINKER_LANGUAGE CXX
231+
)
232+
install(
233+
TARGETS ${target_name}
234+
EXPORT ExecuTorchTargets
235+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
236+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
237+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
238+
)
239+
endfunction()

0 commit comments

Comments
 (0)