Skip to content

Commit 47f6148

Browse files
0xc0170hugueskamba
authored andcommitted
CMake: Fix GCC_ARM pre-linking stage (#13575)
Make it generic for all targets. It was previously hardcoded for K64F
1 parent 1b576c3 commit 47f6148

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

CMakeLists.txt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,13 @@ endfunction()
7575
# Specifies linker script used for linking `target`.
7676
#
7777
function(mbed_set_mbed_target_linker_script target)
78-
get_property(mbed_target_startup GLOBAL PROPERTY MBED_TARGET_LINKER_FILE)
79-
80-
# TODO: @mbed-os-tools This pre-build commands should get details from target + profile.
78+
get_property(mbed_target_linker_script GLOBAL PROPERTY MBED_TARGET_LINKER_FILE)
79+
mbed_generate_gcc_options_for_linker(${target} _linker_preprocess_definitions _linker_preprocess_options)
8180
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
8281
set(CMAKE_PRE_BUILD_COMMAND
8382
COMMAND "arm-none-eabi-cpp" -E -P
84-
-Wl,--gc-sections -Wl,--wrap,main -Wl,--wrap,_malloc_r -Wl,--wrap,_free_r
85-
-Wl,--wrap,_realloc_r -Wl,--wrap,_memalign_r -Wl,--wrap,_calloc_r
86-
-Wl,--wrap,exit -Wl,--wrap,atexit -Wl,-n
87-
-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
88-
-DMBED_ROM_START=0x0 -DMBED_ROM_SIZE=0x100000 -DMBED_RAM_START=0x20000000
89-
-DMBED_RAM_SIZE=0x30000 -DMBED_RAM1_START=0x1fff0000
90-
-DMBED_RAM1_SIZE=0x10000 -DMBED_BOOT_STACK_SIZE=1024
91-
-DXIP_ENABLE=0
92-
${mbed_target_startup} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld
83+
${_linker_preprocess_options} ${_linker_preprocess_definitions}
84+
${mbed_target_linker_script} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld
9385

9486
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
9587
BYPRODUCTS "${CMAKE_BINARY_DIR}/${target}.link_script.ld"
@@ -98,7 +90,7 @@ function(mbed_set_mbed_target_linker_script target)
9890
set(CMAKE_PRE_BUILD_COMMAND COMMAND "")
9991
target_link_options(mbed-os
10092
PUBLIC
101-
"--scatter=${mbed_target_startup}"
93+
"--scatter=${mbed_target_linker_script}"
10294
)
10395
endif()
10496
add_custom_command(

cmake/toolchains/GCC_ARM.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,23 @@ function(mbed_set_toolchain_options target)
5555
${link_options}
5656
)
5757
endfunction()
58+
59+
# GCC ARM requires preprecessing linker script, execute generators to get definitions needed for
60+
# this step - linker options and compile definitions
61+
function(mbed_generate_gcc_options_for_linker target definitions_file linker_options_file)
62+
set(_compile_definitions
63+
"$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>"
64+
)
65+
66+
set(_linker_options
67+
"$<TARGET_PROPERTY:${target},LINK_OPTIONS>"
68+
)
69+
70+
set(_compile_definitions
71+
"$<$<BOOL:${_compile_definitions}>:-D$<JOIN:${_compile_definitions}, -D>>"
72+
)
73+
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n")
74+
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/linker_options.txt" CONTENT "${_linker_options}\n")
75+
set(definitions_file @${CMAKE_BINARY_DIR}/compile_time_defs.txt)
76+
set(linker_options_file @${CMAKE_BINARY_DIR}/linker_options.txt)
77+
endfunction()

0 commit comments

Comments
 (0)