Commit graph

37 commits

Author SHA1 Message Date
Jamie McCrae f4ddca5dca sysbuild: Check for duplicate image names
Checks if the IMAGES variable has been updated with a duplicate
image name, which would otherwise cause an infinite loop.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-01-13 12:00:57 +01:00
Jamie McCrae ce31799c73 sysbuild: Allow board revisions to be specified for targets
Allows specifying board revisions when configuring target images
with sysbuild.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-01-12 12:44:53 +01:00
Torsten Rasmussen fe3efbc6a2 cmake: BOARD_REVISION_CONFIG setting for Kconfig revision fragments
Fixes: #53696

Create a BOARD_REVISION_CONFIG setting to be consistent with the
BOARD_DEFCONFIG setting.

This allows systems which re-uses the Kconfig module to overrule the
file to be used as BOARD_REVISION_CONFIG in same way as is done for
the BOARD_DEFCONFIG file.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-01-11 08:10:45 -08:00
Torsten Rasmussen 3b32444f10 sysbuild: shared cache variable instead of local scope variable
Fixes: #52353

If a CMake variable is available in both local scope and as CMake cache
variable, then the use of `${<var>}` fetches the local scoped variable.
If only the cache variable is set, then things works as expected.

Ensure that the cached variable is always the variable being shared to
images by using `$CACHE{<var>}` instead.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-12-27 12:44:19 +01:00
Ming Shao 3c9aa927ee cmake: fix the wrong arg name when calling check_zephyr_package()
check_zephyr_package() accepts an one-value arg named "WORKSPACE_DIR".
But it is called with "CURRENT_WORKSPACE_DIR".

Signed-off-by: Ming Shao <smrtos@163.com>
2022-12-19 14:34:37 +01:00
Jamie McCrae b65699cc4a cmake: sysbuild: Add support for recurive target cmake inclusion
Adds support for all sysbuild targets to have a sysbuild.cmake file
included and processed as part of sysbuild instead of just the main
application.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-11-03 13:04:08 +01:00
Torsten Rasmussen e0fb04458f cmake: sysbuild: import image kconfig settings to image target
Load image kconfig setting into image target properties.
This allows sysbuild to evaluate and check image configuration as part
of CMake invocation.

sysbuild_get() is updated to support reading of CMake cache or Kconfig
settings for an image.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-11-02 15:42:23 +09:00
Torsten Rasmussen 303c1eb60c sysbuild: support sample configuration of extra images
This commit introduces the possibility of a sample to locate
configuration files for extra images that are used when building with
MCUboot.

This allows use-cases where a sample, A, want to include MCUboot but has
adjustments to the default MCUboot configuration.

By adding a Kconfig fragment `<sample>/sysbuild/mcuboot.conf`, then that
fragment will be used together with the default configuration for
MCUboot.

It is also possible to completely replace the MCUboot configuration.
This is done by creating `<sample>/sysbuild/mcuboot/` folder.
This folder will then be used as the `APPLICATION_CONFIG_DIR` when
building MCUboot.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-10-18 14:13:27 +02:00
Torsten Rasmussen 8941aebc49 sysbuild: support loading of CMakeCache from Zephyr projects
This commit loads the CMakeCache of Zephyr projects.

This allows sysbuild to fetch information from Zephyr projects into
sysbuild itself.

This commit is a first step in the process of sharing more knowledge
between images and sysbuild, and pave the way for closer sharing of
settings between images.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-10-12 18:42:01 +02:00
Torsten Rasmussen 88ae9cbb9d cmake: extend zephyr_get() to handle build configurations from sysbuild
Enhance sysbuild controlled configurations.

The current scheme of passing settings using `-D` on the CMake
invocation is vulnerable to quoting and lists.

With `zephyr_get()` in place as a uniform way of handling user
controlled settings (CMake cache / environment / CMake local variable)
we have a mechanism in place for a cleaner handling of sysbuild
controlled settings.

This improves the robustness of variable passing and add the same cleans
up and simplifies the logic in sysbuild.

The Kconfig Zephyr CMake module has been updated accordingly so that
CONFIG settings are taken from the sysbuild shadow cache when sysbuild
is used as higher level build system.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-02 15:16:50 +02:00
Torsten Rasmussen b88c8e1363 cmake: sysbuild: signing support
This commit introduces image signing by adding the possibility to
specify algorithm and signing key for sysbuild images.

It introduces Kconfig setting to specify signing algorithm and key file.

It will default the signing key to the default key provided by MCUBoot
if no key has been specified.

