blob: 907c3847cb601119fcdf1fe8e9c7c09fc3f0fbf8 [file] [log] [blame]
Sadik Armagan3c24f432020-10-19 17:35:30 +01001#
2# Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3# SPDX-License-Identifier: MIT
4#
5
6include(FindPackageHandleStandardArgs)
7unset(TFLITE_FOUND)
8
Jim Flynnfca233e2021-09-23 12:16:53 +01009#
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 Davisd62eef92021-09-20 18:17:33 +010017# First look for the static version of tensorflow lite
18find_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
20find_library(TfLite_LIB NAMES "libtensorflow_lite_all.so" "libtensorflowlite.so" HINTS ${TFLITE_LIB_ROOT} ${TFLITE_LIB_ROOT}/tensorflow/lite)
Sadik Armagan3c24f432020-10-19 17:35:30 +010021
Keith Davisd62eef92021-09-20 18:17:33 +010022# If the static library was found, gather all of its dependencies
23if (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 Armagan3c24f432020-10-19 17:35:30 +010037
Keith Davisd62eef92021-09-20 18:17:33 +010038 ## Set TFLITE_FOUND if all libraries are satisfied for static lib
Jim Flynnfca233e2021-09-23 12:16:53 +010039 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 Davisd62eef92021-09-20 18:17:33 +010040 # 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 Davisd62eef92021-09-20 18:17:33 +010043 endif ()
44elseif (TfLite_LIB MATCHES .so$)
45 message("-- Dynamic tensorflow lite library found, using for ArmNN build")
Jim Flynnfca233e2021-09-23 12:16:53 +010046 find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_LIB)
Keith Davisd62eef92021-09-20 18:17:33 +010047 ## Set external variables for usage in CMakeLists.txt
48 if (TFLITE_FOUND)
49 set(TfLite_LIB ${TfLite_LIB})
Keith Davisd62eef92021-09-20 18:17:33 +010050 endif ()
51else()
52 message(FATAL_ERROR "Could not find a tensorflow lite library to use")
53endif()