blob: 1fbd8b845a3f5998d0fd856c0007beeefe015c3a [file] [log] [blame]
Ruomei Yandb7c3912019-03-08 17:50:25 +00001#
2# Copyright © 2017 Arm Ltd. All rights reserved.
3# SPDX-License-Identifier: MIT
4#
5if(BUILD_TF_LITE_PARSER)
6 set(armnn_tf_lite_parser_sources)
7 list(APPEND armnn_tf_lite_parser_sources
8 ../../include/armnnTfLiteParser/ITfLiteParser.hpp
Matthew Sloyanac001ee2021-02-03 10:43:04 +00009 ../../include/armnnTfLiteParser/Version.hpp
Ruomei Yandb7c3912019-03-08 17:50:25 +000010 TfLiteParser.hpp
11 TfLiteParser.cpp
12 )
13
14 add_library_ex(armnnTfLiteParser SHARED ${armnn_tf_lite_parser_sources})
15
Jim Flynnfc8d4342021-09-14 17:53:20 +010016 # NOTE: even though the tensorflow sources contain a ./tensorflow/lite/schema/schema_generated.h
17 # file we cannot use this directly because we need to take packaging for linux distros into
18 # account. On Ubuntu 20.04 the available package is flatbuffers 1.11 and on 21.10 it is 1.12
19 # despite the minor versioning they are not backward compatible. The current tensorflow lite
20 # source (v2.3-v2.5) is generated from 1.12... so we need to generate from the
21 # ./tensorflow/lite/schema/schema.fbs in the tensorflow lite source using the flatc matching
22 # the target platform but use the ./tensorflow/lite/version.h to determine which version of
23 # tensorflow lite the header was generated from.
Ruomei Yandb7c3912019-03-08 17:50:25 +000024 include_directories(SYSTEM "${FLATBUFFERS_INCLUDE_PATH}")
25 set_target_properties(armnnTfLiteParser PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
26 target_include_directories(armnnTfLiteParser PRIVATE ../armnn)
27 target_include_directories(armnnTfLiteParser PRIVATE ../armnnUtils)
28 target_include_directories(armnnTfLiteParser SYSTEM PRIVATE "${TF_LITE_SCHEMA_INCLUDE_PATH}")
29
Jim Flynnfc8d4342021-09-14 17:53:20 +010030
31 # using the armnn/delegate/cmake/Modules/FindTfLite.cmake to find the TfLite sources
32 # so that we can use the tensorflow/lite/version.h to determine which version of
33 # tensorflow lite we are compiling against
34 find_package(TfLite REQUIRED MODULE)
35
36 # Various tflite header files are not warning clean
37 # We can't change compilation flags on header files directly, so we need to add them to an interface library first
38 add_library(tflite_version_headers INTERFACE)
39 target_include_directories(tflite_version_headers INTERFACE $<BUILD_INTERFACE:${TfLite_INCLUDE_DIR}>
40 $<INSTALL_INTERFACE:include/tflite_version_headers>)
41
42 target_compile_options(tflite_version_headers INTERFACE -Wno-conversion
43 -Wno-sign-conversion
44 -Wno-unused-parameter
45 -Wno-unused-function)
46
Rob Hughesc3da2682020-01-07 13:26:42 +000047 # If user has explicitly specified flatbuffers lib then use that,
48 # otherwise search for it based on FLATBUFFERS_BUILD_DIR
49 if (FLATBUFFERS_LIBRARY)
Jim Flynnfc8d4342021-09-14 17:53:20 +010050 target_link_libraries(armnnTfLiteParser
51 armnn
52 tflite_version_headers
53 ${FLATBUFFERS_LIBRARY})
Rob Hughesc3da2682020-01-07 13:26:42 +000054 else()
55 # Use PATH_SUFFIXES to help find separate libs for debug/release on Windows builds
56 find_library(FLATBUFFERS_LIBRARY_DEBUG NAMES flatbuffers
57 HINTS ${FLATBUFFERS_BUILD_DIR}
58 PATH_SUFFIXES "Debug")
59 find_library(FLATBUFFERS_LIBRARY_RELEASE NAMES flatbuffers
60 HINTS ${FLATBUFFERS_BUILD_DIR}
61 PATH_SUFFIXES "Release")
Jim Flynnfc8d4342021-09-14 17:53:20 +010062 target_link_libraries(armnnTfLiteParser
63 armnn
64 tflite_version_headers
65 debug ${FLATBUFFERS_LIBRARY_DEBUG}
66 optimized ${FLATBUFFERS_LIBRARY_RELEASE})
Rob Hughesc3da2682020-01-07 13:26:42 +000067 endif()
Matthew Benthama7b79282019-06-03 13:00:50 +010068
Matthew Sloyanac001ee2021-02-03 10:43:04 +000069 set_target_properties(armnnTfLiteParser PROPERTIES VERSION ${TFLITE_PARSER_LIB_VERSION} SOVERSION ${TFLITE_PARSER_LIB_SOVERSION} )
Matteo Martincighbccc3452019-10-18 14:59:19 +010070
Matthew Benthama7b79282019-06-03 13:00:50 +010071 install(TARGETS armnnTfLiteParser
Rob Hughes91e1d892019-08-23 10:11:58 +010072 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
73 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Matthew Benthama7b79282019-06-03 13:00:50 +010074endif()