|
1 | | -include(FetchContent) |
2 | | - |
3 | | -set(TFLITE_TAG "v${TFLITE_VERSION}") |
4 | | - |
5 | | -message(STATUS "Fetching TFLite ${TFLITE_TAG}...") |
6 | | - |
7 | | -# static linking makes life with TFLite much easier |
8 | | -set(TFLITE_C_BUILD_SHARED_LIBS OFF) |
9 | | - |
10 | | -# We don't care about comparing against these delegates (yet), |
11 | | -# and disabling it reduces compile time meaningfully |
12 | | -set(TFLITE_ENABLE_RUY OFF) |
13 | | -set(TFLITE_ENABLE_XNNPACK OFF) |
14 | | - |
15 | | -# Also have to disable some stuff dragged in by TFLite |
16 | | -set(FLATBUFFERS_BUILD_TESTS OFF) |
17 | | -set(FLATBUFFERS_INSTALL OFF) |
18 | | -set(FLATBUFFERS_BUILD_FLATC OFF) |
19 | | - |
20 | | -# Enable this to see details about downloading -- useful for debugging |
21 | | -# set(FETCHCONTENT_QUIET NO) |
22 | | - |
23 | | -# tflite includes neon2sse transitively, but it's pinned to an old version |
24 | | -# that declares a minimum CMake version of 3.0. We override it here to a |
25 | | -# new enough version that CMake 4+ won't refuse to build it. |
26 | | -FetchContent_Declare( |
27 | | - neon2sse |
28 | | - GIT_REPOSITORY https://github.com/intel/ARM_NEON_2_x86_SSE |
29 | | - GIT_TAG 4732aac1e6c02984a12635d85c4644c2ffe585ca |
| 1 | +add_library(tflite_parser STATIC tflite_parser.cpp) |
| 2 | +target_sources( |
| 3 | + tflite_parser |
| 4 | + PUBLIC |
| 5 | + FILE_SET HEADERS |
| 6 | + FILES tflite_parser.h |
30 | 7 | ) |
31 | | - |
32 | | -FetchContent_Declare( |
33 | | - tflite |
34 | | - GIT_REPOSITORY https://github.com/tensorflow/tensorflow |
35 | | - GIT_TAG ${TFLITE_TAG} |
36 | | - GIT_SHALLOW TRUE |
37 | | - SOURCE_SUBDIR tensorflow/lite/c |
| 8 | +target_link_libraries( |
| 9 | + tflite_parser |
| 10 | + PUBLIC hannk_headers tensorflow-lite::tensorflow-lite interpreter |
| 11 | + PRIVATE Halide::Runtime |
38 | 12 | ) |
39 | | - |
40 | | -block(SCOPE_FOR POLICIES VARIABLES) |
41 | | - # Suppress warnings about rotting CMake code we don't control |
42 | | - set(CMAKE_POLICY_DEFAULT_CMP0135 OLD) # DOWNLOAD_EXTRACT_TIMESTAMP |
43 | | - set(CMAKE_POLICY_DEFAULT_CMP0169 OLD) # FetchContent_Populate |
44 | | - set(CMAKE_POLICY_DEFAULT_CMP0177 OLD) # install() path normalization |
45 | | - |
46 | | - # Configuration for tflite + upstream deps |
47 | | - set(ABSL_PROPAGATE_CXX_STD ON) |
48 | | - |
49 | | - # Suppress warnings in tflite code |
50 | | - add_compile_options( |
51 | | - $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-anon-enum-enum-conversion> |
52 | | - $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-deprecated-this-capture> |
53 | | - $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-shadow-uncaptured-local> |
54 | | - $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-shadow> |
55 | | - $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-tautological-type-limit-compare> |
56 | | - $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unused-template> |
57 | | - ) |
58 | | - |
59 | | - FetchContent_MakeAvailable(tflite) |
60 | | - |
61 | | - set_property(TARGET tensorflowlite_c PROPERTY EXCLUDE_FROM_ALL TRUE) |
62 | | -endblock() |
63 | | - |
64 | | -FetchContent_GetProperties(tflite) |
65 | | - |
66 | | -# Make an interface library that is just to get the tflite headers, |
67 | | -# without any implied linkage |
68 | | -add_library(tensorflowlite_headers INTERFACE) |
69 | | -target_include_directories(tensorflowlite_headers INTERFACE |
70 | | - $<BUILD_INTERFACE:${tflite_SOURCE_DIR}>) |
71 | | - |
72 | | -# ---------------- |
73 | | -add_library(tflite_parser STATIC tflite_parser.cpp) |
74 | | -target_include_directories(tflite_parser |
75 | | - PUBLIC $<BUILD_INTERFACE:${hannk_SOURCE_DIR}> |
76 | | - PRIVATE $<BUILD_INTERFACE:${hannk_BINARY_DIR}> |
77 | | - $<BUILD_INTERFACE:${tflite_SOURCE_DIR}>) |
78 | | -# Ensure that the includes from TFLite's captive flatbuffer library get precedence; |
79 | | -# in case the system may have a too-old version installed. |
80 | | -target_include_directories(tflite_parser BEFORE |
81 | | - PRIVATE $<BUILD_INTERFACE:${FlatBuffers_SOURCE_DIR}/include>) |
82 | | -target_link_libraries(tflite_parser PRIVATE Halide::Runtime) |
0 commit comments