forked from cpetig/tflite_micro_compiler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
90 lines (76 loc) · 2.51 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
CMAKE_MINIMUM_REQUIRED(VERSION 3.13 FATAL_ERROR)
PROJECT(tflite_micro_compiler)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
IF(NOT TF_DIR)
SET(TF_DIR "../tensorflow" CACHE STRING "TensorFlow source directory")
ENDIF()
GET_FILENAME_COMPONENT(tf_fullpath ${TF_DIR} REALPATH)
IF(NOT GET_TF_SRC)
if(EXISTS "${tf_fullpath}")
SET(TFL_SRC ${TF_DIR}/tensorflow/lite)
SET(TFLM_SRC ${TFL_SRC}/micro)
SET(TFLMD_SRC ${TFLM_SRC}/tools/make/downloads)
SET(TF_INCS
${TF_DIR}
${TFLMD_SRC}/flatbuffers/include
${TFLMD_SRC}/ruy
)
ELSE()
MESSAGE(FATAL_ERROR "\
No valid TensorFlow source directory provided, default path \
'../tensorflow' is also not valid. To automatically pull TensorFlow \
source please provide argument '-DGET_TF_SRC=ON' to CMake.\
")
ENDIF()
ELSE()
FIND_PACKAGE(TFLite REQUIRED)
SET(TF_INCS
${TFLite_INCLUDE_DIRS}
)
ENDIF()
SET(TF_LIB tensorflow-microlite)
SET(COMPILER_HEADERS
${PROJECT_SOURCE_DIR}/src/CodeWriter.h
${PROJECT_SOURCE_DIR}/src/Compiler.h
${PROJECT_SOURCE_DIR}/src/CustomOperators.h
${PROJECT_SOURCE_DIR}/src/MemMap.h
${PROJECT_SOURCE_DIR}/src/RecordAllocations.h
${PROJECT_SOURCE_DIR}/src/TypeToString.h
)
SET(COMPILER_SRCS
${PROJECT_SOURCE_DIR}/src/CodeWriter.cpp
${PROJECT_SOURCE_DIR}/src/Compiler.cpp
${PROJECT_SOURCE_DIR}/src/CustomOperators.cpp
${PROJECT_SOURCE_DIR}/src/MemMap.cpp
${PROJECT_SOURCE_DIR}/src/RecordAllocations.cpp
${PROJECT_SOURCE_DIR}/src/TypeToString.cpp
${PROJECT_SOURCE_DIR}/src/main.cpp
)
ADD_LIBRARY(${PROJECT_NAME} STATIC
${COMPILER_SRCS}
)
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC
${TF_INCS}
)
IF(WIN32)
TARGET_LINK_DIRECTORIES(${PROJECT_NAME} PUBLIC ${TFLM_SRC}/tools/make/gen/windows_x86_64/lib)
ELSE()
TARGET_LINK_DIRECTORIES(${PROJECT_NAME} PUBLIC ${TFLM_SRC}/tools/make/gen/linux_x86_64/lib)
ENDIF()
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${TF_LIB})
TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} PUBLIC
TF_LITE_STATIC_MEMORY
TF_LITE_DISABLE_X86_NEON
SUFFICIENT_ARENA_SIZE=128*1024*1024
)
TARGET_COMPILE_FEATURES(${PROJECT_NAME} PUBLIC cxx_std_14)
ADD_EXECUTABLE(compiler src/main.cpp)
TARGET_LINK_LIBRARIES(compiler ${PROJECT_NAME} ${CMAKE_DL_LIBS})
ADD_CUSTOM_TARGET(
format
COMMAND clang-format -i ${COMPILER_SRCS} ${COMPILER_HEADERS}
)
IF(TF_EXAMPLES)
ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/examples)
ENDIF()