|
9 | 9 | # is:
|
10 | 10 | #
|
11 | 11 | # find_package(executorch REQUIRED)
|
12 |
| - |
| 12 | +# ------- |
| 13 | +# |
| 14 | +# Finds the ExecuTorch library |
| 15 | +# |
| 16 | +# This will define the following variables: |
| 17 | +# |
| 18 | +# EXECUTORCH_FOUND -- True if the system has the Torch library |
| 19 | +# EXECUTORCH_INCLUDE_DIRS -- The include directories for torch |
| 20 | +# EXECUTORCH_LIBRARIES -- Libraries to link against |
| 21 | +# |
13 | 22 | cmake_minimum_required(VERSION 3.19)
|
14 | 23 |
|
15 |
| -set(_root "${CMAKE_CURRENT_LIST_DIR}/../..") |
16 |
| -set(required_lib_list executorch executorch_core portable_kernels) |
17 |
| -foreach(lib ${required_lib_list}) |
18 |
| - set(lib_var "LIB_${lib}") |
19 |
| - add_library(${lib} STATIC IMPORTED) |
20 |
| - find_library( |
21 |
| - ${lib_var} ${lib} |
22 |
| - HINTS "${_root}" |
23 |
| - CMAKE_FIND_ROOT_PATH_BOTH |
| 24 | +# Find prebuilt libportable_lib.so. If found, assuming current file is inside |
| 25 | +# a pip package: |
| 26 | +# <site-packages>/executorch/executorch-config.cmake. |
| 27 | +# If not found, assuming current file is inside cmake-out: |
| 28 | +# <cmake-out>/cmake/ExecuTorch/executorch-config.cmake |
| 29 | +find_library(_portable_lib_LIBRARY _portable_lib.so PATHS "${CMAKE_CURRENT_LIST_DIR}/extension/pybindings/") |
| 30 | +message(WARNING "${CMAKE_CURRENT_LIST_DIR}/extension/pybindings/") |
| 31 | +set(EXECUTORCH_LIBRARIES) |
| 32 | +if(_portable_lib_LIBRARY) |
| 33 | + # Assuming current file is <site-packages>/executorch/executorch-config.cmake |
| 34 | + message(WARNING "portable library is found") |
| 35 | + list(APPEND EXECUTORCH_LIBRARIES _portable_lib) |
| 36 | + add_library(_portable_lib STATIC IMPORTED) |
| 37 | + set(EXECUTORCH_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/include) |
| 38 | + set_target_properties(_portable_lib PROPERTIES |
| 39 | + IMPORTED_LOCATION "${_portable_lib_LIBRARY}" |
| 40 | + INTERFACE_INCLUDE_DIRECTORIES "${EXECUTORCH_INCLUDE_DIRS}" |
| 41 | + CXX_STANDARD 17 |
24 | 42 | )
|
25 |
| - set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") |
26 |
| - target_include_directories(${lib} INTERFACE ${_root}) |
27 |
| -endforeach() |
| 43 | +else() |
| 44 | + # Assuming current file is <cmake-out>/cmake/ExecuTorch/executorch-config.cmake |
| 45 | + message(WARNING "portable library is not found") |
| 46 | + set(_root "${CMAKE_CURRENT_LIST_DIR}/../..") |
| 47 | + set(required_lib_list executorch executorch_core portable_kernels) |
| 48 | + foreach(lib ${required_lib_list}) |
| 49 | + set(lib_var "LIB_${lib}") |
| 50 | + add_library(${lib} STATIC IMPORTED) |
| 51 | + find_library( |
| 52 | + ${lib_var} ${lib} |
| 53 | + HINTS "${_root}" |
| 54 | + CMAKE_FIND_ROOT_PATH_BOTH |
| 55 | + ) |
| 56 | + set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") |
| 57 | + target_include_directories(${lib} INTERFACE ${_root}) |
| 58 | + endforeach() |
28 | 59 |
|
29 |
| -target_link_libraries(executorch INTERFACE executorch_core) |
| 60 | + target_link_libraries(executorch INTERFACE executorch_core) |
30 | 61 |
|
31 |
| -if(CMAKE_BUILD_TYPE MATCHES "Debug") |
32 |
| - set(FLATCCRT_LIB flatccrt_d) |
33 |
| -else() |
34 |
| - set(FLATCCRT_LIB flatccrt) |
35 |
| -endif() |
| 62 | + if(CMAKE_BUILD_TYPE MATCHES "Debug") |
| 63 | + set(FLATCCRT_LIB flatccrt_d) |
| 64 | + else() |
| 65 | + set(FLATCCRT_LIB flatccrt) |
| 66 | + endif() |
36 | 67 |
|
37 |
| -set(lib_list |
38 |
| - etdump |
39 |
| - bundled_program |
40 |
| - extension_data_loader |
41 |
| - ${FLATCCRT_LIB} |
42 |
| - coremldelegate |
43 |
| - mpsdelegate |
44 |
| - qnn_executorch_backend |
45 |
| - portable_ops_lib |
46 |
| - extension_module |
47 |
| - extension_module_static |
48 |
| - extension_runner_util |
49 |
| - extension_tensor |
50 |
| - extension_threadpool |
51 |
| - extension_training |
52 |
| - xnnpack_backend |
53 |
| - # Start XNNPACK Lib Deps |
54 |
| - XNNPACK |
55 |
| - microkernels-prod |
56 |
| - kleidiai |
57 |
| - # End XNNPACK Lib Deps |
58 |
| - cpuinfo |
59 |
| - pthreadpool |
60 |
| - vulkan_backend |
61 |
| - optimized_kernels |
62 |
| - cpublas |
63 |
| - eigen_blas |
64 |
| - optimized_ops_lib |
65 |
| - optimized_native_cpu_ops_lib |
66 |
| - quantized_kernels |
67 |
| - quantized_ops_lib |
68 |
| - quantized_ops_aot_lib |
69 |
| -) |
70 |
| -foreach(lib ${lib_list}) |
71 |
| - # Name of the variable which stores result of the find_library search |
72 |
| - set(lib_var "LIB_${lib}") |
73 |
| - find_library( |
74 |
| - ${lib_var} ${lib} |
75 |
| - HINTS "${_root}" |
76 |
| - CMAKE_FIND_ROOT_PATH_BOTH |
| 68 | + set(lib_list |
| 69 | + etdump |
| 70 | + bundled_program |
| 71 | + extension_data_loader |
| 72 | + ${FLATCCRT_LIB} |
| 73 | + coremldelegate |
| 74 | + mpsdelegate |
| 75 | + qnn_executorch_backend |
| 76 | + portable_ops_lib |
| 77 | + extension_module |
| 78 | + extension_module_static |
| 79 | + extension_runner_util |
| 80 | + extension_tensor |
| 81 | + extension_threadpool |
| 82 | + extension_training |
| 83 | + xnnpack_backend |
| 84 | + # Start XNNPACK Lib Deps |
| 85 | + XNNPACK |
| 86 | + microkernels-prod |
| 87 | + kleidiai |
| 88 | + # End XNNPACK Lib Deps |
| 89 | + cpuinfo |
| 90 | + pthreadpool |
| 91 | + vulkan_backend |
| 92 | + optimized_kernels |
| 93 | + cpublas |
| 94 | + eigen_blas |
| 95 | + optimized_ops_lib |
| 96 | + optimized_native_cpu_ops_lib |
| 97 | + quantized_kernels |
| 98 | + quantized_ops_lib |
| 99 | + quantized_ops_aot_lib |
77 | 100 | )
|
78 |
| - if(NOT ${lib_var}) |
79 |
| - message("${lib} library is not found. |
80 |
| - If needed rebuild with the proper options in CMakeLists.txt" |
| 101 | + foreach(lib ${lib_list}) |
| 102 | + # Name of the variable which stores result of the find_library search |
| 103 | + set(lib_var "LIB_${lib}") |
| 104 | + find_library( |
| 105 | + ${lib_var} ${lib} |
| 106 | + HINTS "${_root}" |
| 107 | + CMAKE_FIND_ROOT_PATH_BOTH |
81 | 108 | )
|
82 |
| - else() |
83 |
| - if("${lib}" STREQUAL "extension_module" AND (NOT CMAKE_TOOLCHAIN_IOS)) |
84 |
| - add_library(${lib} SHARED IMPORTED) |
| 109 | + if(NOT ${lib_var}) |
| 110 | + message("${lib} library is not found. |
| 111 | + If needed rebuild with the proper options in CMakeLists.txt" |
| 112 | + ) |
85 | 113 | else()
|
86 |
| - # Building a share library on iOS requires code signing, so it's easier to |
87 |
| - # keep all libs as static when CMAKE_TOOLCHAIN_IOS is used |
88 |
| - add_library(${lib} STATIC IMPORTED) |
| 114 | + if("${lib}" STREQUAL "extension_module" AND (NOT CMAKE_TOOLCHAIN_IOS)) |
| 115 | + add_library(${lib} SHARED IMPORTED) |
| 116 | + else() |
| 117 | + # Building a share library on iOS requires code signing, so it's easier to |
| 118 | + # keep all libs as static when CMAKE_TOOLCHAIN_IOS is used |
| 119 | + add_library(${lib} STATIC IMPORTED) |
| 120 | + endif() |
| 121 | + set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") |
| 122 | + target_include_directories(${lib} INTERFACE ${_root}) |
89 | 123 | endif()
|
90 |
| - set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") |
91 |
| - target_include_directories(${lib} INTERFACE ${_root}) |
92 |
| - endif() |
93 |
| -endforeach() |
| 124 | + endforeach() |
| 125 | +endif() |
0 commit comments