From d2cc1f996a622d7880d68eb30cc431d71cd72a71 Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Wed, 11 Sep 2024 17:56:47 +0800 Subject: [PATCH] Fix linker script incorrectly selected for bare-metal profile 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. --- tools/cmake/mbed_target_functions.cmake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/cmake/mbed_target_functions.cmake b/tools/cmake/mbed_target_functions.cmake index 826545ec286..11a8e203b98 100644 --- a/tools/cmake/mbed_target_functions.cmake +++ b/tools/cmake/mbed_target_functions.cmake @@ -120,18 +120,21 @@ function(mbed_set_post_build target) # add linker script. Skip for greentea test code, there the linker script is set in mbed_setup_linker_script() if (NOT MBED_IS_STANDALONE) if("${ARGN}" STREQUAL "") - if(TARGET mbed-os) + get_target_property(POST_BUILD_TARGET_LINK_LIBRARIES ${target} LINK_LIBRARIES) + if("mbed-os" IN_LIST POST_BUILD_TARGET_LINK_LIBRARIES) get_target_property(LINKER_SCRIPT_PATH mbed-os LINKER_SCRIPT_PATH) target_link_options(${target} PRIVATE "-T" "${LINKER_SCRIPT_PATH}" ) - elseif(TARGET mbed-baremetal) + elseif("mbed-baremetal" IN_LIST POST_BUILD_TARGET_LINK_LIBRARIES) get_target_property(LINKER_SCRIPT_PATH mbed-baremetal LINKER_SCRIPT_PATH) target_link_options(${target} PRIVATE "-T" "${LINKER_SCRIPT_PATH}" ) + else() + message(FATAL_ERROR "Target ${target} used with mbed_set_post_build() but does not link to mbed-os or mbed-baremetal!") endif() else() message(STATUS "${target} uses custom linker script ${ARGV1}")