1 2# Copyright (c) Meta Platforms, Inc. and affiliates. 3# All rights reserved. 4# 5# This source code is licensed under the BSD-style license found in the 6# LICENSE file in the root directory of this source tree. 7 8# Config defining how CMake should find ExecuTorch package. CMake will search 9# for this file and find ExecuTorch package if it is installed. Typical usage 10# is: 11# 12# find_package(executorch REQUIRED) 13# ------- 14# 15# Finds the ExecuTorch library 16# 17# This will define the following variables: 18# 19# EXECUTORCH_FOUND -- True if the system has the ExecuTorch library 20# EXECUTORCH_INCLUDE_DIRS -- The include directories for ExecuTorch 21# EXECUTORCH_LIBRARIES -- Libraries to link against 22# 23# The actual values for these variables will be different from what executorch-config.cmake 24# in executorch pip package gives, but we wanted to keep the contract of exposing these 25# CMake variables. 26 27cmake_minimum_required(VERSION 3.19) 28 29set(_root "${CMAKE_CURRENT_LIST_DIR}/../..") 30set(required_lib_list executorch executorch_core portable_kernels) 31set(EXECUTORCH_LIBRARIES) 32set(EXECUTORCH_INCLUDE_DIRS ${_root}) 33foreach(lib ${required_lib_list}) 34 set(lib_var "LIB_${lib}") 35 add_library(${lib} STATIC IMPORTED) 36 find_library( 37 ${lib_var} ${lib} 38 HINTS "${_root}" 39 CMAKE_FIND_ROOT_PATH_BOTH 40 ) 41 set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") 42 target_include_directories(${lib} INTERFACE ${_root}) 43 list(APPEND EXECUTORCH_LIBRARIES ${lib}) 44endforeach() 45 46# If we reach here, ET required libraries are found. 47set(EXECUTORCH_FOUND ON) 48 49target_link_libraries(executorch INTERFACE executorch_core) 50 51if(CMAKE_BUILD_TYPE MATCHES "Debug") 52 set(FLATCCRT_LIB flatccrt_d) 53else() 54 set(FLATCCRT_LIB flatccrt) 55endif() 56 57set(lib_list 58 etdump 59 bundled_program 60 extension_data_loader 61 ${FLATCCRT_LIB} 62 coremldelegate 63 mpsdelegate 64 neuron_backend 65 qnn_executorch_backend 66 portable_ops_lib 67 extension_module 68 extension_module_static 69 extension_runner_util 70 extension_tensor 71 extension_threadpool 72 extension_training 73 xnnpack_backend 74 # Start XNNPACK Lib Deps 75 XNNPACK 76 microkernels-prod 77 kleidiai 78 # End XNNPACK Lib Deps 79 cpuinfo 80 pthreadpool 81 vulkan_backend 82 optimized_kernels 83 cpublas 84 eigen_blas 85 optimized_ops_lib 86 optimized_native_cpu_ops_lib 87 quantized_kernels 88 quantized_ops_lib 89 quantized_ops_aot_lib 90) 91foreach(lib ${lib_list}) 92 # Name of the variable which stores result of the find_library search 93 set(lib_var "LIB_${lib}") 94 find_library( 95 ${lib_var} ${lib} 96 HINTS "${_root}" 97 CMAKE_FIND_ROOT_PATH_BOTH 98 ) 99 if(NOT ${lib_var}) 100 message("${lib} library is not found. 101 If needed rebuild with the proper options in CMakeLists.txt" 102 ) 103 else() 104 if("${lib}" STREQUAL "extension_module" AND (NOT CMAKE_TOOLCHAIN_IOS)) 105 add_library(${lib} SHARED IMPORTED) 106 else() 107 # Building a share library on iOS requires code signing, so it's easier to 108 # keep all libs as static when CMAKE_TOOLCHAIN_IOS is used 109 add_library(${lib} STATIC IMPORTED) 110 endif() 111 set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") 112 target_include_directories(${lib} INTERFACE ${_root}) 113 list(APPEND EXECUTORCH_LIBRARIES ${lib}) 114 endif() 115endforeach() 116