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>
This commit is contained in:
Torsten Rasmussen 2022-03-01 09:40:17 +01:00 committed by Carles Cufí
parent 1a0fed70d5
commit 0a64b08062

View file

@ -11,6 +11,9 @@
# It will be empty if not set in environment.
macro(include_boilerplate location)
set(Zephyr_DIR ${ZEPHYR_BASE}/share/zephyr-package/cmake CACHE PATH
"The directory containing a CMake configuration file for Zephyr." FORCE
)
list(PREPEND CMAKE_MODULE_PATH ${ZEPHYR_BASE}/cmake/modules)
if(ZEPHYR_UNITTEST)
message(WARNING "The ZephyrUnittest CMake package has been deprecated.\n"