From 0a64b080622d421f9681260d984b313d32b393f1 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Tue, 1 Mar 2022 09:40:17 +0100 Subject: [PATCH] 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=` 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 --- share/zephyr-package/cmake/ZephyrConfig.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/share/zephyr-package/cmake/ZephyrConfig.cmake b/share/zephyr-package/cmake/ZephyrConfig.cmake index 8c06377e716..c81efc4f030 100644 --- a/share/zephyr-package/cmake/ZephyrConfig.cmake +++ b/share/zephyr-package/cmake/ZephyrConfig.cmake @@ -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"