Skip to content

Commit eceaea5

Browse files
authored
Merge pull request #14299 from hugueskamba/hk_cmake_refactor_mapfile_generation
CMake: Refactor mapfile generation
2 parents 1de9e39 + ed09a5c commit eceaea5

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

CMakeLists.txt

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020 ARM Limited. All rights reserved.
1+
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

44
# This is the boilerplate for Mbed OS
@@ -139,21 +139,6 @@ string(PREPEND MBED_TARGET_CONVERTED "mbed-")
139139

140140
target_link_libraries(mbed-core INTERFACE ${MBED_TARGET_CONVERTED})
141141

142-
#
143-
# Configures the application
144-
# Note, this function will be removed in the next revisions
145-
#
146-
function(mbed_configure_app_target target)
147-
# Gcc Arm requires memap to be set with app name, equally to ARMClang
148-
# TODO: move this to toolchain and set properly
149-
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
150-
target_link_options(mbed-core
151-
INTERFACE
152-
"-Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map"
153-
)
154-
endif()
155-
endfunction()
156-
157142
#
158143
# Converts output file of `target` to binary file and to Intel HEX file.
159144
#
@@ -233,6 +218,10 @@ endfunction()
233218
# Set post build operations
234219
#
235220
function(mbed_set_post_build target)
221+
# The mapfile name includes the top-level target name and the
222+
# executable suffix for all toolchains as CMake hardcodes the name of the
223+
# diagnostic output file for some toolchains.
224+
mbed_configure_memory_map(mbed-core "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map")
236225
mbed_validate_application_profile(${target})
237226
mbed_generate_bin_hex(${target})
238227

@@ -249,3 +238,7 @@ if ("${CMAKE_GENERATOR}" MATCHES "Ninja")
249238
set(CMAKE_NINJA_FORCE_RESPONSE_FILE 1 CACHE INTERNAL "")
250239
endif()
251240
endif()
241+
242+
# TODO: Remove once all example applications have removed it
243+
function(mbed_configure_app_target target)
244+
endfunction()

tools/cmake/toolchains/ARM.cmake

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ list(APPEND asm_compile_options
3131
--target=arm-arm-none-eabi
3232
)
3333

34-
list(APPEND link_options
35-
"--map"
36-
)
37-
3834
# Add linking time preprocessor macro for TFM targets
3935
if(MBED_CPU_CORE MATCHES "-NS$")
4036
list(APPEND link_options
@@ -67,3 +63,15 @@ function(mbed_set_printf_lib target lib_type)
6763
)
6864
endif()
6965
endfunction()
66+
67+
# Add linker flags to generate a mapfile with a given name
68+
# `mapfile` is overridden as CMake provides the name of the diagnostic output
69+
# file by providing armlink with the --list command line option.
70+
# See https://gitlab.kitware.com/cmake/cmake/-/issues/21538
71+
function(mbed_configure_memory_map target mapfile)
72+
target_link_options(${target}
73+
INTERFACE
74+
"--map"
75+
"--list=${mapfile}"
76+
)
77+
endfunction()

tools/cmake/toolchains/GCC_ARM.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,11 @@ function(mbed_set_printf_lib target lib_type)
8484
)
8585
endif()
8686
endfunction()
87+
88+
# Add linker flags to generate a mapfile with a given name
89+
function(mbed_configure_memory_map target mapfile)
90+
target_link_options(${target}
91+
INTERFACE
92+
"-Wl,-Map=${mapfile}"
93+
)
94+
endfunction()

0 commit comments

Comments
 (0)