CMakeLists.txt 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ## TODO: GLOB is not a good way to collect files. Use explicit file list instead
  2. cmake_minimum_required(VERSION 3.5)
  3. set(tflite_dir "${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite")
  4. set(tfmicro_dir "${tflite_dir}/micro")
  5. set(tfmicro_frontend_dir "${tflite_dir}/experimental/microfrontend/lib")
  6. set(tfmicro_kernels_dir "${tfmicro_dir}/kernels")
  7. file(GLOB srcs_micro
  8. "${tfmicro_dir}/*.cc"
  9. "${tfmicro_dir}/*.c")
  10. file(GLOB src_micro_frontend
  11. "${tfmicro_frontend_dir}/*.c"
  12. "${tfmicro_frontend_dir}/*.cc")
  13. file(GLOB srcs_kernels
  14. "${tfmicro_kernels_dir}/*.c"
  15. "${tfmicro_kernels_dir}/*.cc")
  16. # remove sources which will be provided by esp_nn
  17. list(REMOVE_ITEM srcs_kernels
  18. "${tfmicro_kernels_dir}/add.cc"
  19. "${tfmicro_kernels_dir}/conv.cc"
  20. "${tfmicro_kernels_dir}/depthwise_conv.cc"
  21. "${tfmicro_kernels_dir}/fully_connected.cc"
  22. "${tfmicro_kernels_dir}/mul.cc"
  23. "${tfmicro_kernels_dir}/pooling.cc"
  24. "${tfmicro_kernels_dir}/softmax.cc")
  25. FILE(GLOB esp_nn_kernels
  26. "${tfmicro_kernels_dir}/esp_nn/*.cc")
  27. set(lib_srcs
  28. "${srcs_micro}"
  29. "${srcs_kernels}"
  30. "${esp_nn_kernels}"
  31. "${src_micro_frontend}"
  32. "${tflite_dir}/kernels/kernel_util.cc"
  33. "${tflite_dir}/micro/memory_planner/greedy_memory_planner.cc"
  34. "${tflite_dir}/micro/memory_planner/linear_memory_planner.cc"
  35. "${tflite_dir}/micro/arena_allocator/non_persistent_arena_buffer_allocator.cc"
  36. "${tflite_dir}/micro/arena_allocator/persistent_arena_buffer_allocator.cc"
  37. "${tflite_dir}/micro/arena_allocator/recording_single_arena_buffer_allocator.cc"
  38. "${tflite_dir}/micro/arena_allocator/single_arena_buffer_allocator.cc"
  39. "${tflite_dir}/c/common.cc"
  40. "${tflite_dir}/core/api/error_reporter.cc"
  41. "${tflite_dir}/core/api/flatbuffer_conversions.cc"
  42. "${tflite_dir}/core/api/op_resolver.cc"
  43. "${tflite_dir}/core/api/tensor_utils.cc"
  44. "${tflite_dir}/kernels/internal/quantization_util.cc"
  45. "${tflite_dir}/schema/schema_utils.cc")
  46. set(priv_req esp-nn)
  47. # include component requirements which were introduced after IDF version 4.1
  48. if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "4.1")
  49. list(APPEND priv_req esp_timer driver)
  50. endif()
  51. idf_component_register(
  52. SRCS "${lib_srcs}"
  53. INCLUDE_DIRS "." "third_party/gemmlowp"
  54. "third_party/flatbuffers/include"
  55. "third_party/ruy"
  56. "third_party/kissfft"
  57. REQUIRES ${pub_req}
  58. PRIV_REQUIRES ${priv_req})
  59. # Reduce the level of paranoia to be able to compile TF sources
  60. target_compile_options(${COMPONENT_LIB} PRIVATE
  61. -Wno-maybe-uninitialized
  62. -Wno-missing-field-initializers
  63. -Wno-error=sign-compare
  64. -Wno-error=double-promotion
  65. -DESP_NN # enables ESP-NN optimizations by Espressif
  66. -Wno-type-limits)
  67. target_compile_options(${COMPONENT_LIB} PRIVATE -fno-unwind-tables -ffunction-sections -fdata-sections -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -O3 -Wsign-compare -Wdouble-promotion -Wshadow -Wunused-variable -Wmissing-field-initializers -Wunused-function -Wswitch -Wvla -Wall -Wextra -Wstrict-aliasing -Wno-unused-parameter -Wno-nonnull)
  68. target_compile_options(${COMPONENT_LIB} PRIVATE $<$<COMPILE_LANGUAGE:CXX>: -std=c++11 -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-unwind-tables -ffunction-sections -fdata-sections -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -O3 -Werror -Wsign-compare -Wdouble-promotion -Wshadow -Wunused-variable -Wmissing-field-initializers -Wunused-function -Wswitch -Wvla -Wall -Wextra -Wstrict-aliasing -Wno-unused-parameter -Wno-return-type -Wno-strict-aliasing -std=gnu++14 >)
  69. target_compile_options(${COMPONENT_LIB} INTERFACE $<$<IN_LIST:-DTF_LITE_STATIC_MEMORY,$<TARGET_PROPERTY:${COMPONENT_LIB},COMPILE_OPTIONS>>:-DTF_LITE_STATIC_MEMORY>)
  70. target_link_libraries(${COMPONENT_LIB} PRIVATE -lm)