blob: 20f93ca4aec2077878f8d6034c4acd01517990cd [file] [log] [blame]
Sadik Armagan3c24f432020-10-19 17:35:30 +01001#
Ryan OShea238ecd92023-03-07 11:44:23 +00002# Copyright © 2020, 2023 Arm Ltd and Contributors. All rights reserved.
Sadik Armagan3c24f432020-10-19 17:35:30 +01003# 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)
Colm Donelan718966f2022-10-10 10:06:12 +010027 find_library(TfLite_abseil_synchronization_LIB "libabsl_synchronization.a"
28 PATH ${TFLITE_LIB_ROOT}/_deps/abseil-cpp-build/absl/synchronization)
Matthew Sloyan76d0c4c2023-09-07 14:48:56 +010029 # Required for building TensorFlow in Debug
30 find_library(TfLite_abseil_graphCycle_internal_LIB "libabsl_graphcycles_internal.a"
31 PATH ${TFLITE_LIB_ROOT}/_deps/abseil-cpp-build/absl/synchronization)
Colm Donelan718966f2022-10-10 10:06:12 +010032
33
Keith Davisd62eef92021-09-20 18:17:33 +010034 find_library(TfLite_farmhash_LIB "libfarmhash.a"
35 PATH ${TFLITE_LIB_ROOT}/_deps/farmhash-build)
36 find_library(TfLite_fftsg_LIB "libfft2d_fftsg.a"
37 PATH ${TFLITE_LIB_ROOT}/_deps/fft2d-build)
38 find_library(TfLite_fftsg2d_LIB "libfft2d_fftsg2d.a"
39 PATH ${TFLITE_LIB_ROOT}/_deps/fft2d-build)
Keith Davisd62eef92021-09-20 18:17:33 +010040 find_library(TfLite_flatbuffers_LIB "libflatbuffers.a"
41 PATH ${TFLITE_LIB_ROOT}/_deps/flatbuffers-build)
Colm Donelan718966f2022-10-10 10:06:12 +010042 find_library(TfLite_cpuinfo_LIB "libcpuinfo.a" PATH
43 ${TFLITE_LIB_ROOT}/_deps/cpuinfo-build)
Colm Donelan718966f2022-10-10 10:06:12 +010044
45 # All remaining libraries are part of libruy.
46 find_library(TfLite_ruy_allocator_LIB "libruy_allocator.a" PATH
47 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
48 find_library(TfLite_ruy_apply_multiplier_LIB "libruy_apply_multiplier.a" PATH
49 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
50 find_library(TfLite_ruy_blocking_counter_LIB "libruy_blocking_counter.a" PATH
51 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
52 find_library(TfLite_ruy_block_map_LIB "libruy_block_map.a" PATH
53 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
54 find_library(TfLite_ruy_context_LIB "libruy_context.a" PATH
55 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
56 find_library(TfLite_ruy_context_get_ctx_LIB "libruy_context_get_ctx.a" PATH
57 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
58 find_library(TfLite_ruy_cpuinfo_LIB "libruy_cpuinfo.a" PATH
59 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
60 find_library(TfLite_ruy_ctx_LIB "libruy_ctx.a" PATH
61 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
62 find_library(TfLite_ruy_denormal_LIB "libruy_denormal.a" PATH
63 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
64 find_library(TfLite_ruy_frontend_LIB "libruy_frontend.a" PATH
65 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
66 find_library(TfLite_ruy_have_built_path_for_avx2_fma_LIB "libruy_have_built_path_for_avx2_fma.a" PATH
67 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
68 find_library(TfLite_ruy_have_built_path_for_avx512_LIB "libruy_have_built_path_for_avx512.a" PATH
69 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
70 find_library(TfLite_ruy_have_built_path_for_avx_LIB "libruy_have_built_path_for_avx.a" PATH
71 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
72 find_library(TfLite_ruy_kernel_arm_LIB "libruy_kernel_arm.a" PATH
73 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
74 find_library(TfLite_ruy_kernel_avx2_fma_LIB "libruy_kernel_avx2_fma.a" PATH
75 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
76 find_library(TfLite_ruy_kernel_avx512_LIB "libruy_kernel_avx512.a" PATH
77 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
78 find_library(TfLite_ruy_kernel_avx_LIB "libruy_kernel_avx.a" PATH
79 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
80 find_library(TfLite_ruy_pack_arm_LIB "libruy_pack_arm.a" PATH
81 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
82 find_library(TfLite_ruy_pack_avx2_fma_LIB "libruy_pack_avx2_fma.a" PATH
83 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
84 find_library(TfLite_ruy_pack_avx512_LIB "libruy_pack_avx512.a" PATH
85 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
86 find_library(TfLite_ruy_pack_avx_LIB "libruy_pack_avx.a" PATH
87 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
88 find_library(TfLite_ruy_prepacked_cache_LIB "libruy_prepacked_cache.a" PATH
89 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
90 find_library(TfLite_ruy_prepare_packed_matrices_LIB "libruy_prepare_packed_matrices.a" PATH
91 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
92 find_library(TfLite_ruy_system_aligned_alloc_LIB "libruy_system_aligned_alloc.a" PATH
93 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
94 find_library(TfLite_ruy_threadpool_LIB "libruy_thread_pool.a" PATH
95 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
96 find_library(TfLite_ruy_trmul_LIB "libruy_trmul.a" PATH
97 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
98 find_library(TfLite_ruy_tune_LIB "libruy_tune.a" PATH
99 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
100 find_library(TfLite_ruy_wait_LIB "libruy_wait.a" PATH
101 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy)
102 find_library(TfLite_ruy_profiler_LIB "libruy_profiler_instrumentation.a" PATH
103 ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy/profiler)
Ryan OShea238ecd92023-03-07 11:44:23 +0000104 find_library(TfLite_pthread_pool_LIB "libpthreadpool.a" PATH
105 ${TFLITE_LIB_ROOT}/pthreadpool)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100106
Keith Davisd62eef92021-09-20 18:17:33 +0100107 ## Set TFLITE_FOUND if all libraries are satisfied for static lib
Colm Donelan718966f2022-10-10 10:06:12 +0100108 find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_LIB TfLite_abseilstrings_LIB TfLite_farmhash_LIB TfLite_fftsg_LIB TfLite_fftsg2d_LIB
109 TfLite_flatbuffers_LIB TfLite_ruy_allocator_LIB TfLite_ruy_apply_multiplier_LIB TfLite_ruy_blocking_counter_LIB
110 TfLite_ruy_block_map_LIB TfLite_ruy_context_LIB TfLite_ruy_context_get_ctx_LIB TfLite_ruy_cpuinfo_LIB
111 TfLite_ruy_ctx_LIB TfLite_ruy_denormal_LIB TfLite_ruy_frontend_LIB TfLite_ruy_have_built_path_for_avx2_fma_LIB
112 TfLite_ruy_have_built_path_for_avx512_LIB TfLite_ruy_have_built_path_for_avx_LIB TfLite_ruy_kernel_arm_LIB
113 TfLite_ruy_kernel_avx2_fma_LIB TfLite_ruy_kernel_avx512_LIB TfLite_ruy_kernel_avx_LIB TfLite_ruy_pack_arm_LIB
114 TfLite_ruy_pack_avx2_fma_LIB TfLite_ruy_pack_avx512_LIB TfLite_ruy_pack_avx_LIB TfLite_ruy_prepacked_cache_LIB
115 TfLite_ruy_prepare_packed_matrices_LIB TfLite_ruy_system_aligned_alloc_LIB TfLite_ruy_threadpool_LIB
Ryan OShea238ecd92023-03-07 11:44:23 +0000116 TfLite_ruy_trmul_LIB TfLite_ruy_tune_LIB TfLite_ruy_wait_LIB TfLite_ruy_profiler_LIB TfLite_cpuinfo_LIB
Matthew Sloyan76d0c4c2023-09-07 14:48:56 +0100117 TfLite_abseil_synchronization_LIB TfLite_abseil_graphCycle_internal_LIB TfLite_pthread_pool_LIB)
Keith Davisd62eef92021-09-20 18:17:33 +0100118 # Set external variables for usage in CMakeLists.txt
119 if (TFLITE_FOUND)
Colm Donelan718966f2022-10-10 10:06:12 +0100120 # WARNING! The order of these libraries is critical. Moving them
121 # around will result in linker errors in DelegateUnitTests.
Colm Donelan88b90252022-10-23 14:02:57 +0100122 set(TfLite_LIB ${TfLite_LIB} ${TfLite_abseilstrings_LIB} ${TfLite_farmhash_LIB} ${TfLite_fftsg_LIB} ${TfLite_fftsg2d_LIB} ${TfLite_flatbuffers_LIB}
123 ${TfLite_ruy_allocator_LIB} ${TfLite_ruy_apply_multiplier_LIB} ${TfLite_ruy_frontend_LIB} ${TfLite_ruy_trmul_LIB}
124 ${TfLite_ruy_threadpool_LIB} ${TfLite_ruy_blocking_counter_LIB} ${TfLite_ruy_block_map_LIB} ${TfLite_ruy_context_LIB}
125 ${TfLite_ruy_context_get_ctx_LIB} ${TfLite_ruy_cpuinfo_LIB} ${TfLite_ruy_ctx_LIB} ${TfLite_ruy_denormal_LIB}
126 ${TfLite_ruy_have_built_path_for_avx2_fma_LIB} ${TfLite_ruy_have_built_path_for_avx512_LIB}
127 ${TfLite_ruy_have_built_path_for_avx_LIB} ${TfLite_ruy_kernel_arm_LIB} ${TfLite_ruy_kernel_avx2_fma_LIB}
128 ${TfLite_ruy_kernel_avx512_LIB} ${TfLite_ruy_kernel_avx_LIB} ${TfLite_ruy_pack_arm_LIB}
129 ${TfLite_ruy_pack_avx2_fma_LIB} ${TfLite_ruy_pack_avx512_LIB} ${TfLite_ruy_pack_avx_LIB} ${TfLite_ruy_prepacked_cache_LIB}
130 ${TfLite_ruy_prepare_packed_matrices_LIB} ${TfLite_ruy_system_aligned_alloc_LIB}
131 ${TfLite_ruy_tune_LIB} ${TfLite_ruy_wait_LIB} ${TfLite_ruy_profiler_LIB}
Matthew Sloyan76d0c4c2023-09-07 14:48:56 +0100132 ${TfLite_cpuinfo_LIB} ${TfLite_abseil_synchronization_LIB} ${TfLite_abseil_graphCycle_internal_LIB} ${TfLite_pthread_pool_LIB})
Keith Davisd62eef92021-09-20 18:17:33 +0100133 endif ()
134elseif (TfLite_LIB MATCHES .so$)
135 message("-- Dynamic tensorflow lite library found, using for ArmNN build")
Jim Flynnfca233e2021-09-23 12:16:53 +0100136 find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_LIB)
Keith Davisd62eef92021-09-20 18:17:33 +0100137 ## Set external variables for usage in CMakeLists.txt
138 if (TFLITE_FOUND)
139 set(TfLite_LIB ${TfLite_LIB})
Keith Davisd62eef92021-09-20 18:17:33 +0100140 endif ()
141else()
142 message(FATAL_ERROR "Could not find a tensorflow lite library to use")
143endif()