Skip to content

Commit eee5a1d

Browse files
tomeuvclaude
andcommitted
cmake: build shared libexecutorch_quantized_ops when EXECUTORCH_BUILD_SHARED=ON
Create a single libexecutorch_quantized_ops.so that bundles quantized_ops_lib and quantized_kernels, allowing consumers to link quantized op implementations via a shared library. quantized_ops_lib already has --whole-archive as an INTERFACE link option from Codegen.cmake, so we do not wrap it in $<LINK_LIBRARY:WHOLE_ARCHIVE,...> to avoid pulling the registration constructor in twice. Link against executorch_shared (not executorch_core) to share a single operator registry. Co-authored-by: Claude <noreply@anthropic.com>
1 parent e90703d commit eee5a1d

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

kernels/quantized/CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,34 @@ install(
157157
PUBLIC_HEADER
158158
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/kernels/quantized/
159159
)
160+
161+
# When building shared libraries, create a single
162+
# libexecutorch_quantized_ops.so that bundles quantized_ops_lib and
163+
# quantized_kernels so consumers can link a shared library instead of
164+
# needing --whole-archive on the static archives.
165+
if(EXECUTORCH_BUILD_SHARED)
166+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/quantized_ops_shared_empty.cpp
167+
"// intentionally empty"
168+
)
169+
add_library(
170+
executorch_quantized_ops SHARED
171+
${CMAKE_CURRENT_BINARY_DIR}/quantized_ops_shared_empty.cpp
172+
)
173+
# quantized_ops_lib already has --whole-archive as an INTERFACE link option
174+
# (from executorch_target_link_options_shared_lib in Codegen.cmake), so do
175+
# NOT wrap it in $<LINK_LIBRARY:WHOLE_ARCHIVE,...> to avoid double pull-in.
176+
target_link_libraries(
177+
executorch_quantized_ops
178+
PRIVATE quantized_ops_lib
179+
quantized_kernels
180+
executorch_shared
181+
)
182+
set_target_properties(
183+
executorch_quantized_ops PROPERTIES LINKER_LANGUAGE CXX
184+
)
185+
install(
186+
TARGETS executorch_quantized_ops
187+
EXPORT ExecuTorchTargets
188+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
189+
)
190+
endif()

0 commit comments

Comments
 (0)