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 | |
Jim Flynn | fca233e | 2021-09-23 12:16:53 +0100 | [diff] [blame] | 9 | # |
| 10 | # NOTE: this module is used to find the tensorflow lite binary libraries only |
| 11 | # the FindTfLiteSrc.cmake module is used to find the tensorflow lite include directory. |
| 12 | # This is to allow components like the Tensorflow lite parser that have a source dependency |
| 13 | # on tensorflow lite headers but no need to link to the binary libraries to use only the sources |
| 14 | # and not have an artificial dependency on the libraries. |
| 15 | # |
| 16 | |
Keith Davis | d62eef9 | 2021-09-20 18:17:33 +0100 | [diff] [blame] | 17 | # First look for the static version of tensorflow lite |
| 18 | find_library(TfLite_LIB NAMES "libtensorflow-lite.a" HINTS ${TFLITE_LIB_ROOT} ${TFLITE_LIB_ROOT}/tensorflow/lite) |
| 19 | # If not found then, look for the dynamic library of tensorflow lite |
| 20 | 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] | 21 | |
Keith Davis | d62eef9 | 2021-09-20 18:17:33 +0100 | [diff] [blame] | 22 | # If the static library was found, gather all of its dependencies |
| 23 | if (TfLite_LIB MATCHES .a$) |
| 24 | message("-- Static tensorflow lite library found, using for ArmNN build") |
| 25 | find_library(TfLite_abseilstrings_LIB "libabsl_strings.a" |
| 26 | PATH ${TFLITE_LIB_ROOT}/_deps/abseil-cpp-build/absl/strings) |
| 27 | find_library(TfLite_farmhash_LIB "libfarmhash.a" |
| 28 | PATH ${TFLITE_LIB_ROOT}/_deps/farmhash-build) |
| 29 | find_library(TfLite_fftsg_LIB "libfft2d_fftsg.a" |
| 30 | PATH ${TFLITE_LIB_ROOT}/_deps/fft2d-build) |
| 31 | find_library(TfLite_fftsg2d_LIB "libfft2d_fftsg2d.a" |
| 32 | PATH ${TFLITE_LIB_ROOT}/_deps/fft2d-build) |
| 33 | find_library(TfLite_ruy_LIB "libruy.a" PATH |
| 34 | ${TFLITE_LIB_ROOT}/_deps/ruy-build) |
| 35 | find_library(TfLite_flatbuffers_LIB "libflatbuffers.a" |
| 36 | PATH ${TFLITE_LIB_ROOT}/_deps/flatbuffers-build) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 37 | |
Keith Davis | d62eef9 | 2021-09-20 18:17:33 +0100 | [diff] [blame] | 38 | ## Set TFLITE_FOUND if all libraries are satisfied for static lib |
Jim Flynn | fca233e | 2021-09-23 12:16:53 +0100 | [diff] [blame] | 39 | find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_LIB TfLite_abseilstrings_LIB TfLite_ruy_LIB TfLite_fftsg_LIB TfLite_fftsg2d_LIB TfLite_farmhash_LIB TfLite_flatbuffers_LIB) |
Keith Davis | d62eef9 | 2021-09-20 18:17:33 +0100 | [diff] [blame] | 40 | # Set external variables for usage in CMakeLists.txt |
| 41 | if (TFLITE_FOUND) |
| 42 | set(TfLite_LIB ${TfLite_LIB} ${TfLite_abseilstrings_LIB} ${TfLite_ruy_LIB} ${TfLite_fftsg_LIB} ${TfLite_fftsg2d_LIB} ${TfLite_farmhash_LIB} ${TfLite_flatbuffers_LIB}) |
Keith Davis | d62eef9 | 2021-09-20 18:17:33 +0100 | [diff] [blame] | 43 | endif () |
| 44 | elseif (TfLite_LIB MATCHES .so$) |
| 45 | message("-- Dynamic tensorflow lite library found, using for ArmNN build") |
Jim Flynn | fca233e | 2021-09-23 12:16:53 +0100 | [diff] [blame] | 46 | find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_LIB) |
Keith Davis | d62eef9 | 2021-09-20 18:17:33 +0100 | [diff] [blame] | 47 | ## Set external variables for usage in CMakeLists.txt |
| 48 | if (TFLITE_FOUND) |
| 49 | set(TfLite_LIB ${TfLite_LIB}) |
Keith Davis | d62eef9 | 2021-09-20 18:17:33 +0100 | [diff] [blame] | 50 | endif () |
| 51 | else() |
| 52 | message(FATAL_ERROR "Could not find a tensorflow lite library to use") |
| 53 | endif() |