Ruomei Yan | db7c391 | 2019-03-08 17:50:25 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | if(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 Sloyan | ac001ee | 2021-02-03 10:43:04 +0000 | [diff] [blame] | 9 | ../../include/armnnTfLiteParser/Version.hpp |
Ruomei Yan | db7c391 | 2019-03-08 17:50:25 +0000 | [diff] [blame] | 10 | TfLiteParser.hpp |
| 11 | TfLiteParser.cpp |
| 12 | ) |
| 13 | |
| 14 | add_library_ex(armnnTfLiteParser SHARED ${armnn_tf_lite_parser_sources}) |
| 15 | |
Jim Flynn | fc8d434 | 2021-09-14 17:53:20 +0100 | [diff] [blame] | 16 | # 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 Yan | db7c391 | 2019-03-08 17:50:25 +0000 | [diff] [blame] | 24 | 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 Flynn | fc8d434 | 2021-09-14 17:53:20 +0100 | [diff] [blame] | 30 | |
| 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 Hughes | c3da268 | 2020-01-07 13:26:42 +0000 | [diff] [blame] | 47 | # 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 Flynn | fc8d434 | 2021-09-14 17:53:20 +0100 | [diff] [blame] | 50 | target_link_libraries(armnnTfLiteParser |
| 51 | armnn |
| 52 | tflite_version_headers |
| 53 | ${FLATBUFFERS_LIBRARY}) |
Rob Hughes | c3da268 | 2020-01-07 13:26:42 +0000 | [diff] [blame] | 54 | 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 Flynn | fc8d434 | 2021-09-14 17:53:20 +0100 | [diff] [blame] | 62 | target_link_libraries(armnnTfLiteParser |
| 63 | armnn |
| 64 | tflite_version_headers |
| 65 | debug ${FLATBUFFERS_LIBRARY_DEBUG} |
| 66 | optimized ${FLATBUFFERS_LIBRARY_RELEASE}) |
Rob Hughes | c3da268 | 2020-01-07 13:26:42 +0000 | [diff] [blame] | 67 | endif() |
Matthew Bentham | a7b7928 | 2019-06-03 13:00:50 +0100 | [diff] [blame] | 68 | |
Matthew Sloyan | ac001ee | 2021-02-03 10:43:04 +0000 | [diff] [blame] | 69 | set_target_properties(armnnTfLiteParser PROPERTIES VERSION ${TFLITE_PARSER_LIB_VERSION} SOVERSION ${TFLITE_PARSER_LIB_SOVERSION} ) |
Matteo Martincigh | bccc345 | 2019-10-18 14:59:19 +0100 | [diff] [blame] | 70 | |
Matthew Bentham | a7b7928 | 2019-06-03 13:00:50 +0100 | [diff] [blame] | 71 | install(TARGETS armnnTfLiteParser |
Rob Hughes | 91e1d89 | 2019-08-23 10:11:58 +0100 | [diff] [blame] | 72 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 73 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
Matthew Bentham | a7b7928 | 2019-06-03 13:00:50 +0100 | [diff] [blame] | 74 | endif() |