-
Notifications
You must be signed in to change notification settings - Fork 608
[pybind] Find portable_lib.so in pip package during cmake build #5961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,85 +9,117 @@ | |
# is: | ||
# | ||
# find_package(executorch REQUIRED) | ||
|
||
# ------- | ||
# | ||
# Finds the ExecuTorch library | ||
# | ||
# This will define the following variables: | ||
# | ||
# EXECUTORCH_FOUND -- True if the system has the Torch library | ||
# EXECUTORCH_INCLUDE_DIRS -- The include directories for torch | ||
larryliu0820 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# EXECUTORCH_LIBRARIES -- Libraries to link against | ||
# | ||
cmake_minimum_required(VERSION 3.19) | ||
|
||
set(_root "${CMAKE_CURRENT_LIST_DIR}/../..") | ||
set(required_lib_list executorch executorch_core portable_kernels) | ||
foreach(lib ${required_lib_list}) | ||
set(lib_var "LIB_${lib}") | ||
add_library(${lib} STATIC IMPORTED) | ||
find_library( | ||
${lib_var} ${lib} | ||
HINTS "${_root}" | ||
CMAKE_FIND_ROOT_PATH_BOTH | ||
# Find prebuilt libportable_lib.so. If found, assuming current file is inside | ||
# a pip package: | ||
# <site-packages>/executorch/executorch-config.cmake. | ||
# If not found, assuming current file is inside cmake-out: | ||
# <cmake-out>/cmake/ExecuTorch/executorch-config.cmake | ||
find_library(_portable_lib_LIBRARY _portable_lib.so PATHS "${CMAKE_CURRENT_LIST_DIR}/extension/pybindings/") | ||
larryliu0820 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
message(WARNING "${CMAKE_CURRENT_LIST_DIR}/extension/pybindings/") | ||
larryliu0820 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
set(EXECUTORCH_LIBRARIES) | ||
if(_portable_lib_LIBRARY) | ||
# Assuming current file is <site-packages>/executorch/executorch-config.cmake | ||
message(WARNING "portable library is found") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of these should use STATUS instead of WARNING since they're just informational |
||
list(APPEND EXECUTORCH_LIBRARIES _portable_lib) | ||
add_library(_portable_lib STATIC IMPORTED) | ||
set(EXECUTORCH_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/include) | ||
set_target_properties(_portable_lib PROPERTIES | ||
IMPORTED_LOCATION "${_portable_lib_LIBRARY}" | ||
INTERFACE_INCLUDE_DIRECTORIES "${EXECUTORCH_INCLUDE_DIRS}" | ||
CXX_STANDARD 17 | ||
) | ||
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") | ||
target_include_directories(${lib} INTERFACE ${_root}) | ||
endforeach() | ||
else() | ||
# Assuming current file is <cmake-out>/cmake/ExecuTorch/executorch-config.cmake | ||
message(WARNING "portable library is not found") | ||
set(_root "${CMAKE_CURRENT_LIST_DIR}/../..") | ||
set(required_lib_list executorch executorch_core portable_kernels) | ||
foreach(lib ${required_lib_list}) | ||
set(lib_var "LIB_${lib}") | ||
add_library(${lib} STATIC IMPORTED) | ||
find_library( | ||
${lib_var} ${lib} | ||
HINTS "${_root}" | ||
CMAKE_FIND_ROOT_PATH_BOTH | ||
) | ||
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") | ||
target_include_directories(${lib} INTERFACE ${_root}) | ||
endforeach() | ||
|
||
target_link_libraries(executorch INTERFACE executorch_core) | ||
target_link_libraries(executorch INTERFACE executorch_core) | ||
|
||
if(CMAKE_BUILD_TYPE MATCHES "Debug") | ||
set(FLATCCRT_LIB flatccrt_d) | ||
else() | ||
set(FLATCCRT_LIB flatccrt) | ||
endif() | ||
if(CMAKE_BUILD_TYPE MATCHES "Debug") | ||
set(FLATCCRT_LIB flatccrt_d) | ||
else() | ||
set(FLATCCRT_LIB flatccrt) | ||
endif() | ||
|
||
set(lib_list | ||
etdump | ||
bundled_program | ||
extension_data_loader | ||
${FLATCCRT_LIB} | ||
coremldelegate | ||
mpsdelegate | ||
qnn_executorch_backend | ||
portable_ops_lib | ||
extension_module | ||
extension_module_static | ||
extension_runner_util | ||
extension_tensor | ||
extension_threadpool | ||
extension_training | ||
xnnpack_backend | ||
# Start XNNPACK Lib Deps | ||
XNNPACK | ||
microkernels-prod | ||
kleidiai | ||
# End XNNPACK Lib Deps | ||
cpuinfo | ||
pthreadpool | ||
vulkan_backend | ||
optimized_kernels | ||
cpublas | ||
eigen_blas | ||
optimized_ops_lib | ||
optimized_native_cpu_ops_lib | ||
quantized_kernels | ||
quantized_ops_lib | ||
quantized_ops_aot_lib | ||
) | ||
foreach(lib ${lib_list}) | ||
# Name of the variable which stores result of the find_library search | ||
set(lib_var "LIB_${lib}") | ||
find_library( | ||
${lib_var} ${lib} | ||
HINTS "${_root}" | ||
CMAKE_FIND_ROOT_PATH_BOTH | ||
set(lib_list | ||
etdump | ||
bundled_program | ||
extension_data_loader | ||
${FLATCCRT_LIB} | ||
coremldelegate | ||
mpsdelegate | ||
qnn_executorch_backend | ||
portable_ops_lib | ||
extension_module | ||
extension_module_static | ||
extension_runner_util | ||
extension_tensor | ||
extension_threadpool | ||
extension_training | ||
xnnpack_backend | ||
# Start XNNPACK Lib Deps | ||
XNNPACK | ||
microkernels-prod | ||
kleidiai | ||
# End XNNPACK Lib Deps | ||
cpuinfo | ||
pthreadpool | ||
vulkan_backend | ||
optimized_kernels | ||
cpublas | ||
eigen_blas | ||
optimized_ops_lib | ||
optimized_native_cpu_ops_lib | ||
quantized_kernels | ||
quantized_ops_lib | ||
quantized_ops_aot_lib | ||
) | ||
if(NOT ${lib_var}) | ||
message("${lib} library is not found. | ||
If needed rebuild with the proper options in CMakeLists.txt" | ||
foreach(lib ${lib_list}) | ||
# Name of the variable which stores result of the find_library search | ||
set(lib_var "LIB_${lib}") | ||
find_library( | ||
${lib_var} ${lib} | ||
HINTS "${_root}" | ||
CMAKE_FIND_ROOT_PATH_BOTH | ||
) | ||
else() | ||
if("${lib}" STREQUAL "extension_module" AND (NOT CMAKE_TOOLCHAIN_IOS)) | ||
add_library(${lib} SHARED IMPORTED) | ||
if(NOT ${lib_var}) | ||
message("${lib} library is not found. | ||
If needed rebuild with the proper options in CMakeLists.txt" | ||
) | ||
else() | ||
# Building a share library on iOS requires code signing, so it's easier to | ||
# keep all libs as static when CMAKE_TOOLCHAIN_IOS is used | ||
add_library(${lib} STATIC IMPORTED) | ||
if("${lib}" STREQUAL "extension_module" AND (NOT CMAKE_TOOLCHAIN_IOS)) | ||
add_library(${lib} SHARED IMPORTED) | ||
else() | ||
# Building a share library on iOS requires code signing, so it's easier to | ||
# keep all libs as static when CMAKE_TOOLCHAIN_IOS is used | ||
add_library(${lib} STATIC IMPORTED) | ||
endif() | ||
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") | ||
target_include_directories(${lib} INTERFACE ${_root}) | ||
endif() | ||
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}") | ||
target_include_directories(${lib} INTERFACE ${_root}) | ||
endif() | ||
endforeach() | ||
endforeach() | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.