Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 1 | # |
| 2 | # Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | |
| 6 | include(FindPackageHandleStandardArgs) |
| 7 | unset(TFLITE_FOUND) |
| 8 | |
Keith Davis | d62eef9 | 2021-09-20 18:17:33 +0100 | [diff] [blame^] | 9 | # First look for the static version of tensorflow lite |
| 10 | find_library(TfLite_LIB NAMES "libtensorflow-lite.a" HINTS ${TFLITE_LIB_ROOT} ${TFLITE_LIB_ROOT}/tensorflow/lite) |
| 11 | # If not found then, look for the dynamic library of tensorflow lite |
| 12 | find_library(TfLite_LIB NAMES "libtensorflow_lite_all.so" "libtensorflowlite.so" HINTS ${TFLITE_LIB_ROOT} ${TFLITE_LIB_ROOT}/tensorflow/lite) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 13 | |
Keith Davis | d62eef9 | 2021-09-20 18:17:33 +0100 | [diff] [blame^] | 14 | # Set relevant paths |
| 15 | find_path(TfLite_INCLUDE_DIR NAMES tensorflow/lite third_party HINTS ${TENSORFLOW_ROOT}) |
| 16 | find_path(TfLite_Schema_INCLUDE_PATH schema_generated.h HINTS ${TENSORFLOW_ROOT}/tensorflow/lite/schema) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 17 | |
Keith Davis | d62eef9 | 2021-09-20 18:17:33 +0100 | [diff] [blame^] | 18 | # If the static library was found, gather all of its dependencies |
| 19 | if (TfLite_LIB MATCHES .a$) |
| 20 | message("-- Static tensorflow lite library found, using for ArmNN build") |
| 21 | find_library(TfLite_abseilstrings_LIB "libabsl_strings.a" |
| 22 | PATH ${TFLITE_LIB_ROOT}/_deps/abseil-cpp-build/absl/strings) |
| 23 | find_library(TfLite_farmhash_LIB "libfarmhash.a" |
| 24 | PATH ${TFLITE_LIB_ROOT}/_deps/farmhash-build) |
| 25 | find_library(TfLite_fftsg_LIB "libfft2d_fftsg.a" |
| 26 | PATH ${TFLITE_LIB_ROOT}/_deps/fft2d-build) |
| 27 | find_library(TfLite_fftsg2d_LIB "libfft2d_fftsg2d.a" |
| 28 | PATH ${TFLITE_LIB_ROOT}/_deps/fft2d-build) |
| 29 | find_library(TfLite_ruy_LIB "libruy.a" PATH |
| 30 | ${TFLITE_LIB_ROOT}/_deps/ruy-build) |
| 31 | find_library(TfLite_flatbuffers_LIB "libflatbuffers.a" |
| 32 | PATH ${TFLITE_LIB_ROOT}/_deps/flatbuffers-build) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 33 | |
Keith Davis | d62eef9 | 2021-09-20 18:17:33 +0100 | [diff] [blame^] | 34 | ## Set TFLITE_FOUND if all libraries are satisfied for static lib |
| 35 | find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_INCLUDE_DIR TfLite_LIB TfLite_abseilstrings_LIB TfLite_ruy_LIB TfLite_fftsg_LIB TfLite_fftsg2d_LIB TfLite_farmhash_LIB TfLite_flatbuffers_LIB TfLite_Schema_INCLUDE_PATH) |
| 36 | # Set external variables for usage in CMakeLists.txt |
| 37 | if (TFLITE_FOUND) |
| 38 | set(TfLite_LIB ${TfLite_LIB} ${TfLite_abseilstrings_LIB} ${TfLite_ruy_LIB} ${TfLite_fftsg_LIB} ${TfLite_fftsg2d_LIB} ${TfLite_farmhash_LIB} ${TfLite_flatbuffers_LIB}) |
| 39 | set(TfLite_INCLUDE_DIR ${TfLite_INCLUDE_DIR}) |
| 40 | set(TfLite_Schema_INCLUDE_PATH ${TfLite_Schema_INCLUDE_PATH}) |
| 41 | endif () |
| 42 | elseif (TfLite_LIB MATCHES .so$) |
| 43 | message("-- Dynamic tensorflow lite library found, using for ArmNN build") |
| 44 | find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_INCLUDE_DIR TfLite_LIB TfLite_Schema_INCLUDE_PATH) |
| 45 | ## Set external variables for usage in CMakeLists.txt |
| 46 | if (TFLITE_FOUND) |
| 47 | set(TfLite_LIB ${TfLite_LIB}) |
| 48 | set(TfLite_INCLUDE_DIR ${TfLite_INCLUDE_DIR}) |
| 49 | set(TfLite_Schema_INCLUDE_PATH ${TfLite_Schema_INCLUDE_PATH}) |
| 50 | endif () |
| 51 | else() |
| 52 | message(FATAL_ERROR "Could not find a tensorflow lite library to use") |
| 53 | endif() |