Make wasi-nn backends as separated shared libraries (#3509)

- All files under *core/iwasm/libraries/wasi-nn* are compiled as shared libraries
- *wasi-nn.c* is shared between backends
- Every backend has a separated shared library
- If wasi-nn feature is enabled, iwasm will depend on shared library libiwasm.so
  instead of linking static library libvmlib.a
This commit is contained in:
liang.he
2024-06-14 12:06:56 +08:00
committed by GitHub
parent 1434c45283
commit f844b33b2d
20 changed files with 296 additions and 258 deletions

View File

@ -6,17 +6,51 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
# Find tensorflow-lite
find_package(tensorflow_lite REQUIRED)
set(WASI_NN_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
set(WASI_NN_ROOT ${CMAKE_CURRENT_LIST_DIR}/..)
include_directories (${WASI_NN_ROOT_DIR}/include)
include_directories (${WASI_NN_ROOT_DIR}/src)
include_directories (${WASI_NN_ROOT_DIR}/src/utils)
set (
WASI_NN_SOURCES
${WASI_NN_ROOT_DIR}/src/wasi_nn.c
${WASI_NN_ROOT_DIR}/src/wasi_nn_tensorflowlite.cpp
${WASI_NN_ROOT_DIR}/src/utils/wasi_nn_app_native.c
#
# wasi-nn general
add_library(
wasi-nn-general
SHARED
${WASI_NN_ROOT}/src/wasi_nn.c
${WASI_NN_ROOT}/src/utils/wasi_nn_app_native.c
)
target_include_directories(
wasi-nn-general
PUBLIC
${WASI_NN_ROOT}/include
${WASI_NN_ROOT}/src
${WASI_NN_ROOT}/src/utils
)
target_link_libraries(
wasi-nn-general
PUBLIC
libiwasm
)
target_compile_definitions(
wasi-nn-general
PUBLIC
$<$<CONFIG:Debug>:NN_LOG_LEVEL=0>
$<$<CONFIG:Release>:NN_LOG_LEVEL=2>
)
set (WASI_NN_LIBS tensorflow-lite)
#
# wasi-nn backends
add_library(
wasi-nn-tflite
SHARED
${WASI_NN_ROOT}/src/wasi_nn_tensorflowlite.cpp
)
#target_link_options(
# wasi-nn-tflite
# PRIVATE
# -Wl,--whole-archive libwasi-nn-general.a
# -Wl,--no-whole-archive
#)
target_link_libraries(
wasi-nn-tflite
PUBLIC
tensorflow-lite
wasi-nn-general
)