diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a053eb28eb..48b43f39a40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -446,18 +446,21 @@ if(EXECUTORCH_BUILD_PYBIND AND APPLE) endif() # -# executorch: Primary runtime library with primitive operators. +# prim_ops_lib: Primary runtime library with primitive operators. # # Provides the Program and Method interfaces, along with primitive operators. # Does not contain portable kernels or other full operators. Does not contain # any backends. # -add_library(executorch ${_executorch__srcs}) -target_link_libraries(executorch PRIVATE executorch_core) -target_include_directories(executorch PUBLIC ${_common_include_directories}) -target_compile_definitions(executorch PUBLIC C10_USING_CUSTOM_GENERATED_MACROS) -target_compile_options(executorch PUBLIC ${_common_compile_options}) -executorch_target_link_options_shared_lib(executorch) +add_library(prim_ops_lib ${_executorch__srcs}) +target_link_libraries(prim_ops_lib PRIVATE executorch_core) +target_include_directories(prim_ops_lib PUBLIC ${_common_include_directories}) +target_compile_definitions(prim_ops_lib PUBLIC C10_USING_CUSTOM_GENERATED_MACROS) +target_compile_options(prim_ops_lib PUBLIC ${_common_compile_options}) +target_link_options_shared_lib(prim_ops_lib) + +# Legacy alias for backward compatibility during transition +add_library(executorch ALIAS prim_ops_lib) # # portable_ops_lib: A library to register core ATen ops using portable kernels, @@ -528,9 +531,9 @@ install( FILES_MATCHING PATTERN "*.h" ) +# ...existing code... install( - TARGETS executorch executorch_core - EXPORT ExecuTorchTargets + TARGETS prim_ops_lib executorch_core INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) @@ -990,12 +993,3 @@ if(EXECUTORCH_BUILD_ANDROID_JNI) endif() include(Test.cmake) - -install( - EXPORT ExecuTorchTargets - FILE ExecuTorchTargets.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ExecuTorch -) - -# Print all the configs that were called with announce_configured_options. -print_configured_options() diff --git a/backends/cadence/CMakeLists.txt b/backends/cadence/CMakeLists.txt index 47183bed21d..aef0512d1f6 100644 --- a/backends/cadence/CMakeLists.txt +++ b/backends/cadence/CMakeLists.txt @@ -32,12 +32,11 @@ if(EXECUTORCH_CADENCE_CPU_RUNNER) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) set(_common_compile_options -Wno-deprecated-declarations -fPIC) - # Find prebuilt libraries. executorch package should contain portable_ops_lib, # etdump, bundled_program. find_package(executorch CONFIG REQUIRED) - executorch_target_link_options_shared_lib(executorch) - executorch_target_link_options_shared_lib(portable_ops_lib) + # Note: target_link_options_shared_lib(prim_ops_lib) is now called automatically in executorch-config.cmake + target_include_directories( executorch INTERFACE ${_common_include_directories} diff --git a/examples/arm/executor_runner/CMakeLists.txt b/examples/arm/executor_runner/CMakeLists.txt index 5e1d7b08147..12ff6ef08ac 100644 --- a/examples/arm/executor_runner/CMakeLists.txt +++ b/examples/arm/executor_runner/CMakeLists.txt @@ -116,8 +116,68 @@ add_corstone_subdirectory(${SYSTEM_CONFIG} ${ETHOS_SDK_PATH}) configure_timing_adapters(${SYSTEM_CONFIG} ${MEMORY_MODE}) # Dependencies from the ExecuTorch build -find_package( - executorch REQUIRED HINTS "${ET_BUILD_DIR_PATH}/lib/cmake/ExecuTorch" +add_library(executorch STATIC IMPORTED) +set_property( + TARGET executorch PROPERTY IMPORTED_LOCATION + "${ET_BUILD_DIR_PATH}/libexecutorch.a" +) + +add_library(executorch_core STATIC IMPORTED) +set_property( + TARGET executorch_core + PROPERTY IMPORTED_LOCATION "${ET_BUILD_DIR_PATH}/libexecutorch_core.a" +) +target_link_libraries(executorch INTERFACE executorch_core) + +add_library(executorch_delegate_ethos_u STATIC IMPORTED) +set_property( + TARGET executorch_delegate_ethos_u + PROPERTY IMPORTED_LOCATION + "${ET_BUILD_DIR_PATH}/backends/arm/libexecutorch_delegate_ethos_u.a" +) + +add_library(portable_ops_lib STATIC IMPORTED) +set_property( + TARGET portable_ops_lib + PROPERTY IMPORTED_LOCATION + "${ET_BUILD_DIR_PATH}/examples/arm/libarm_portable_ops_lib.a" +) +add_library(portable_kernels STATIC IMPORTED) +set_property( + TARGET portable_kernels + PROPERTY IMPORTED_LOCATION + "${ET_BUILD_DIR_PATH}/kernels/portable/libportable_kernels.a" +) +add_library(quantized_ops_lib STATIC IMPORTED) +set_property( + TARGET quantized_ops_lib + PROPERTY IMPORTED_LOCATION + "${ET_BUILD_DIR_PATH}/kernels/quantized/libquantized_ops_lib.a" +) +add_library(quantized_kernels STATIC IMPORTED) +set_property( + TARGET quantized_kernels + PROPERTY IMPORTED_LOCATION + "${ET_BUILD_DIR_PATH}/kernels/quantized/libquantized_kernels.a" +) +add_library(cortex_m_ops_lib STATIC IMPORTED) +set_property( + TARGET cortex_m_ops_lib + PROPERTY IMPORTED_LOCATION + "${ET_BUILD_DIR_PATH}/backends/cortex_m/libcortex_m_ops_lib.a" +) +add_library(cortex_m_kernels STATIC IMPORTED) +set_property( + TARGET cortex_m_kernels + PROPERTY IMPORTED_LOCATION + "${ET_BUILD_DIR_PATH}/backends/cortex_m/libcortex_m_kernels.a" +) +add_library(extension_runner_util STATIC IMPORTED) +set_property( + TARGET extension_runner_util + PROPERTY + IMPORTED_LOCATION + "${ET_BUILD_DIR_PATH}/extension/runner_util/libextension_runner_util.a" ) # Convert pte to header diff --git a/examples/devtools/CMakeLists.txt b/examples/devtools/CMakeLists.txt index 355ff375361..7df0e818328 100644 --- a/examples/devtools/CMakeLists.txt +++ b/examples/devtools/CMakeLists.txt @@ -37,8 +37,6 @@ set(_common_include_directories ${EXECUTORCH_ROOT}/..) # Find prebuilt libraries. executorch package should contain portable_ops_lib, # etdump, bundled_program. find_package(executorch CONFIG REQUIRED) -executorch_target_link_options_shared_lib(executorch) -executorch_target_link_options_shared_lib(portable_ops_lib) target_include_directories(executorch INTERFACE ${_common_include_directories}) diff --git a/examples/models/llama/CMakeLists.txt b/examples/models/llama/CMakeLists.txt index 2cc5902c43a..7f302569c69 100644 --- a/examples/models/llama/CMakeLists.txt +++ b/examples/models/llama/CMakeLists.txt @@ -77,12 +77,8 @@ find_package(gflags REQUIRED) # llama_main: test binary to run llama, with tokenizer and sampler integrated # -# find `executorch` libraries. CMAKE_PREFIX_PATH would work for host -# compilation, but CMAKE_FIND_ROOT_PATH appears to be necessary for -# cross-compiling (e.g., to Android) to work as well. -list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../..) -find_package(executorch CONFIG REQUIRED FIND_ROOT_PATH_BOTH) -executorch_target_link_options_shared_lib(executorch) +set(executorch_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../lib/cmake/ExecuTorch) +find_package(executorch CONFIG REQUIRED) # llama_runner library add_subdirectory(runner) diff --git a/examples/models/llava/CMakeLists.txt b/examples/models/llava/CMakeLists.txt index cf9d54ad3ec..feffe8dcbc8 100644 --- a/examples/models/llava/CMakeLists.txt +++ b/examples/models/llava/CMakeLists.txt @@ -75,9 +75,8 @@ find_package(gflags REQUIRED) # # find `executorch` libraries Same as for gflags -list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../..) -find_package(executorch CONFIG REQUIRED FIND_ROOT_PATH_BOTH) -executorch_target_link_options_shared_lib(executorch) +set(executorch_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../lib/cmake/ExecuTorch) +find_package(executorch CONFIG REQUIRED) # llava_runner library add_subdirectory(runner) diff --git a/examples/models/yolo12/CMakeLists.txt b/examples/models/yolo12/CMakeLists.txt index 60b11685bdf..49625de906a 100644 --- a/examples/models/yolo12/CMakeLists.txt +++ b/examples/models/yolo12/CMakeLists.txt @@ -30,7 +30,6 @@ set(_common_include_directories ${EXECUTORCH_ROOT}/..) # find `executorch` libraries Same as for gflags find_package(executorch CONFIG REQUIRED PATHS ${EXECUTORCH_ROOT}/cmake-out) -executorch_target_link_options_shared_lib(executorch) add_subdirectory(${EXECUTORCH_ROOT}/third-party/gflags gflags) set(link_libraries gflags) diff --git a/extension/android/CMakeLists.txt b/extension/android/CMakeLists.txt index c1fb1125c3e..34a0e49a27f 100644 --- a/extension/android/CMakeLists.txt +++ b/extension/android/CMakeLists.txt @@ -67,7 +67,9 @@ set_target_properties( "${CMAKE_CURRENT_BINARY_DIR}/third-party/fbjni/prefab/modules/fbjni/libs/android.${ANDROID_ABI}/libfbjni.so" ) -executorch_target_link_options_shared_lib(executorch) + +set(executorch_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../lib/cmake/ExecuTorch) +find_package(executorch CONFIG REQUIRED) add_library( executorch_jni SHARED jni/jni_layer.cpp jni/log.cpp jni/jni_layer_runtime.cpp diff --git a/tools/cmake/executorch-config.cmake b/tools/cmake/executorch-config.cmake index 6c27e8ba616..bdf8b03a3ea 100644 --- a/tools/cmake/executorch-config.cmake +++ b/tools/cmake/executorch-config.cmake @@ -48,9 +48,19 @@ foreach(lib ${required_lib_list}) endif() list(APPEND EXECUTORCH_LIBRARIES ${lib}) endforeach() + +# If we reach here, ET required libraries are found. +target_link_libraries(executorch INTERFACE executorch_core) +target_link_options_shared_lib(prim_ops_lib) + set(EXECUTORCH_FOUND ON) -include("${CMAKE_CURRENT_LIST_DIR}/ExecuTorchTargets.cmake") +target_link_libraries(executorch INTERFACE executorch_core) + +# ...existing code... + +# Move target_link_options_shared_lib(prim_ops_lib) to line 177 (after all target_link_libraries for executorch) +target_link_options_shared_lib(prim_ops_lib) set(optional_lib_list flatccrt @@ -88,7 +98,64 @@ set(optional_lib_list torchao_kernels_aarch64 ) -foreach(lib ${optional_lib_list}) +# TODO: investigate use of install(EXPORT) to cleanly handle +# target_compile_options/target_compile_definitions for everything. +if(TARGET cpublas) + set_target_properties( + cpublas PROPERTIES INTERFACE_LINK_LIBRARIES + "extension_threadpool;eigen_blas" + ) +endif() +if(TARGET optimized_kernels) + set_target_properties( + optimized_kernels PROPERTIES INTERFACE_LINK_LIBRARIES + "executorch_core;cpublas;extension_threadpool" + ) +endif() + +if(TARGET coremldelegate) + set_target_properties( + coremldelegate PROPERTIES INTERFACE_LINK_LIBRARIES + "coreml_inmemoryfs;coreml_util" + ) +endif() + +if(TARGET etdump) + set_target_properties(etdump PROPERTIES INTERFACE_LINK_LIBRARIES "flatccrt;executorch") +endif() + +if(TARGET optimized_native_cpu_ops_lib) + if(TARGET optimized_portable_kernels) + set(_maybe_optimized_portable_kernels_lib optimized_portable_kernels) + else() + set(_maybe_optimized_portable_kernels_lib portable_kernels) + endif() + set_target_properties( + optimized_native_cpu_ops_lib + PROPERTIES INTERFACE_LINK_LIBRARIES + "optimized_kernels;${_maybe_optimized_portable_kernels_lib}" + ) +endif() +if(TARGET extension_threadpool) + target_compile_definitions(extension_threadpool INTERFACE ET_USE_THREADPOOL) + set_target_properties( + extension_threadpool PROPERTIES INTERFACE_LINK_LIBRARIES + "cpuinfo;pthreadpool" + ) +endif() + +# target_link_options_shared_lib(prim_ops_lib) is now called automatically in executorch-config.cmake +target_link_options_shared_lib(prim_ops_lib) + +set(shared_lib_list + # executorch -- size tests fail due to regression if we include this and I'm not sure it's needed. + optimized_native_cpu_ops_lib + portable_ops_lib + quantized_ops_lib + xnnpack_backend + vulkan_backend + quantized_ops_aot_lib) +foreach(lib ${shared_lib_list}) if(TARGET ${lib}) list(APPEND EXECUTORCH_LIBRARIES ${lib}) else()