zephyr/share/zephyr-package/cmake
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
..
ZephyrConfig.cmake
ZephyrConfigVersion.cmake cmake: check zephyr version if specified and ZEPHYR_BASE is set 2021-05-25 16:48:35 -05:00
zephyr_export.cmake
zephyr_package_search.cmake