Skip to content

Commit 9bd7f46

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Populates EXECUTORCH_LIBRARIES and other variables in executorch-config.cmake (#6204)
Summary: executorch-config.cmake As titled. This PR aligns the behavior of `executorch-config.cmake` (being used by building ET from source) and the behavior of `executorch-wheel-config.cmake` (being used by installing ET from pip), by exposing these variables: * `EXECUTORCH_FOUND` set to `ON` when required libraries are found * `EXECUTORCH_LIBRARIES` a list of targets for installed ET libraries * `EXECUTORCH_INCLUDE_DIRS` a list of directory paths to headers Pull Request resolved: #6204 Reviewed By: metascroy Differential Revision: D64363174 Pulled By: larryliu0820 fbshipit-source-id: a150cd3eacbfc4a6ab2870611b5c3b7f453332fb
1 parent ce767cb commit 9bd7f46

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

build/executorch-config.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,26 @@
1010
# is:
1111
#
1212
# 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.
1326

1427
cmake_minimum_required(VERSION 3.19)
1528

1629
set(_root "${CMAKE_CURRENT_LIST_DIR}/../..")
1730
set(required_lib_list executorch executorch_core portable_kernels)
31+
set(EXECUTORCH_LIBRARIES)
32+
set(EXECUTORCH_INCLUDE_DIRS ${_root})
1833
foreach(lib ${required_lib_list})
1934
set(lib_var "LIB_${lib}")
2035
add_library(${lib} STATIC IMPORTED)
@@ -25,8 +40,12 @@ foreach(lib ${required_lib_list})
2540
)
2641
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}")
2742
target_include_directories(${lib} INTERFACE ${_root})
43+
list(APPEND EXECUTORCH_LIBRARIES ${lib})
2844
endforeach()
2945

46+
# If we reach here, ET required libraries are found.
47+
set(EXECUTORCH_FOUND ON)
48+
3049
target_link_libraries(executorch INTERFACE executorch_core)
3150

3251
if(CMAKE_BUILD_TYPE MATCHES "Debug")
@@ -91,5 +110,6 @@ foreach(lib ${lib_list})
91110
endif()
92111
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}")
93112
target_include_directories(${lib} INTERFACE ${_root})
113+
list(APPEND EXECUTORCH_LIBRARIES ${lib})
94114
endif()
95115
endforeach()

0 commit comments

Comments
 (0)