Skip to content

Commit

Permalink
cmake: set Zephyr_DIR when loading Zephyr package
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tejlmand authored and carlescufi committed Mar 7, 2022
1 parent 1a0fed7 commit 0a64b08
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions share/zephyr-package/cmake/ZephyrConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0a64b08

Please sign in to comment.