-
Notifications
You must be signed in to change notification settings - Fork 8.3k
cmake: extensions: use INTERFACE_SOURCES as property for code relocation #81249
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: extensions: use INTERFACE_SOURCES as property for code relocation #81249
Conversation
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 zephyrproject-rtos#60220 Signed-off-by: Daniel DeGrasse <[email protected]>
|
@tejlmand I'm interested to hear your opinion on this fix- I really dislike the fact that if we use
By that documentation, the
|
|
I got a custom property to work by wrapping the genex with: # either
$<GENEX_EVAL:$<TARGET_PROPERTY:code_data_relocation_target,RELOCATE_FILES>>
# or
$<TARGET_GENEX_EVAL:code_data_relocation_target,$<TARGET_PROPERTY:code_data_relocation_target,RELOCATE_FILES>>I think that both will work equivalently for the code relocation implementation. The only difference is that |
That documentation refers to the use of target_sources(), meaning that if you want to use that function together with a custom target, then you can only use the private scope. The property itself is still available on the target, as you have noticed. I share the feeling of this being sub-optimal, but unfortunately CMake doesn't allow generator expressions on custom properties, which means that the idea given in #81249 (comment) of using a custom property will not work because we rely on generator expressions in the property value, ref: zephyr/cmake/modules/extensions.cmake Lines 1478 to 1489 in 65511ea
This actually indicates that
|
it might be worth a try, but iirc then the issue with this approach when I tested at an earlier occasion was that the property is containing multiple levels of generator expressions. Also worth remembering is the linker consumer needs to be aware that the property retrieved must be expended in a |
@tejlmand I haven't tested very thoroughly, just settled on building But I concluded that as long as the custom property value would only contain things like Still, if |
Personally if we are ok with |
@57300 Yes, as long as we can be sure we only have simple constructs. Developers must be aware that they need additional genex eval calls if the extend the code. For example this fails: because one more level of generator expression is used in sub-property. So would need to be: Meaning there is a risk that at some point in time, something will break. Sticking to a property which themselves allows generator expression within them, like |
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 usesadd_definitionsandCONFIG_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 CMakeFixes #60220