Skip to content
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

CMake: pass macros to ARM toolchain linker #13930

Merged
merged 2 commits into from
Nov 24, 2020
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
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ endfunction()
#
function(mbed_set_mbed_target_linker_script target)
get_property(mbed_target_linker_script GLOBAL PROPERTY MBED_TARGET_LINKER_FILE)
mbed_generate_options_for_linker(${target} _linker_preprocess_definitions)
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
mbed_generate_gcc_options_for_linker(${target} _linker_preprocess_definitions)
set(CMAKE_PRE_BUILD_COMMAND
COMMAND "arm-none-eabi-cpp" ${_linker_preprocess_definitions} -x assembler-with-cpp -E -Wp,-P
${mbed_target_linker_script} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld
Expand All @@ -146,6 +146,7 @@ function(mbed_set_mbed_target_linker_script target)
target_link_options(mbed-core
INTERFACE
"--scatter=${mbed_target_linker_script}"
"--predefine=${_linker_preprocess_definitions}"
)
endif()
add_custom_command(
Expand Down
21 changes: 21 additions & 0 deletions tools/cmake/toolchain.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# Generate a file containing compile definitions
function(mbed_generate_options_for_linker target definitions_file)
set(_compile_definitions
"$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>"
)

# Remove macro definitions that contain spaces as the lack of escape sequences and quotation marks
# in the macro when retrieved using generator expressions causes linker errors.
# This includes string macros, array macros, and macros with operations.
# TODO CMake: Add escape sequences and quotation marks where necessary instead of removing these macros.
set(_compile_definitions
"$<FILTER:${_compile_definitions},EXCLUDE, +>"
)

# Append -D to all macros as we pass these as response file to cxx compiler
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")
set(${definitions_file} @${CMAKE_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE)
endfunction()
# Set the system processor depending on the CPU core type
if (MBED_CPU_CORE STREQUAL Cortex-A9)
set(CMAKE_SYSTEM_PROCESSOR cortex-a9)
Expand Down
22 changes: 0 additions & 22 deletions tools/cmake/toolchains/GCC_ARM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,6 @@ function(mbed_set_toolchain_options target)
)
endfunction()

# Generate a file containing compile definitions
function(mbed_generate_gcc_options_for_linker target definitions_file)
set(_compile_definitions
"$<TARGET_PROPERTY:${target},COMPILE_DEFINITIONS>"
)

# Remove macro definitions that contain spaces as the lack of escape sequences and quotation marks
# in the macro when retrieved using generator expressions causes linker errors.
# This includes string macros, array macros, and macros with operations.
# TODO CMake: Add escape sequences and quotation marks where necessary instead of removing these macros.
set(_compile_definitions
"$<FILTER:${_compile_definitions},EXCLUDE, +>"
)

# Append -D to all macros as we pass these as response file to cxx compiler
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")
set(${definitions_file} @${CMAKE_BINARY_DIR}/compile_time_defs.txt PARENT_SCOPE)
endfunction()

# Configure the toolchain to select the selected C library
function(mbed_set_c_lib target lib_type)
if (${lib_type} STREQUAL "small")
Expand Down