@@ -175,8 +175,9 @@ option(EXECUTORCH_BUILD_VULKAN "Build the Vulkan backend" OFF)
175
175
#
176
176
# pthreadpool: build pthreadpool library. Disable on unsupported platforms
177
177
#
178
- cmake_dependent_option (EXECUTORCH_BUILD_PTHREADPOOL "Build pthreadpool library."
179
- ON "NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF )
178
+ cmake_dependent_option (
179
+ EXECUTORCH_BUILD_PTHREADPOOL "Build pthreadpool library." ON
180
+ "NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF )
180
181
181
182
#
182
183
# cpuinfo: build cpuinfo library. Disable on unsupported platforms
@@ -186,6 +187,9 @@ cmake_dependent_option(EXECUTORCH_BUILD_CPUINFO "Build cpuinfo library." ON
186
187
187
188
if (EXECUTORCH_BUILD_CPUINFO )
188
189
# --- cpuinfo
190
+ set (ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG
191
+ ${CMAKE_POSITION_INDEPENDENT_CODE} )
192
+ set (CMAKE_POSITION_INDEPENDENT_CODE ON )
189
193
set (CPUINFO_SOURCE_DIR "backends/xnnpack/third-party/cpuinfo" )
190
194
set (CPUINFO_BUILD_TOOLS
191
195
OFF
@@ -207,10 +211,15 @@ if(EXECUTORCH_BUILD_CPUINFO)
207
211
CACHE STRING "" )
208
212
set (CLOG_SOURCE_DIR "${CPUINFO_SOURCE_DIR} /deps/clog" )
209
213
add_subdirectory ("${CPUINFO_SOURCE_DIR} " )
214
+ set (CMAKE_POSITION_INDEPENDENT_CODE
215
+ ${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG} )
210
216
endif ()
211
217
212
218
if (EXECUTORCH_BUILD_PTHREADPOOL )
213
219
# --- pthreadpool
220
+ set (ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG
221
+ ${CMAKE_POSITION_INDEPENDENT_CODE} )
222
+ set (CMAKE_POSITION_INDEPENDENT_CODE ON )
214
223
set (PTHREADPOOL_SOURCE_DIR "backends/xnnpack/third-party/pthreadpool" )
215
224
set (PTHREADPOOL_BUILD_TESTS
216
225
OFF
@@ -230,6 +239,8 @@ if(EXECUTORCH_BUILD_PTHREADPOOL)
230
239
CACHE STRING "" )
231
240
endif ()
232
241
add_subdirectory ("${PTHREADPOOL_SOURCE_DIR} " )
242
+ set (CMAKE_POSITION_INDEPENDENT_CODE
243
+ ${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG} )
233
244
endif ()
234
245
235
246
if (NOT PYTHON_EXECUTABLE )
@@ -352,23 +363,25 @@ add_subdirectory(schema)
352
363
# Only contains primitive operators; does not contain portable kernels or other
353
364
# full operators. Does not contain any backends.
354
365
#
355
-
356
- add_library (executorch ${_executorch__srcs} )
357
- target_link_libraries (executorch PRIVATE program_schema )
358
- target_link_options_shared_lib (executorch )
366
+ add_library (executorch_no_prim_ops ${_executorch_no_prim_ops__srcs} )
367
+ target_link_libraries (executorch_no_prim_ops PRIVATE program_schema )
359
368
# Check if dl exists for this toolchain and only then link it.
360
369
find_library (DL_LIBRARY_EXISTS NAMES dl )
361
370
# Check if the library was found
362
371
if (DL_LIBRARY_EXISTS )
363
- target_link_libraries (executorch PRIVATE dl ) # For dladdr()
372
+ target_link_libraries (executorch_no_prim_ops PRIVATE dl ) # For dladdr()
364
373
endif ()
365
- target_include_directories (executorch PUBLIC ${_common_include_directories} )
366
- target_compile_options (executorch PUBLIC ${_common_compile_options} )
374
+ target_include_directories (executorch_no_prim_ops PUBLIC ${_common_include_directories} )
375
+ target_compile_options (executorch_no_prim_ops PUBLIC ${_common_compile_options} )
367
376
if (MAX_KERNEL_NUM )
368
- target_compile_definitions (executorch
377
+ target_compile_definitions (executorch_no_prim_ops
369
378
PRIVATE MAX_KERNEL_NUM=${MAX_KERNEL_NUM} )
370
379
endif ()
371
380
381
+ add_library (executorch ${_executorch__srcs} )
382
+ target_link_libraries (executorch PRIVATE executorch_no_prim_ops )
383
+ target_link_options_shared_lib (executorch )
384
+
372
385
#
373
386
# portable_ops_lib: A library to register core ATen ops using portable kernels,
374
387
# see kernels/portable/CMakeLists.txt.
@@ -504,25 +517,38 @@ if(EXECUTORCH_BUILD_PYBIND)
504
517
add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /sdk )
505
518
endif ()
506
519
520
+ # find pytorch lib, to allow pybind to take at::Tensor as input/output
521
+ find_package (Torch CONFIG REQUIRED )
522
+ find_library (TORCH_PYTHON_LIBRARY torch_python
523
+ PATHS "${TORCH_INSTALL_PREFIX} /lib" )
524
+
525
+ set (_dep_libs
526
+ ${TORCH_PYTHON_LIBRARY}
527
+ bundled_program
528
+ etdump
529
+ executorch
530
+ extension_data_loader
531
+ portable_ops_lib
532
+ util
533
+ torch )
534
+
507
535
if (EXECUTORCH_BUILD_COREML )
508
- set ( PYBIND_LINK_COREML " coremldelegate" )
536
+ list ( APPEND _dep_libs coremldelegate )
509
537
endif ()
510
538
511
539
if (EXECUTORCH_BUILD_MPS )
512
- set ( PYBIND_LINK_MPS " mpsdelegate" )
540
+ list ( APPEND _dep_libs mpsdelegate )
513
541
endif ()
514
542
515
543
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 )
544
+ # need to explicitly specify XNNPACK here otherwise uses XNNPACK symbols
545
+ # from libtorch_cpu
546
+ list ( APPEND _dep_libs xnnpack_backend XNNPACK )
519
547
endif ()
520
548
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
-
549
+ if (EXECUTORCH_BUILD_CUSTOM )
550
+ list (APPEND _dep_libs custom_ops custom_ops_aot_lib )
551
+ endif ()
526
552
# compile options for pybind
527
553
528
554
set (_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
@@ -544,19 +570,7 @@ if(EXECUTORCH_BUILD_PYBIND)
544
570
PUBLIC EXECUTORCH_PYTHON_MODULE_NAME=portable_lib )
545
571
target_include_directories (portable_lib PRIVATE ${TORCH_INCLUDE_DIRS} )
546
572
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} )
573
+ target_link_libraries (portable_lib PUBLIC ${_dep_libs} )
560
574
561
575
install (TARGETS portable_lib
562
576
LIBRARY DESTINATION executorch/extension/pybindings )
0 commit comments