When signing is enabling, the signature key will be passed to the
application so the build system can sign the image as post build step.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-03 16:05:07 +02:00
Torsten Rasmussen 598bea0899 cmake: create domains.yaml
Support creation of domains.yaml to support
`west <build|flash|debug> --domain` when working with sysbuild multi
image.

Each Zephyr based image is added to list of domain that can be handled
by the Zephyr west extension commands.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-03 16:05:07 +02:00
Torsten Rasmussen 3d520dde2b cmake: support MCUBoot bootloader natively with SYSBuild
This commit adds CMake and Kconfig files needed to build MCUboot as
an extra image using SYSBuild.

Building an application with MCUBoot using SYSBuild allows users to
build both images using a single build.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-03 16:05:07 +02:00
Torsten Rasmussen 9d6cc39d6f cmake: initial sysbuild / multi image support
This is the initial commit with system build, sysbuild.

Using CMake as infrastructure together with the Zephyr sysbuild allows
us to support a convenient way of building a sample and allow for extra
images to be built as part of a larger system.

It uses Kconfig for configuration of image builds.
This allows for future extension with additional build images.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-03 16:05:07 +02:00
Dominik Ermel 851393f237 cmake: Fix "Loading Zephyr module(s)" message
Modules' names would get concatenated together into single
string, making the message hard to read.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-07-30 08:34:11 -05:00
Torsten Rasmussen 498973de0c cmake: support QUIET argument for find_package
The CMake function `find_package()` supports the flag QUIET.
QUIET will disable informational printing within CMakes own
find_package function.

To align with CMakes find_package, this commit will honor the QUIET flag
and disable informational printing related to package lookup.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-06-14 22:28:18 +02:00
Torsten Rasmussen d169171a66 cmake: Use CMake DEPRECATION level instead of WARNING
CMake provides a DEPRECATION level for messages.
This should be used instead of WARNING for deprecated features.

