# Project configuration
option(BUILD_TOOLS "Bulid nnfw projects under tools/" ON)
+CMAKE_DEPENDENT_OPTION(BUILD_ANDROID_TFLITE "Enable android support for TensorFlow Lite"
+ # Enable android support for android build
+ ON "${TARGET_OS} STREQUAL android"
+ # Disable android support otherwise
+ OFF)
# GTest support
option(BUILD_GTEST "Download and build Google Test" ON)
# The original android build script (for future reference)
#
# add_subdirectory(libs)
-# add_subdirectory(externals)
# add_subdirectory(tests/tools/nnapi_test)
# add_subdirectory(tests/tools/tflite_benchmark)
# add_subdirectory(tests/nnapi)
#
# add_subdirectory(runtimes)
-add_subdirectory(externals)
add_subdirectory(contrib)
add_subdirectory(libs)
add_subdirectory(runtimes)
--- /dev/null
+if(NOT BUILD_ANDROID_TFLITE)
+ return()
+endif(NOT BUILD_ANDROID_TFLITE)
+
+nnfw_find_package(TensorFlowLite REQUIRED)
+
+# TODO Set this as system-level global configuration on android build
+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}")
+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)
+++ /dev/null
-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()