@@ -21,20 +21,19 @@ endfunction(mbed_set_linker_script)
2121# Set up the linker script for the top-level Mbed OS targets.
2222# If needed, this also creates another target to preprocess the linker script.
2323#
24- # mbed_os_target: CMake target for Mbed OS
25- # mbed_baremetal_target: CMake target for Mbed Baremetal
24+ # mbed_os_target: CMake target for Mbed OS core library
2625# target_defines_header: the full path to the header containing all of the Mbed target defines
2726#
28- function (mbed_setup_linker_script mbed_os_target mbed_baremetal_target target_defines_header)
27+ function (mbed_setup_linker_script mbed_os_target target_defines_header)
2928
3029 # Find the path to the desired linker script
3130 # (the property should be set on both the OS and baremetal targets in a sane world)
32- get_property (RAW_LINKER_SCRIPT_PATHS_SET TARGET ${mbed_baremetal_target } PROPERTY INTERFACE_MBED_LINKER_SCRIPT SET)
31+ get_property (RAW_LINKER_SCRIPT_PATHS_SET TARGET ${mbed_os_target } PROPERTY INTERFACE_MBED_LINKER_SCRIPT SET)
3332 if (NOT RAW_LINKER_SCRIPT_PATHS_SET)
3433 message (FATAL_ERROR "No linker script has been set for the Mbed target. Ensure that code is calling mbed_set_linker_script() for the mbed-<your-board-name> target or one of its parents" )
3534 endif ()
3635
37- get_property (RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_baremetal_target } PROPERTY INTERFACE_MBED_LINKER_SCRIPT)
36+ get_property (RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_os_target } PROPERTY INTERFACE_MBED_LINKER_SCRIPT)
3837
3938 # Check if two (or more) different linker scripts got used
4039 list (REMOVE_DUPLICATES RAW_LINKER_SCRIPT_PATHS)
@@ -82,24 +81,22 @@ function(mbed_setup_linker_script mbed_os_target mbed_baremetal_target target_de
8281 # which is then added as a dependency of the MCU target. This ensures the linker script will exist
8382 # by the time we need it.
8483 add_custom_target (mbed-linker-script DEPENDS ${LINKER_SCRIPT_PATH} VERBATIM )
85- foreach (TARGET ${mbed_baremetal_target} ${mbed_os_target} )
86- add_dependencies (${TARGET} mbed-linker-script)
87-
88- # When building the Mbed internal tests, the tests get created before the mbed-os target does. So, the normal logic
89- # in mbed_set_post_build() to set the linker script does not work. So, we need to instead attach the linker script to
90- # the mbed-os and mbed-baremetal libraries themselves, so it will get picked up automatically.
91- # This prevents a custom linker script from being used in STANDALONE mode, but we don't need to do that.
92- set_target_properties (${TARGET} PROPERTIES LINKER_SCRIPT_PATH ${LINKER_SCRIPT_PATH} )
93-
94- # add linker script only for tests
95- if (MBED_IS_STANDALONE)
96- target_link_options (${TARGET}
97- INTERFACE
98- "-T" "${LINKER_SCRIPT_PATH} "
99- )
100- set_property (TARGET ${TARGET} APPEND PROPERTY INTERFACE_LINK_DEPENDS ${LINKER_SCRIPT_PATH} )
101- endif ()
102- endforeach ()
84+ add_dependencies (${mbed_os_target} mbed-linker-script)
85+
86+ # When building the Mbed internal tests, the tests get created before the mbed-os target does. So, the normal logic
87+ # in mbed_set_post_build() to set the linker script does not work. So, we need to instead attach the linker script to
88+ # the mbed-os and mbed-baremetal libraries themselves, so it will get picked up automatically.
89+ # This prevents a custom linker script from being used in STANDALONE mode, but we don't need to do that.
90+ set_target_properties (${mbed_os_target} PROPERTIES LINKER_SCRIPT_PATH ${LINKER_SCRIPT_PATH} )
91+
92+ # add linker script only for tests
93+ if (MBED_IS_STANDALONE)
94+ target_link_options (${mbed_os_target}
95+ INTERFACE
96+ "-T" "${LINKER_SCRIPT_PATH} "
97+ )
98+ set_property (TARGET ${mbed_os_target} APPEND PROPERTY INTERFACE_LINK_DEPENDS ${LINKER_SCRIPT_PATH} )
99+ endif ()
103100
104101endfunction (mbed_setup_linker_script)
105102
0 commit comments