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

zephyr_library_*() configuration has lower precedence than global zephyr_*() configuration #5097

Closed
SebastianBoe opened this issue Nov 21, 2017 · 1 comment · Fixed by #5110
Assignees
Labels
area: Build System bug The issue is a bug, or the PR is fixing a bug

Comments

@SebastianBoe
Copy link
Collaborator

It is expected behaviour that if a "global" flag from zephyr_compile_options() conflicts with a library-specific flag given with zephyr_library_compile_options() then the local library-specific option will override the global option.

An example of a use-case is that we are able to globally configure whether we build optimized for size or speed, but the bluetooth controller is on the limit of it's real-time requirement and must therefore always be built for speed. https://github.com/zephyrproject-rtos/zephyr/blob/master/subsys/bluetooth/controller/CMakeLists.txt#L36

Now, CMake has no idea what flags conflict with each other, so it can't help us, but GCC does, and it gives precedence to the flag specified last on the command line. So it is a simple matter of ensuring that zephyr_library_* adds flags later on the command line than zephyr_*. But unfortunately CMake places flags from link interface libraries after a target's flag's.

@SebastianBoe SebastianBoe added area: Build System bug The issue is a bug, or the PR is fixing a bug labels Nov 21, 2017
@SebastianBoe SebastianBoe self-assigned this Nov 21, 2017
@SebastianBoe
Copy link
Collaborator Author

Source file flags have higher precedence than link interface flags, so reworking the extentions to use source file properties might be the cleanest solution.

@SebastianBoe SebastianBoe changed the title zephyr_library_*() configuration is unexpectedly overridden by global zephyr_*() configuration zephyr_library_*() configuration has lower precedence than global zephyr_*() configuration Nov 21, 2017
SebastianBoe added a commit to SebastianBoe/zephyr that referenced this issue Nov 22, 2017
This fixes zephyrproject-rtos#5097.

The desired behaviour is that when a flag that is given through the
zephyr_* API conflicts with the zephyr_library_* API then precedence
will be given to the zephyr_library_* API. In other words, local
configuration overrides global configuration.

We choose to rely upon the compiler for sane behaviour when flags are
in conflict. Compilers generally give precedence to flags given late
on the command line. So to ensure that zephyr_library_* flags are
placed late on the command line we create a dummy interface library
and link with it to obtain the flags.

Other options were considered, source file properties would also have
higher priority. But that would have required some kind of
post-processing stage that applies all the source file properties.

Linking with a dummy interface library will place flags later on the
command line than the the flags from zephyr_interface because
zephyr_interface will be the first interface library that flags are
taken from.

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
nashif pushed a commit that referenced this issue Nov 23, 2017
This fixes #5097.

The desired behaviour is that when a flag that is given through the
zephyr_* API conflicts with the zephyr_library_* API then precedence
will be given to the zephyr_library_* API. In other words, local
configuration overrides global configuration.

We choose to rely upon the compiler for sane behaviour when flags are
in conflict. Compilers generally give precedence to flags given late
on the command line. So to ensure that zephyr_library_* flags are
placed late on the command line we create a dummy interface library
and link with it to obtain the flags.

Other options were considered, source file properties would also have
higher priority. But that would have required some kind of
post-processing stage that applies all the source file properties.

Linking with a dummy interface library will place flags later on the
command line than the the flags from zephyr_interface because
zephyr_interface will be the first interface library that flags are
taken from.

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant