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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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
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>