@@ -144,6 +144,8 @@ option(EXECUTORCH_BUILD_COREML "Build the Core ML backend" OFF)
144144
145145option (EXECUTORCH_BUILD_CUSTOM "Build the custom kernels" OFF )
146146
147+ option (EXECUTORCH_BUILD_CUSTOM_OPS_AOT "Build the custom ops lib for AOT" OFF )
148+
147149option (EXECUTORCH_BUILD_EXTENSION_DATA_LOADER "Build the Data Loader extension"
148150 OFF )
149151
@@ -175,17 +177,29 @@ option(EXECUTORCH_BUILD_VULKAN "Build the Vulkan backend" OFF)
175177#
176178# pthreadpool: build pthreadpool library. Disable on unsupported platforms
177179#
178- cmake_dependent_option (EXECUTORCH_BUILD_PTHREADPOOL "Build pthreadpool library."
179- ON "NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF )
180+ cmake_dependent_option (
181+ EXECUTORCH_BUILD_PTHREADPOOL "Build pthreadpool library." ON
182+ "NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF )
180183
181184#
182185# cpuinfo: build cpuinfo library. Disable on unsupported platforms
183186#
184187cmake_dependent_option (EXECUTORCH_BUILD_CPUINFO "Build cpuinfo library." ON
185188 "NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF )
186189
190+ if (EXECUTORCH_BUILD_CUSTOM_OPS_AOT)
191+ set (EXECUTORCH_BUILD_CUSTOM ON )
192+ endif ()
193+
194+ if (EXECUTORCH_BUILD_CUSTOM)
195+ set (EXECUTORCH_BUILD_OPTIMIZED ON )
196+ endif ()
197+
187198if (EXECUTORCH_BUILD_CPUINFO)
188199 # --- cpuinfo
200+ set (ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG
201+ ${CMAKE_POSITION_INDEPENDENT_CODE } )
202+ set (CMAKE_POSITION_INDEPENDENT_CODE ON )
189203 set (CPUINFO_SOURCE_DIR "backends/xnnpack/third-party/cpuinfo" )
190204 set (CPUINFO_BUILD_TOOLS
191205 OFF
@@ -207,10 +221,15 @@ if(EXECUTORCH_BUILD_CPUINFO)
207221 CACHE STRING "" )
208222 set (CLOG_SOURCE_DIR "${CPUINFO_SOURCE_DIR } /deps/clog" )
209223 add_subdirectory ("${CPUINFO_SOURCE_DIR } " )
224+ set (CMAKE_POSITION_INDEPENDENT_CODE
225+ ${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG} )
210226endif ()
211227
212228if (EXECUTORCH_BUILD_PTHREADPOOL)
213229 # --- pthreadpool
230+ set (ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG
231+ ${CMAKE_POSITION_INDEPENDENT_CODE } )
232+ set (CMAKE_POSITION_INDEPENDENT_CODE ON )
214233 set (PTHREADPOOL_SOURCE_DIR "backends/xnnpack/third-party/pthreadpool" )
215234 set (PTHREADPOOL_BUILD_TESTS
216235 OFF
@@ -230,6 +249,8 @@ if(EXECUTORCH_BUILD_PTHREADPOOL)
230249 CACHE STRING "" )
231250 endif ()
232251 add_subdirectory ("${PTHREADPOOL_SOURCE_DIR } " )
252+ set (CMAKE_POSITION_INDEPENDENT_CODE
253+ ${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG} )
233254endif ()
234255
235256if (NOT PYTHON_EXECUTABLE)
@@ -504,25 +525,38 @@ if(EXECUTORCH_BUILD_PYBIND)
504525 add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR } /sdk )
505526 endif ()
506527
528+ # find pytorch lib, to allow pybind to take at::Tensor as input/output
529+ find_package (Torch CONFIG REQUIRED )
530+ find_library (TORCH_PYTHON_LIBRARY torch_python
531+ PATHS "${TORCH_INSTALL_PREFIX} /lib" )
532+
533+ set (_dep_libs
534+ ${TORCH_PYTHON_LIBRARY}
535+ bundled_program
536+ etdump
537+ executorch
538+ extension_data_loader
539+ portable_ops_lib
540+ util
541+ torch)
542+
507543 if (EXECUTORCH_BUILD_COREML)
508- set (PYBIND_LINK_COREML " coremldelegate" )
544+ list ( APPEND _dep_libs coremldelegate)
509545 endif ()
510546
511547 if (EXECUTORCH_BUILD_MPS)
512- set (PYBIND_LINK_MPS " mpsdelegate" )
548+ list ( APPEND _dep_libs mpsdelegate)
513549 endif ()
514550
515551 if (EXECUTORCH_BUILD_XNNPACK)
516- # need to explicitly specify XNNPACK here
517- # otherwise uses XNNPACK symbols from libtorch_cpu
518- set (PYBIND_LINK_XNNPACK xnnpack_backend XNNPACK)
552+ # need to explicitly specify XNNPACK here otherwise uses XNNPACK symbols
553+ # from libtorch_cpu
554+ list ( APPEND _dep_libs xnnpack_backend XNNPACK)
519555 endif ()
520556
521- # find pytorch lib, to allow pybind to take at::Tensor as input/output
522- find_package (Torch CONFIG REQUIRED )
523- find_library (TORCH_PYTHON_LIBRARY torch_python
524- PATHS "${TORCH_INSTALL_PREFIX} /lib" )
525-
557+ if (EXECUTORCH_BUILD_CUSTOM)
558+ list (APPEND _dep_libs custom_ops custom_ops_aot_lib)
559+ endif ()
526560 # compile options for pybind
527561
528562 set (_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
@@ -544,19 +578,7 @@ if(EXECUTORCH_BUILD_PYBIND)
544578 PUBLIC EXECUTORCH_PYTHON_MODULE_NAME=portable_lib )
545579 target_include_directories (portable_lib PRIVATE ${TORCH_INCLUDE_DIRS} )
546580 target_compile_options (portable_lib PUBLIC ${_pybind_compile_options} )
547- target_link_libraries (
548- portable_lib
549- PUBLIC ${TORCH_PYTHON_LIBRARY}
550- bundled_program
551- etdump
552- executorch
553- extension_data_loader
554- portable_ops_lib
555- util
556- torch
557- ${PYBIND_LINK_COREML}
558- ${PYBIND_LINK_MPS}
559- ${PYBIND_LINK_XNNPACK} )
581+ target_link_libraries (portable_lib PUBLIC ${_dep_libs} )
560582
561583 install (TARGETS portable_lib
562584 LIBRARY DESTINATION executorch/extension/pybindings)
0 commit comments