Skip to content

Conversation

tejlmand
Copy link
Contributor

This commit provides a CMakePresets.json which includes the sample's CMakePresets.json file.

west build is extended to set APP_DIR in environment when sysbuild is used. This allows sysbuild's CMakePresets.json to include the sample's presets file.

Alternative to: #95047

@pdgendt
Copy link
Contributor

pdgendt commented Sep 26, 2025

Needs a rebase

@tejlmand
Copy link
Contributor Author

@benedekkupper ptal.

@pdgendt pdgendt assigned tejlmand and unassigned pdgendt Sep 26, 2025
57300
57300 previously approved these changes Sep 26, 2025
Copy link
Contributor

@57300 57300 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re #95047 (comment)

As a minor (not blocking) note then this PR only makes it possible to use presets together with west, and thus does not support pure CMake / projects which are not using west, but have custom tools.

Actually, it already works with pure CMake if you define APP_DIR in your environment beforehand.

In fact, I would suggest updating sysbuild itself so it could pick up the same environment variable:

if(NOT DEFINED APP_DIR)
message(FATAL_ERROR "No main application specified")
endif()

The standard, non-west sysbuild invocation could then change from:

cmake -Bbuild ~/ncs/zephyr/share/sysbuild -DAPP_DIR=$PWD

to:

APP_DIR=$PWD cmake -Bbuild ~/ncs/zephyr/share/sysbuild

and let the --preset argument be added without hassle.

Not blocking this PR, but that would be another benefit to this approach.

@benedekkupper
Copy link
Contributor

This PR is a lot cleaner, and I'd prefer to do it this way than #95047, however it doesn't solve the relative path translation issue: the application's presets file is full of such variables (e.g. "BOARD_ROOT": "${sourceParentDir}/", "CONF_FILE": "${sourceDir}/prj_release.conf"), since these resolve to sysbuild's directory and not to the app's, the build fails.

@tejlmand
Copy link
Contributor Author

As a minor (not blocking) note then this PR only makes it possible to use presets together with west, and thus does not support pure CMake / projects which are not using west, but have custom tools.

Actually, it already works with pure CMake if you define APP_DIR in your environment beforehand.

@57300 That was a comment to #95047.
#95047 does not support pure CMake sysbuild as described in https://docs.zephyrproject.org/latest/build/sysbuild/index.html#building-with-sysbuild

cmake -Bbuild -GNinja -DBOARD=reel_board -DAPP_DIR=samples/hello_world share/sysbuild

because #95047 relies on west build to copy the CMakePresets.json file.

But PR#96609 supports both west build ... -- --preset=<name> as well as APP_DIR=<path-to-app> cmake ... -DAPP_DIR=<path-to-app> --preset=<name>

In fact, I would suggest updating sysbuild itself so it could pick up the same environment variable:

Yes, I did consider that as well, but wanted some feedback from @benedekkupper first regarding the alternative approach before doing wider changes.

@57300
Copy link
Contributor

57300 commented Sep 26, 2025

That was a comment to #95047.

I see, I didn't realize that "this PR" was referring to #95047. I'm sorry for misreading your original comment.

In fact, I would suggest updating sysbuild itself so it could pick up the same environment variable:

Yes, I did consider that as well, but wanted some feedback from benedekkupper first regarding the alternative approach before doing wider changes.

Good to know. I guess this is essentially a work in progress and I jumped in too early.

@benedekkupper
Copy link
Contributor

benedekkupper commented Sep 26, 2025

I could make this patch work in my environment, by relying on ${fileDir} instead of ${sourceDir} and co. in the application's CMakePresets.json, and while not ideal, this is the optimal solution that I can see for this problem at the moment.

@tejlmand
Copy link
Contributor Author

I could make this patch work in my environment, by relying on ${fileDir} instead of ${sourceDir} and co. in the application's CMakePresets.json, and while not ideal, this is the optimal solution that I can see for this problem at the moment.

@benedekkupper Thanks for testing it out and provide feedback.
I think fileDir is a good replacement for sourceDir for the current state.

Will cleanup the PR and add some doc notes on regarding this.
Marking draft for the time being.

@tejlmand tejlmand marked this pull request as draft September 29, 2025 09:29
@tejlmand tejlmand force-pushed the sysbuild_presets_support branch from d8f180a to 5f5e1a6 Compare September 29, 2025 12:30
@tejlmand tejlmand marked this pull request as ready for review September 29, 2025 12:30
@tejlmand
Copy link
Contributor Author

Good to know. I guess this is essentially a work in progress and I jumped in too early.

@57300 and @benedekkupper ptal, it's fully ready now 🙂


.. group-tab:: ``west build``

Here is an example where preser ``release`` should be used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "preser" -> preset

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


.. note::

Because sysbuild consumes and process ``CMakePresets.json`` then preset macros referring to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rephrase this a bit, e.g.: As sysbuild changes the top-level cmake project to its own directory, the cmake presets are parsed from there, the application's presets are included from this file verbatim. Therefore relative paths, and macros resolving relative to the source directory will not work as expected, but as relative to share/sysbuild. The ${fileDir} macro can be used to create portable paths relative to the application's directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion.
Applied.

This commit provides a CMakePresets.json which includes the sample's
CMakePresets.json file.

`west build` is extended to set `APP_DIR` in environment when sysbuild
is used. This allows sysbuild's CMakePresets.json to include the
sample's presets file.

Signed-off-by: Torsten Rasmussen <[email protected]>
@tejlmand tejlmand force-pushed the sysbuild_presets_support branch from 5f5e1a6 to 522eb86 Compare September 29, 2025 13:50
Copy link

@benedekkupper
Copy link
Contributor

LGTM :)

@marc-hb marc-hb removed their request for review September 29, 2025 18:15
@jhedberg jhedberg merged commit b88e615 into zephyrproject-rtos:main Oct 3, 2025
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants