Skip to content

Commit f70d618

Browse files
committed
Add top-level CMake backends target
ghstack-source-id: 299c14f ghstack-comment-id: 3099241838 Pull-Request: #12689
1 parent c52136f commit f70d618

File tree

2 files changed

+54
-26
lines changed

2 files changed

+54
-26
lines changed

CMakeLists.txt

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ add_library(executorch_core ${_executorch_core__srcs})
351351
# Legacy name alias.
352352
add_library(executorch_no_prim_ops ALIAS executorch_core)
353353

354+
# A list of all configured backends.
355+
set(_executorch_backends "")
356+
354357
target_link_libraries(executorch_core PRIVATE program_schema)
355358
if(ANDROID)
356359
target_link_libraries(executorch_core PUBLIC log)
@@ -494,6 +497,7 @@ install(FILES tools/cmake/Utils.cmake tools/cmake/executorch-config.cmake
494497

495498
if(EXECUTORCH_BUILD_ARM_BAREMETAL)
496499
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/arm)
500+
list(APPEND _executorch_backends executorch_delegate_ethos_u)
497501
endif()
498502

499503
if(EXECUTORCH_BUILD_CADENCE)
@@ -502,30 +506,37 @@ endif()
502506

503507
if(EXECUTORCH_BUILD_NXP_NEUTRON)
504508
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/nxp)
509+
list(APPEND _executorch_backends executorch_delegate_neutron)
505510
endif()
506511

507512
if(EXECUTORCH_BUILD_COREML)
508513
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/apple/coreml)
514+
list(APPEND _executorch_backends coremldelegate)
509515
endif()
510516

511517
if(EXECUTORCH_BUILD_MPS)
512518
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/apple/mps)
519+
list(APPEND _executorch_backends mpsdelegate)
513520
endif()
514521

515522
if(EXECUTORCH_BUILD_NEURON)
516523
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/mediatek)
524+
list(APPEND _executorch_backends neuron_backend)
517525
endif()
518526

519527
if(EXECUTORCH_BUILD_OPENVINO)
520528
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/openvino)
529+
list(APPEND _executorch_backends openvino_backend)
521530
endif()
522531

523532
if(EXECUTORCH_BUILD_QNN)
524533
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/qualcomm)
534+
list(APPEND _executorch_backends qnn_executorch_backend)
525535
endif()
526536

527537
if(EXECUTORCH_BUILD_XNNPACK)
528538
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/xnnpack)
539+
list(APPEND _executorch_backends xnnpack_backend)
529540
endif()
530541

531542
if(EXECUTORCH_BUILD_CORTEX_M)
@@ -689,6 +700,17 @@ if(EXECUTORCH_BUILD_KERNELS_QUANTIZED)
689700
target_link_options_shared_lib(quantized_ops_lib)
690701
endif()
691702

703+
if(EXECUTORCH_BUILD_VULKAN)
704+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/vulkan)
705+
list(APPEND _executorch_backends vulkan_backend)
706+
endif()
707+
708+
# Top-level interface targets.
709+
add_library(executorch_backends INTERFACE)
710+
711+
# A target containing all configured backends.
712+
target_link_libraries(executorch_backends INTERFACE ${_executorch_backends})
713+
692714
if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
693715
# Baseline libraries that executor_runner will link against.
694716
set(_executor_runner_libs executorch gflags)
@@ -726,19 +748,6 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
726748
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
727749
target_link_options_gc_sections(executor_runner)
728750
endif()
729-
target_link_libraries(executor_runner ${_executor_runner_libs})
730-
target_compile_options(executor_runner PUBLIC ${_common_compile_options})
731-
732-
# Automatically set when using `emcmake cmake` for Wasm build.
733-
if(EMSCRIPTEN)
734-
# Directory of model pte files to embed in the wasm binary.
735-
if(NOT DEFINED WASM_MODEL_DIR)
736-
set(WASM_MODEL_DIR "${CMAKE_SOURCE_DIR}/models/")
737-
endif()
738-
739-
set(CMAKE_EXECUTABLE_SUFFIX ".html")
740-
target_link_options(executor_runner PUBLIC -sALLOW_MEMORY_GROWTH --embed-file "${WASM_MODEL_DIR}@/")
741-
endif()
742751
endif()
743752

744753
if(EXECUTORCH_BUILD_VULKAN)
@@ -749,6 +758,10 @@ if(EXECUTORCH_BUILD_ANDROID_JNI)
749758
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/android)
750759
endif()
751760

761+
if(EXECUTORCH_BUILD_ANDROID_JNI)
762+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/android)
763+
endif()
764+
752765
include(Test.cmake)
753766

754767
# Print all the configs that were called with announce_configured_options.

tools/cmake/executorch-config.cmake

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,28 @@ set(EXECUTORCH_FOUND ON)
5757

5858
target_link_libraries(executorch INTERFACE executorch_core)
5959

60-
set(lib_list
61-
flatccrt
62-
etdump
63-
bundled_program
64-
extension_data_loader
65-
extension_flat_tensor
60+
set(backend_lib_list
6661
coreml_util
6762
coreml_inmemoryfs
6863
coremldelegate
6964
mpsdelegate
7065
neuron_backend
7166
qnn_executorch_backend
67+
# Start XNNPACK Lib Deps
68+
XNNPACK
69+
xnnpack-microkernels-prod
70+
kleidiai
71+
# End XNNPACK Lib Deps
72+
xnnpack_backend
73+
vulkan_backend
74+
)
75+
76+
set(lib_list
77+
flatccrt
78+
etdump
79+
bundled_program
80+
extension_data_loader
81+
extension_flat_tensor
7282
portable_ops_lib
7383
custom_ops
7484
extension_module
@@ -77,15 +87,8 @@ set(lib_list
7787
extension_tensor
7888
extension_threadpool
7989
extension_training
80-
xnnpack_backend
81-
# Start XNNPACK Lib Deps
82-
XNNPACK
83-
xnnpack-microkernels-prod
84-
kleidiai
85-
# End XNNPACK Lib Deps
8690
cpuinfo
8791
pthreadpool
88-
vulkan_backend
8992
optimized_kernels
9093
optimized_portable_kernels
9194
cpublas
@@ -96,6 +99,9 @@ set(lib_list
9699
quantized_ops_lib
97100
quantized_ops_aot_lib
98101
)
102+
103+
list(APPEND lib_list ${backend_lib_list})
104+
99105
foreach(lib ${lib_list})
100106
# Name of the variable which stores result of the find_library search
101107
set(lib_var "LIB_${lib}")
@@ -198,3 +204,12 @@ if(TARGET xnnpack_backend)
198204
)
199205
target_link_options_shared_lib(xnnpack_backend)
200206
endif()
207+
208+
# An interface target containing all available backends.
209+
add_library(executorch_backends INTERFACE)
210+
211+
foreach(lib ${backend_lib_list})
212+
if(TARGET ${lib})
213+
target_link_options(executorch_backends INTERFACE ${lib})
214+
endif()
215+
endforeach()

0 commit comments

Comments
 (0)