From 8988aa5fc161a9f65e4d0bcce513ee3de7b5205f Mon Sep 17 00:00:00 2001 From: Kshitij Sisodia Date: Tue, 15 Jul 2025 20:52:54 +0100 Subject: [PATCH] MLECO-6389: Conditional generic logging for framework TensorFlow Lite Micro based logging uses the overrides for generic Arm Cortex-M CPU targets. This patch ensures that this is the case only when the framework library target is configured internally. This will allow external library targets to be provided without mandating the use of generic Arm Cortex-M target files being included in the build. Change-Id: I022efc9d884d789e22f970e1f6e5ddb5e12efe4f Signed-off-by: Kshitij Sisodia --- source/application/api/fwk/tflm/CMakeLists.txt | 12 ++++++++++++ .../api/fwk/tflm/source/TensorFlowLiteMicro.cc | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/source/application/api/fwk/tflm/CMakeLists.txt b/source/application/api/fwk/tflm/CMakeLists.txt index 6db9b1f..fc092bb 100644 --- a/source/application/api/fwk/tflm/CMakeLists.txt +++ b/source/application/api/fwk/tflm/CMakeLists.txt @@ -35,7 +35,10 @@ endif() # including this project can provide its own version # of the target. if (NOT TARGET google::tensorflow-lite-micro) + set(TFLM_EXTERNAL_TARGET OFF) include(tensorflow_lite_micro) +else() + set(TFLM_EXTERNAL_TARGET ON) endif() # Create static library @@ -66,6 +69,15 @@ target_link_libraries(${ML_FWK_TFLM_TARGET} PUBLIC target_compile_definitions(${ML_FWK_TFLM_TARGET} INTERFACE MLEK_FWK_TFLM=1) +# Set the source file property to indicate that it should not use the logging +# facility from the Cortex-M CPU generic target unless it is an internally +# configured target. Reason: for external target, we can't assume that it +# compiles the sources required. +if (TFLM_EXTERNAL_TARGET) + set_source_files_properties(source/TensorFlowLiteMicro.cc + PROPERTIES COMPILE_DEFINITIONS TFLM_EXTERNAL_TARGET) +endif() + # Display status: message(STATUS "*******************************************************") message(STATUS "Library: " ${ML_FWK_TFLM_TARGET}) diff --git a/source/application/api/fwk/tflm/source/TensorFlowLiteMicro.cc b/source/application/api/fwk/tflm/source/TensorFlowLiteMicro.cc index 1ef0a2f..78515de 100644 --- a/source/application/api/fwk/tflm/source/TensorFlowLiteMicro.cc +++ b/source/application/api/fwk/tflm/source/TensorFlowLiteMicro.cc @@ -20,7 +20,7 @@ /* If target is arm-none-eabi and arch profile is 'M', wire the logging for * TensorFlow Lite Micro */ -#if defined(__arm__) && (__ARM_ARCH_PROFILE == 77) +#if defined(__arm__) && (__ARM_ARCH_PROFILE == 77) && !defined(TFLM_EXTERNAL_TARGET) #include "tensorflow/lite/micro/cortex_m_generic/debug_log_callback.h" #ifdef __cplusplus @@ -39,8 +39,8 @@ void arm::app::fwk::tflm::EnableTFLMLog() RegisterDebugLogCallback(TFLMLog); } -#else /* defined(__arm__) && (__ARM_ARCH_PROFILE == 77) */ +#else /* defined(__arm__) && (__ARM_ARCH_PROFILE == 77) && !defined(TFLM_EXTERNAL_TARGET) */ void arm::app::fwk::tflm::EnableTFLMLog() {} -#endif /* defined(__arm__) && (__ARM_ARCH_PROFILE == 77) */ +#endif /* defined(__arm__) && (__ARM_ARCH_PROFILE == 77) && !defined(TFLM_EXTERNAL_TARGET) */ -- GitLab