33
44# File containing various functions for operating on library and executable targets.
55
6+ include_guard (GLOBAL )
7+
68#
79# Converts output file of `target` to binary file and to Intel HEX file.
810#
@@ -189,4 +191,67 @@ endfunction()
189191#
190192function (mbed_finalize_build)
191193 mbed_finalize_ide_debug_configurations()
192- endfunction (mbed_finalize_build)
194+ endfunction (mbed_finalize_build)
195+
196+ # Lists that mbed_disable_mcu_target_file stores data in
197+ set (MBED_DISABLE_MCU_TARGET_FILE_TARGETS "" CACHE INTERNAL "" FORCE)
198+ set (MBED_DISABLE_MCU_TARGET_FILE_FILES "" CACHE INTERNAL "" FORCE)
199+
200+ # Use this function to disable a source file from one of the MCU targets in the targets/ directory.
201+ # This allows you to override this file from a custom target.
202+ # This function may only be used with a target in the mbed-os/targets directory, and may only be
203+ # called after including app.cmake and before adding mbed-os as a subdirectory.
204+ function (mbed_disable_mcu_target_file TARGET FILENAME)
205+
206+ # Record this file for later disablement
207+ set (MBED_DISABLE_MCU_TARGET_FILE_TARGETS ${MBED_DISABLE_MCU_TARGET_FILE_TARGETS} ${TARGET} CACHE INTERNAL "" FORCE)
208+ set (MBED_DISABLE_MCU_TARGET_FILE_FILES ${MBED_DISABLE_MCU_TARGET_FILE_FILES} ${FILENAME} CACHE INTERNAL "" FORCE)
209+
210+ endfunction (mbed_disable_mcu_target_file)
211+
212+ # Called later, midway through the Mbed configure, to apply the file disables that were recorded earlier.
213+ function (mbed_apply_mcu_target_file_disables)
214+
215+ # Iterate through each disable request
216+ list (LENGTH MBED_DISABLE_MCU_TARGET_FILE_TARGETS NUM_DISABLES)
217+ set (DISABLE_IDX 0)
218+ while (DISABLE_IDX LESS NUM_DISABLES)
219+
220+ # Get the target and the file
221+ list (GET MBED_DISABLE_MCU_TARGET_FILE_TARGETS ${DISABLE_IDX} CURR_TARGET)
222+ list (GET MBED_DISABLE_MCU_TARGET_FILE_FILES ${DISABLE_IDX} CURR_FILE)
223+
224+ if (TARGET ${CURR_TARGET} )
225+ get_property (CURR_TARGET_TYPE TARGET ${CURR_TARGET} PROPERTY TYPE )
226+ if ("${CURR_TARGET_TYPE} " STREQUAL "INTERFACE_LIBRARY" )
227+
228+ # Iterate through the list of sources and remove the target one
229+ get_property (CURR_TARGET_IFACE_SOURCES TARGET ${CURR_TARGET} PROPERTY INTERFACE_SOURCES)
230+ set (FOUND FALSE )
231+ foreach (SOURCE_FILE ${CURR_TARGET_IFACE_SOURCES} )
232+ get_filename_component (SOURCE_FILE_NAME ${SOURCE_FILE} NAME )
233+ if ("${SOURCE_FILE_NAME} " STREQUAL CURR_FILE)
234+ set (FOUND TRUE )
235+ list (REMOVE_ITEM CURR_TARGET_IFACE_SOURCES "${SOURCE_FILE} " )
236+ endif ()
237+ endforeach ()
238+
239+ if (FOUND)
240+ message (STATUS "Disabled file '${CURR_FILE} ' in target '${CURR_TARGET} '" )
241+ else ()
242+ message (WARNING "mbed_disable_mcu_target_file(): File '${CURR_FILE} ' not found in target '${CURR_TARGET} '" )
243+ endif ()
244+
245+ set_property (TARGET ${CURR_TARGET} PROPERTY INTERFACE_SOURCES ${CURR_TARGET_IFACE_SOURCES} )
246+
247+ else ()
248+ message (FATAL_ERROR "mbed_disable_mcu_target_file(): Target '${CURR_TARGET} ' is not an interface target." )
249+ endif ()
250+ else ()
251+ message (FATAL_ERROR "mbed_disable_mcu_target_file(): Failed to find target '${CURR_TARGET} '." )
252+ endif ()
253+
254+ math (EXPR DISABLE_IDX "${DISABLE_IDX} + 1" )
255+ endwhile ()
256+
257+ endfunction (mbed_apply_mcu_target_file_disables)
0 commit comments