Skip to content

Commit a49d8f2

Browse files
authored
Fix linker script incorrectly selected for bare-metal profile (#342)
mbed-os and mbed-baremetal library targets both are created, so we cannot use if(TARGET mbed-os) or if(TARGET mbed-baremetal) to determine which one the application target links to. Instead, determine by checking application target's LINK_LIBRARIES property.
1 parent 40e3056 commit a49d8f2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tools/cmake/mbed_target_functions.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,21 @@ function(mbed_set_post_build target)
120120
# add linker script. Skip for greentea test code, there the linker script is set in mbed_setup_linker_script()
121121
if (NOT MBED_IS_STANDALONE)
122122
if("${ARGN}" STREQUAL "")
123-
if(TARGET mbed-os)
123+
get_target_property(POST_BUILD_TARGET_LINK_LIBRARIES ${target} LINK_LIBRARIES)
124+
if("mbed-os" IN_LIST POST_BUILD_TARGET_LINK_LIBRARIES)
124125
get_target_property(LINKER_SCRIPT_PATH mbed-os LINKER_SCRIPT_PATH)
125126
target_link_options(${target}
126127
PRIVATE
127128
"-T" "${LINKER_SCRIPT_PATH}"
128129
)
129-
elseif(TARGET mbed-baremetal)
130+
elseif("mbed-baremetal" IN_LIST POST_BUILD_TARGET_LINK_LIBRARIES)
130131
get_target_property(LINKER_SCRIPT_PATH mbed-baremetal LINKER_SCRIPT_PATH)
131132
target_link_options(${target}
132133
PRIVATE
133134
"-T" "${LINKER_SCRIPT_PATH}"
134135
)
136+
else()
137+
message(FATAL_ERROR "Target ${target} used with mbed_set_post_build() but does not link to mbed-os or mbed-baremetal!")
135138
endif()
136139
else()
137140
message(STATUS "${target} uses custom linker script ${ARGV1}")

0 commit comments

Comments
 (0)