1# Copyright (c) 2025 IAR Systems AB
2#
3# SPDX-License-Identifier: Apache-2.0
4
5# Override the default CMake's IAR ILINK linker signature
6
7# The default behaviour of these new optimization flags for the linker
8# is to use the compiler optimization flags if no flags are set.
9# This does not work for IAR tools as there are no optimization flags
10# for the linker, and leaving the property empty causes it to be
11# filled with the compiler flags.
12# This workaround adds extra info to the map file only so should not
13# affect the generated code
14# To have this working properly, either the automatic use of compiler
15# flags must be removed, or we add some kind of dummy do nothing
16# command line option to the linker.
17# Either way, as this is causing an error right now, we use this
18# temporary workaround.
19
20set_property(TARGET linker PROPERTY no_optimization --entry_list_in_address_order)
21set_property(TARGET linker PROPERTY optimization_debug --entry_list_in_address_order)
22set_property(TARGET linker PROPERTY optimization_speed --entry_list_in_address_order)
23set_property(TARGET linker PROPERTY optimization_size --entry_list_in_address_order)
24set_property(TARGET linker PROPERTY optimization_size_aggressive --entry_list_in_address_order)
25
26
27string(APPEND CMAKE_C_LINK_FLAGS --no-wrap-diagnostics)
28
29if(CONFIG_IAR_DATA_INIT)
30  string(APPEND CMAKE_C_LINK_FLAGS " --redirect z_data_copy=__iar_data_init3")
31endif()
32foreach(lang C CXX ASM)
33  set(commands "--log modules,libraries,initialization,redirects,sections")
34  set(CMAKE_${lang}_LINK_EXECUTABLE
35  "<CMAKE_LINKER> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> ${commands} <LINK_LIBRARIES> <OBJECTS> -o <TARGET>")
36  set(commands)
37endforeach()
38