I have an arm-eabi-none environment (mbed-os) and want to add a custom linker script option to the build system. The current system uses a fixed linker script, assigned to the used target mcu/board.
The original script is set by
add_custom_target(mbed-linker-script DEPENDS ${LINKER_SCRIPT_PATH} VERBATIM)
foreach(TARGET ${mbed_baremetal_target} ${mbed_os_target})
add_dependencies(${TARGET} mbed-linker-script)
# Add linker flags to the MCU target to pick up the preprocessed linker script
target_link_options(${TARGET}
INTERFACE
"-T" "${LINKER_SCRIPT_PATH}"
)
endforeach()
Now I want to override this option in a later, optional step.
remove_flag_from_target(${TARGET} "-T" "${LINKER_SCRIPT_PATH}")
# Add linker flags to the MCU target to pick up the preprocessed linker script
target_link_options(${TARGET}
INTERFACE
"-T" "${CUSTOM_LINKER_SCRIPT_PATH}"
)
The remove flag macro is from Stackoverflow, it reads the options into a list and removes the item if found::
macro(remove_flag_from_target _target _flag)
get_target_property(_target_cxx_flags ${_target} INTERFACE_LINK_OPTIONS)
if(_target_cxx_flags)
list(REMOVE_ITEM _target_cxx_flags ${_flag})
set_target_properties(${_target} PROPERTIES INTERFACE_LINK_OPTIONS "${_target_cxx_flags}")
endif()
endmacro()
But this does not work, I have tried now many versions of writing the flags, it will not remove -T and the script name. What is missing?
after executing this, the remaining INTERFACE_LINK_OPTIONS are:
[cmake] INTERFACE_LINK_OPTIONS in mbed-os: -Wl,--gc-sections-Wl,--wrap,main-Wl,--wrap,_malloc_r-Wl,--wrap,_free_r-Wl,--wrap,_realloc_r-Wl,--wrap,_memalign_r-Wl,--wrap,_calloc_r-Wl,--wrap,exit-Wl,--wrap,atexit-Wl,-n/home/jojo/projects/HeaterController/build/F769NI-STM32CUBE-Debug/mbed-disco-f769ni.link_script.ld-T/home/jojo/projects/HeaterController/build/F769NI-STM32CUBE-Debug/app_Hello/app_hello.link_spript.ld
only the first flag id ‘-T’ is removed.