Using DEPRECATION allows users to disable the deprecation warning with
`cmake -Wno-deprecated ...`
or turn deprecation warning into an error using
`cmake -Werror=deprecated`

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-06-14 22:28:18 +02:00
Jordan Yates 568fb35a62 cmake: zephyr-package: add message mode
Explicitly set the <mode> value to the message printed when including
zephyr modules. The documentation is added to explain why it is
output to stderr, as this has been been subject of multiple PR's
(#31365,#43009).

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-03-23 13:24:41 +01:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Nazar Kazakov 9713f0d47c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-14 20:22:24 -04:00
Torsten Rasmussen f96ee77c7c cmake: function to update Zephyr_DIR when loading old Zephyr packages
Fixes: #43094

This commit introduces a function which updates Zephyr_DIR to point to
the directory of the Zephyr package being loaded.

For Zephyr 3.0 and earlier, the Zephyr_DIR might in some cases be
`Zephyr_DIR-NOTFOUND` or pointing to the Zephyr package including the
boilerplate code instead of the Zephyr package of the included
boilerplate code.

This code ensures that when a package is loaded then Zephyr_DIR will
point correctly.
This ensures that when Zephyr releases <=3.0 is loaded, then Zephyr_DIR
will point correctly, see more in #43094.

Old style Zephyr package will in some cases load boilerplate.cmake
directly so to ensure proper behavior, restrict boilerplate uses of
`find_package(Zephyr)` to not use default search path, but allow only
the current Zephyr.

Of the same reason, only print warning if Zephyr_DIR is not defined as
this indicates old style inclusion.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-03-07 16:35:54 +01:00
Torsten Rasmussen 0a64b08062 cmake: set Zephyr_DIR when loading Zephyr package
CMake find_package() is expected to set the cached variable Zephyr_DIR
with the value of the package included.

Zephyr_DIR in the CMakeCache is used by CMake re-runs for
`find_package(Zephyr)` to directly lookup the package to use.

The Zephyr_DIR is set correctly when a single Zephyr workspace is used
but may in some other cases be set to `Zephyr_DIR=Zephyr_DIR-NOTFOUND`.
This causes CMake to rerun the Zephyr package search mechanism and loop
through potential candidates before loading the correct Zephyr
installation.
After a second run, Zephyr_DIR is n some cases set to
`Zephyr_DIR=<path-to-including-Zephyr>` which might be different from
the Zephyr in use.

The Zephyr_DIR should be pointing to the package defined by ZEPHYR_BASE.

This commit ensures that when ZephyrConfig.cmake package is loaded, then
Zephyr_DIR is set correctly.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-03-07 16:35:54 +01:00
Torsten Rasmussen 31e90f1bc5 cmake: support sub-component loading in zephyr_default module
This commit allows to load only subcomponents of the default Zephyr
CMake module, zephyr_default.cmake.

This allows other tools to execute Zephyr CMake build system up to a
specific module and the stop further processing.

This commit is an enabler for future support in twister to process only
devicetree or kconfig, to allow test / sample filtering before
generating a complete build system.

Sub-components can be loaded as:
> find_package(Zephyr COMPONENTS zephyr_default:<sub-component>)

for example:
> find_package(Zephyr COMPONENTS zephyr_default:dts)

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-02-23 11:34:22 -08:00
Torsten Rasmussen e4ccde3774 cmake: moved unittest.cmake to Zephyr CMake modules dir
Move the unittest.cmake to the new Zephyr CMake modules dir.

This allows us to have a single Zephyr CMake package and load unittest
module as: 'find_package(Zephyr COMPONENTS unittest)'

This unifies the way Zephyr package is sourced and removes the need for
a dedicated ZephyrUnittest package.

Deprecate the use of: 'find_package(ZephyrUnittest)'

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-02-22 10:02:39 -08:00
Torsten Rasmussen 61453e4a58 cmake: Zephyr CMake package and CMake modules
Create a cmake/modules folder containing all Zephyr CMake modules.
All Zephyr cmake files that are included from boilerplate are now
converted into CMake modules which can be individually loaded.

The Zephyr CMake package is updated to support loading of individual
CMake modules using the COMPONENTS argument to `find_package(Zephyr)`.
If the COMPONENTS argument is not specified, the default Zephyr build
system will load.
If COMPONENTS is specified then, only those components and the
dependencies will be loaded.

If a Zephyr CMake module depends on another CMake module which has not
been loaded, it will automatically be loaded.

This allows us to modularize and reuse individual parts of the Zephyr
CMake build system in a more flexible way in future.

Such usage could be:
- Higher livel multi image build system
- Invocation of individual components, for example dts processing by
  twister without loading all build code
- Doc build
- Unittesting

With this new CMake package and CMake module scheme then direct
sourcing of boilerplate.cmake has been deprecated.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-02-22 10:02:39 -08:00
Torsten Rasmussen b574c4f626 cmake: check zephyr version if specified and ZEPHYR_BASE is set
Fixes: #35187

This extends the Zephyr package to also honor version when ZEPHYR_BASE
is set in environment.

Specifying `find_package(Zephyr 2.x.y)` without using ZEPHYR_BASE will
lookup a Zephyr in following order:
- Current repo, if that is a Zephyr repo
- Current west workspace
- Exported Zephyr CMake package for freestanding application
and ensure that the chosen Zephyr meets the version criteria.

When setting ZEPHYR_BASE in environment the version check is disabled
and the Zephyr referenced by ZEPHYR_BASE will always be used regardless
of its version.

A user doing `find_package(Zephyr 2.6.0)` and using ZEPHYR_BASE
presumable still want to ensure that the Zephyr referenced by
ZEPHYR_BASE is v2.6.0 or newer.

Also, `west build` with a freestanding application requires ZEPHYR_BASE
in order for west to lookup the `west build` extension command.

This practically means a user cannot both specify a Zephyr version for a
freestanding application and at the same time use `west build` but has
to use plain CMake to ensure correct version check, see #35187.

With this commit, users will have complete Zephyr package version
checking with freestanding applications
find_package(Zephyr 2.6.0 REQUIRED HINTS $ENV{ZEPHYR_BASE})
find_package(Zephyr 2.6.0 EXACT REQUIRED HINTS $ENV{ZEPHYR_BASE})
when also having ZEPHYR_BASE in environment.

This commit has no behavioral change for those patterns:
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
find_package(Zephyr 2.6.0 REQUIRED HINTS $ENV{ZEPHYR_BASE})
find_package(Zephyr 2.6.0 EXACT REQUIRED HINTS $ENV{ZEPHYR_BASE})
when ZEPHYR_BASE is not in environment.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-05-25 16:48:35 -05:00
Torsten Rasmussen fe5728dcb0 cmake: using MD5_INFILE variable instead of ZephyrPackagePath.txt
Running `west zephyr-export` creates an entry in the CMake User package
registry.

During this process, a temporary file `current_path.txt` is created.

This commit ensure the file is removed when no longer needed.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-02-23 19:34:27 +01:00
Torsten Rasmussen edde894d04 cmake: Zephyr CMake package clean-up and minor fix
Fixes: #27375

This is a cleanup of the Zephyr CMake package export.
The code has been simplified so that the export now happens through a
CMake script. This avoids several generated CMake build files compared
to previous export mode, and thus removes the need for a CMake pristine
script.

A benefit of this cleanup is that it also fixes #27375.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-08-19 12:52:33 -04:00
Torsten Rasmussen 4c28016e43 cmake: fixing infinite loop when searching for Zephyr on windows
Fixes: #24909

This commit compares against previous search path instead of '/'.
This fixes the infinite loop issue on windows when building a Zephyr
standalone application and not setting ZEPHYR_BASE.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Ethan Slattery <ethan@wildlifecomputers.com>
2020-05-05 10:02:11 -05:00
Torsten Rasmussen 3074a7a498 cmake: Relocating Zephyr Unittest CMake package.
Fixes: #23872

Relocating Zephyr Unittest CMake package to ensure that
HINTS ${ZEPHYR_BASE} in
find_package(ZephyrUnittest HINTS ${ZEPHYR_BASE}) works correctly when
the package has not been exported to CMake user package registry.

This ensure that the new package functionality is fully backwards
compatible on systems where the package is not exported and ZEPHYR_BASE
is set.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-31 10:00:15 -04:00
Torsten Rasmussen 8e929fd20c cmake: find_package to honor list of zephyr installations to prefer
This commit introduces ZEPHYR_PREFER which is a list that user can
specify when compiling an application.

This allows a user who has multiple Zephyr installations in the same
work-tree to provide a list of which Zephyr to prefer.

This is an extension to CMake VERSION field, as a user who is working
with multiple Zephyr installations could face a situation where multiple
Zephyr's is having same version, as example 2.2.99, in which case CMake
version is not sufficient.

Example, workspace looking as:
/projects/workspace/zephyr
/projects/workspace/zephyr-alternate
/projects/workspace/zephyr-wip
/projects/workspace/my_app

To prefer zephyr-alternate, then zephyr-wip the my_app/CMakeLists.txt
should look as:
set(ZEPHYR_PREFER "zephyr-alternate" "zephyr-wip")
find_package(Zephyr)

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Torsten Rasmussen e85cfe4554 cmake: West extension command for Zephyr config package registration
This command make it possible to use west for first time registration
of a Zephyr config package in CMake.

To register Zephyr as a CMake config package, invoke:
west zephyr-export

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Torsten Rasmussen 8829e8237a cmake: ZephyrUnittestConfig.cmake added
Adding ZephyrUnittestConfig.cmake and ZephyrUnittestConfigVersion.cmake
to allow unittest projects to use find_package to locate ZephyrUnittest.

This means that it will be possible to allow users to run CMake without
the need to source zephyr-env.sh or run zephyr-env.cmd.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Torsten Rasmussen caf596ef1b cmake: Zephyr package now sets ZEPHYR_BASE as cmake cached variable
This commit introduces ZEPHYR_BASE as a cached variable, ensures that
once ZEPHYR_BASE has been set in a project, it is sticky.
Using cached variable also allows users to reconfigure ZEPHYR_BASE if
they so wish.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Torsten Rasmussen 555eb9b5dc cmake: detection and using a not registered Zephyr repository package
This commit adds the possibility of using a Zephyr repository package
base even when it has not been exported to CMake package registry.

It also introduces the possibility of locating and using Zephyr
CMake config package correctly when invoking CMake on an out-of-tree
project.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Torsten Rasmussen 3dd96d8927 cmake: Added possibility to disable the printing of version
When ZephyrConfig package is being version checked, then
ZephyrConfigVersion.cmake loads version.cmake.

This causes a print message, such as the following to happen:
-- Zephyr version: 2.2.0

Now, in case a user has multiple Zephyr installations, this could
result in something similar to:
-- Zephyr version: 2.2.0
-- Zephyr version: 2.x.0
-- Zephyr version: 3.x.0
being printed.

This commit add the possibility to disable version printing.

With new Zephyr base find_package, printing of ZEPHYR_BASE is added
after the version, in order to make it easy for users to see which
Zephyr is used.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>

suggested change: print ZEPHYR_BASE
2020-03-27 16:23:46 +01:00
Torsten Rasmussen 81007172a4 cmake: adding ZephyrConfig.cmake to allow an easy way to locate Zephyr
Adding ZephyrConfig.cmake and ZephyrConfigVersion.cmake allows projects
to use find_package to locate Zephyr.

This means that it will be possible to allow users to run CMake without
the need to source zephyr-env.sh or run zephyr-env.cmd.

This is especially useful for IDEs such as Eclipse or SES, where it will
no longer be required to source the above files before launching the
IDE.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00