Skip to content

Commit 3a9fdf7

Browse files
committed
Add top-level CMake extensions target
ghstack-source-id: 5dd260f ghstack-comment-id: 3099981300 Pull-Request: #12696
1 parent f70d618 commit 3a9fdf7

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

CMakeLists.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ add_library(executorch_no_prim_ops ALIAS executorch_core)
354354
# A list of all configured backends.
355355
set(_executorch_backends "")
356356

357+
# A list of all configured extensions.
358+
set(_executorch_extensions "")
359+
357360
target_link_libraries(executorch_core PRIVATE program_schema)
358361
if(ANDROID)
359362
target_link_libraries(executorch_core PUBLIC log)
@@ -549,14 +552,17 @@ endif()
549552

550553
if(EXECUTORCH_BUILD_EXTENSION_APPLE)
551554
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/apple)
555+
list(APPEND _executorch_extensions apple_extension)
552556
endif()
553557

554558
if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
555559
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/data_loader)
560+
list(APPEND _executorch_extensions extension_data_loader)
556561
endif()
557562

558563
if(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR)
559564
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/flat_tensor)
565+
list(APPEND _executorch_extensions extension_flat_tensor)
560566
endif()
561567

562568
if(EXECUTORCH_BUILD_EXTENSION_MODULE)
@@ -567,26 +573,32 @@ if(EXECUTORCH_BUILD_EXTENSION_MODULE)
567573
FILES_MATCHING
568574
PATTERN "*.h"
569575
)
576+
list(APPEND _executorch_extensions extension_module_static)
570577
endif()
571578

572579
if(EXECUTORCH_BUILD_EXTENSION_LLM)
573580
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/tokenizers)
581+
list(APPEND _executorch_extensions tokenizers)
574582
endif()
575583

576584
if(EXECUTORCH_BUILD_EXTENSION_LLM_APPLE)
577585
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/apple)
586+
list(APPEND _executorch_extensions extension_llm_apple)
578587
endif()
579588

580589
if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER)
581590
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/runner)
591+
list(APPEND _executorch_extensions extension_llm_runner)
582592
endif()
583593

584594
if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL)
585595
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/runner_util)
596+
list(APPEND _executorch_extensions extension_runner_util)
586597
endif()
587598

588599
if(EXECUTORCH_BUILD_EXTENSION_TENSOR)
589600
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/tensor)
601+
list(APPEND _executorch_extensions extension_tensor)
590602
endif()
591603

592604
if(EXECUTORCH_BUILD_PTHREADPOOL AND EXECUTORCH_BUILD_CPUINFO)
@@ -688,6 +700,7 @@ endif()
688700

689701
if(EXECUTORCH_BUILD_EXTENSION_TRAINING)
690702
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/training)
703+
list(APPEND _executorch_extensions extension_training)
691704
endif()
692705

693706
if(EXECUTORCH_BUILD_KERNELS_LLM)
@@ -706,11 +719,15 @@ if(EXECUTORCH_BUILD_VULKAN)
706719
endif()
707720

708721
# Top-level interface targets.
709-
add_library(executorch_backends INTERFACE)
710722

711723
# A target containing all configured backends.
724+
add_library(executorch_backends INTERFACE)
712725
target_link_libraries(executorch_backends INTERFACE ${_executorch_backends})
713726

727+
# A target containing all configured extensions.
728+
add_library(executorch_extensions INTERFACE)
729+
target_link_libraries(executorch_extensions INTERFACE ${_executorch_extensions})
730+
714731
if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
715732
# Baseline libraries that executor_runner will link against.
716733
set(_executor_runner_libs executorch gflags)

tools/cmake/executorch-config.cmake

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,23 @@ set(backend_lib_list
7373
vulkan_backend
7474
)
7575

76-
set(lib_list
77-
flatccrt
78-
etdump
79-
bundled_program
76+
set(extension_lib_list
8077
extension_data_loader
8178
extension_flat_tensor
82-
portable_ops_lib
83-
custom_ops
8479
extension_module
8580
extension_module_static
8681
extension_runner_util
8782
extension_tensor
8883
extension_threadpool
8984
extension_training
85+
)
86+
87+
set(lib_list
88+
flatccrt
89+
etdump
90+
bundled_program
91+
portable_ops_lib
92+
custom_ops
9093
cpuinfo
9194
pthreadpool
9295
optimized_kernels
@@ -100,7 +103,7 @@ set(lib_list
100103
quantized_ops_aot_lib
101104
)
102105

103-
list(APPEND lib_list ${backend_lib_list})
106+
list(APPEND lib_list ${backend_lib_list} ${extension_lib_list})
104107

105108
foreach(lib ${lib_list})
106109
# Name of the variable which stores result of the find_library search
@@ -213,3 +216,12 @@ foreach(lib ${backend_lib_list})
213216
target_link_options(executorch_backends INTERFACE ${lib})
214217
endif()
215218
endforeach()
219+
220+
# An interface target containing all available extensions.
221+
add_library(executorch_extensions INTERFACE)
222+
223+
foreach(lib ${extension_lib_list})
224+
if(TARGET ${lib})
225+
target_link_options(executorch_extensions INTERFACE ${lib})
226+
endif()
227+
endforeach()

0 commit comments

Comments
 (0)