Skip to content

Android custom lib #5501

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
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions extension/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ set(executorch_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../lib/cmake/ExecuTorch)
find_package(executorch CONFIG REQUIRED)
target_link_options_shared_lib(executorch)

add_library(executorch_jni SHARED jni/jni_layer.cpp)

set(link_libraries)
list(
APPEND
Expand Down Expand Up @@ -58,13 +60,21 @@ else()
list(APPEND link_libraries portable_ops_lib portable_kernels)
target_link_options_shared_lib(portable_ops_lib)
endif()

if(TARGET quantized_kernels)
list(APPEND link_libraries quantized_kernels quantized_ops_lib)
target_link_options_shared_lib(quantized_ops_lib)
endif()

if(TARGET qnn_executorch_backend)
list(APPEND link_libraries qnn_executorch_backend)
endif()

if(TARGET xnnpack_backend)
target_link_options_shared_lib(xnnpack_backend)
list(APPEND link_libraries xnnpack_backend XNNPACK pthreadpool cpuinfo)
endif()

if(TARGET vulkan_backend)
target_link_options_shared_lib(vulkan_backend)
list(APPEND link_libraries vulkan_backend)
Expand All @@ -79,7 +89,27 @@ if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
target_link_options_shared_lib(custom_ops)
endif()

add_library(executorch_jni SHARED jni/jni_layer.cpp)
if(TARGET pthreadpool)
target_compile_definitions(executorch_jni PRIVATE ET_USE_THREADPOOL=1)
target_include_directories(
executorch_jni
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../backends/xnnpack/third-party/cpuinfo/include
)
target_include_directories(
executorch_jni
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../backends/xnnpack/third-party/pthreadpool/include
)
endif()

if(EXECUTORCH_JNI_CUSTOM_LIBRARY)
list(APPEND link_libraries ${EXECUTORCH_JNI_CUSTOM_LIBRARY})
target_link_libraries(
executorch_jni -Wl,--whole-archive ${EXECUTORCH_JNI_CUSTOM_LIBRARY}
-Wl,--no-whole-archive
)
endif()

if(EXECUTORCH_BUILD_LLAMA_JNI)
target_sources(executorch_jni PRIVATE jni/jni_layer_llama.cpp)
Expand All @@ -96,29 +126,10 @@ if(EXECUTORCH_BUILD_LLAMA_JNI)
)
endif()

if(TARGET quantized_kernels)
list(APPEND link_libraries quantized_kernels quantized_ops_lib)
target_link_options_shared_lib(quantized_ops_lib)
endif()

target_include_directories(
executorch_jni PRIVATE ${_common_include_directories}
)

target_compile_options(executorch_jni PUBLIC ${_common_compile_options})

target_link_libraries(executorch_jni ${link_libraries})

if(TARGET pthreadpool)
target_compile_definitions(executorch_jni PRIVATE ET_USE_THREADPOOL=1)
target_include_directories(
executorch_jni
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../backends/xnnpack/third-party/cpuinfo/include
)
target_include_directories(
executorch_jni
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../backends/xnnpack/third-party/pthreadpool/include
)
endif()
Loading