ObKo / stm32-cmake

CMake for stm32 developing.
MIT License
1.2k stars 339 forks source link

Default linker script interferes with custom linker script #339

Closed moritzstoetter closed 7 months ago

moritzstoetter commented 7 months ago

Describe the bug When specifying a custom linker script through target_link_options(my_target PRIVATE -T ${CMAKE_SOURCE_DIR}/custom.ld) or stm32_add_linker_script(my_target PRIVATE custom.ld) the default linker script is still created and configured through the cmake function cmsis_generate_default_linker_script. When linking, both scripts are configured and interfere with on another.

Sources to reproduce Clone this https://github.com/moritzstoetter/stm32-cmake_custom_linker_script.git

Steps to reproduce

. <(curl https://aka.ms/vcpkg-init.sh -L)
vcpkg activate
cmake --preset debug
cmake --build --preset debug

produces

ld:.../L4R9AI.ld:9: warning: redeclaration of memory region `FLASH'
ld:.../L4R9AI.ld:10: warning: redeclaration of memory region `RAM'

These warnings are in themselves not the issue. They are indicative of the underlying problem though.

Expected behavior When specifying a custom linker script, the default linker script should not interfere. Probably it shouldn't even get produced.

Environment (please complete the following information):

moritzstoetter commented 7 months ago

Never mind, found the bit in the documentation that explains this.

Linking to a fully specd target device e.g. CMSIS::STM32::L4R9AI will create and include the default linker script. Linking to the general type e.g. CMSIS::STM32::L4R9xx won't.