summaryrefslogtreecommitdiff
path: root/externals/CMakeLists.txt
blob: cb4073f98971095e82387b944d69bff485cacb75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
nnfw_find_package(TensorFlowLite QUIET)

if(NOT TensorFlowLite_FOUND)
  return()
endif(NOT TensorFlowLite_FOUND)

if("${TARGET_OS}" STREQUAL "android")
  if(NOT DEFINED NDK_DIR)
    file(GLOB NDK_DIRS "${CMAKE_SOURCE_DIR}/tools/cross/ndk/*")
    list(LENGTH NDK_DIRS NDK_DIRS_COUNT)
    if (NDK_DIRS_COUNT EQUAL 1)
      set(NDK_DIR "${NDK_DIRS}")
    endif(NDK_DIRS_COUNT EQUAL 1)
  endif(NOT DEFINED NDK_DIR)

  if(NOT DEFINED NDK_DIR)
    message(FATAL_ERROR "NDK_DIR should be specified via environment variable")
  endif()
  message(STATUS "Found NDK: ${NDK_DIR}")
  target_include_directories(tensorflow-lite SYSTEM PUBLIC "${NDK_DIR}")
endif()

if("${TARGET_OS}" STREQUAL "android")
  target_link_libraries(tensorflow-lite log)
  #
  # Tensorflow Lite JNI library
  #
  set(TFLITE_JNI_BASE ${TENSORFLOW_LITE_BASE}/java/src/main/native)
  set(TFLITE_JNI_SRCS ${TFLITE_JNI_BASE}/duration_utils_jni.cc
                      ${TFLITE_JNI_BASE}/exception_jni.cc
                      ${TFLITE_JNI_BASE}/nativeinterpreterwrapper_jni.cc
                      ${TFLITE_JNI_BASE}/tensor_jni.cc
                      ${TFLITE_JNI_BASE}/tensorflow_lite_jni.cc
                      ${TFLITE_JNI_BASE}/builtin_ops_jni.cc
                      )
  set(TFLITE_JNI_INCLUDES ${TENSORFLOW_LITE_BASE}/java/src/native)

  # We need this for running vanilla tflite
  # TODO remove this when nnfw is used
  set(TFLITE_SRCS_V ${TENSORFLOW_LITE_BASE}/kernels/register.cc)

  # TODO use tensorflow-lite static library instead of compiling all the sources again
  add_library(tensorflowlite_jni SHARED ${TFLITE_JNI_SRCS} ${TFLITE_SRCS} ${TFLITE_SRCS_V})
  target_include_directories(tensorflowlite_jni PUBLIC ${TFLITE_JNI_INCLUDES} ${TFLITE_INCLUDES})
  target_link_libraries(tensorflowlite_jni eigen ${LIB_PTHREAD} dl)
  target_link_libraries(tensorflowlite_jni log)
  install(TARGETS tensorflowlite_jni DESTINATION lib)
endif()