Zephyr: Compiler flags added late in the build are not exported to external build systems

Created on 9 Jan 2018  路  6Comments  路  Source: zephyrproject-rtos/zephyr

The current infrastructure for integrating with external build systems can cause flags to be omitted in a way that is confusing and inconvenient for build script developers.

Today it works like this:

CMakeLists.txt code is processed in a sequential manner. Different subsystems (arch/, zephyr/CMakeLists.txt, subsystems/, ext/) can globally add flags to the build, and the zephyr_get_*
API reads out this global list of flags _when it is invoked_ to export flags to external build systems.

For third party build systems that are integrated in the 'app' CMakeLists.txt file this works fine, because the code in the 'app' CMakeLists.txt that is placed after boilerplate.cmake is the last code to be executed and will therefore have access to all flags.

For Zephyr components things are trickier. No matter how careful we are in ordering arch, ext, subsys, there will eventually arise a use-case where two different systems are both exporting flags to external build systems and also globally adding compiler flags.

Build System bug low

All 6 comments

A temporary workaround is to re-order CMakeLists.txt code until you get all the flags you need.

Not sure what a proper fix would look like. Perhaps in addition to the boilerplate.cmake header we could have a footer_boilerplate.cmake that reads out the final list of flags. But this solution would both increase bloat in the 'app' CMakeLists.txt code and be a breaking change, so we should try to find a better solution.

The CMake-way of solving this generic problem of "configuration done late must affect configuration done early" is generator expressions. CMake can evaluate CMake variables at generation-time (Just after all CMakeLists.txt code has been processed). Perhaps if the flags were contained in generator expressions we could make this work.

@pfalcon : @KaSroka : FYI

Ack, thanks for ping.

is this fixed already?

Unfortunately no.

over 1 year, closing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dhavalpanchalispl picture dhavalpanchalispl  路  3Comments

cfriedt picture cfriedt  路  3Comments

carlescufi picture carlescufi  路  5Comments

nashif picture nashif  路  5Comments

rosterloh picture rosterloh  路  4Comments