Skip to content

CMake: Gcc Arm prebuild step fix #13575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,13 @@ endfunction()
# Specifies linker script used for linking `target`.
#
function(mbed_set_mbed_target_linker_script target)
get_property(mbed_target_startup GLOBAL PROPERTY MBED_TARGET_LINKER_FILE)

# TODO: @mbed-os-tools This pre-build commands should get details from target + profile.
get_property(mbed_target_linker_script GLOBAL PROPERTY MBED_TARGET_LINKER_FILE)
mbed_generate_gcc_options_for_linker(${target} _linker_preprocess_definitions _linker_preprocess_options)
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
set(CMAKE_PRE_BUILD_COMMAND
COMMAND "arm-none-eabi-cpp" -E -P
-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
-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
-DMBED_ROM_START=0x0 -DMBED_ROM_SIZE=0x100000 -DMBED_RAM_START=0x20000000
-DMBED_RAM_SIZE=0x30000 -DMBED_RAM1_START=0x1fff0000
-DMBED_RAM1_SIZE=0x10000 -DMBED_BOOT_STACK_SIZE=1024
-DXIP_ENABLE=0
${mbed_target_startup} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld
${_linker_preprocess_options} ${_linker_preprocess_definitions}
${mbed_target_linker_script} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld

WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
BYPRODUCTS "${CMAKE_BINARY_DIR}/${target}.link_script.ld"
Expand All @@ -98,7 +90,7 @@ function(mbed_set_mbed_target_linker_script target)
set(CMAKE_PRE_BUILD_COMMAND COMMAND "")
target_link_options(mbed-os
PUBLIC
"--scatter=${mbed_target_startup}"
"--scatter=${mbed_target_linker_script}"
)
endif()
add_custom_command(
Expand Down
20 changes: 20 additions & 0 deletions cmake/toolchains/GCC_ARM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,23 @@ function(mbed_set_toolchain_options target)
${link_options}
)
endfunction()

# GCC ARM requires preprecessing linker script, execute generators to get definitions needed for
# this step - linker options and compile definitions
function(mbed_generate_gcc_options_for_linker target definitions_file linker_options_file)
set(_compile_definitions
"$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>"
)

set(_linker_options
"$<TARGET_PROPERTY:${target},LINK_OPTIONS>"
)

set(_compile_definitions
"$<$<BOOL:${_compile_definitions}>:-D$<JOIN:${_compile_definitions}, -D>>"
)
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/compile_time_defs.txt" CONTENT "${_compile_definitions}\n")
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/linker_options.txt" CONTENT "${_linker_options}\n")
set(definitions_file @${CMAKE_BINARY_DIR}/compile_time_defs.txt)
set(linker_options_file @${CMAKE_BINARY_DIR}/linker_options.txt)
endfunction()