Skip to content

Commit 0ea2129

Browse files
danieldegrassenashif
authored andcommitted
cmake: extensions: use INTERFACE_SOURCES as property for code relocation
In order to enable code relocation, we use a custom target (code_data_relocation_target), and add files we wish to relocate, as well as which sections should be relocated to the COMPILE_DEFINITIONS property for the target. This approach has been fragile, because COMPILE_DEFINITIONS can also be added to for all targets using `add_definitions`. This means if another part of the project uses `add_definitions` and CONFIG_CODE_DATA_RELOCATION is on, a warning will appear about the "file" not being found. The "file" of course, is just the definition added by `add_definitions`. To work around this, switch to overloading the INTERFACE_SOURCES property. This property should be a bit more robust, because nobody else will add sources to the code_data_relocation_target. However, this approach has the downside that the CMake documentation pstates targets created with `add_custom_target()` (which the code_data_relocation_target is) do not have an INTERFACE scope for their sources- so while this approach works, it is not officially supported by CMake Fixes #60220 Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent abc296f commit 0ea2129

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

cmake/linker/arcmwdt/target.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ macro(toolchain_ld_relocation)
155155
${ZEPHYR_BASE}/scripts/build/gen_relocate_app.py
156156
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
157157
-d ${APPLICATION_BINARY_DIR}
158-
-i \"$<TARGET_PROPERTY:code_data_relocation_target,COMPILE_DEFINITIONS>\"
158+
-i \"$<TARGET_PROPERTY:code_data_relocation_target,INTERFACE_SOURCES>\"
159159
-o ${MEM_RELOCATION_LD}
160160
-s ${MEM_RELOCATION_SRAM_DATA_LD}
161161
-b ${MEM_RELOCATION_SRAM_BSS_LD}

cmake/linker/ld/target_relocation.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ macro(toolchain_ld_relocation)
1616
OUTPUT
1717
${DICT_FILE}
1818
CONTENT
19-
$<TARGET_PROPERTY:code_data_relocation_target,COMPILE_DEFINITIONS>
19+
$<TARGET_PROPERTY:code_data_relocation_target,INTERFACE_SOURCES>
2020
)
2121

2222
add_custom_command(

cmake/modules/extensions.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,9 +1526,9 @@ function(zephyr_code_relocate)
15261526
# each directive can embed multiple CMake lists, representing flags and files,
15271527
# the latter of which can come from generator expressions.
15281528
get_property(code_rel_str TARGET code_data_relocation_target
1529-
PROPERTY COMPILE_DEFINITIONS)
1529+
PROPERTY INTERFACE_SOURCES)
15301530
set_property(TARGET code_data_relocation_target
1531-
PROPERTY COMPILE_DEFINITIONS
1531+
PROPERTY INTERFACE_SOURCES
15321532
"${code_rel_str}|${CODE_REL_LOCATION}:${flag_list}:${file_list}")
15331533
endfunction()
15341534

0 commit comments

Comments
 (0)