From 4959a0241e3fd23875fac825a37228c3883633dd Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Thu, 11 Apr 2024 13:38:07 +0200 Subject: [PATCH] cmake: fix issue with parsing version file located in `/VERSION` Fixes: #71384 A VERSION file placed in `/` or `:\` was accidentally being picked up during `find_package(Zephyr)`. This happened because Zephyr loads the VERSION file to determine if it is the correct Zephyr to use. During initial phase of find_package(), then APPLICATION_SOURCE_DIR is not defined, causing one version file to be picked up from `/VERSION` instead of `/VERSION`. `/VERSION` is outside any Zephyr repo, west workspace, or the application itself and therefore should not be picked up accidentally. Fix this be checking that APPLICATION_SOURCE_DIR is defined, and only when defined, look for a VERSION file there. Signed-off-by: Torsten Rasmussen --- cmake/modules/version.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/modules/version.cmake b/cmake/modules/version.cmake index 72c0424031..16d772e2cd 100644 --- a/cmake/modules/version.cmake +++ b/cmake/modules/version.cmake @@ -36,8 +36,12 @@ # The final load of `version.cmake` will setup correct build version values. if(NOT DEFINED VERSION_FILE AND NOT DEFINED VERSION_TYPE) - set(VERSION_FILE ${ZEPHYR_BASE}/VERSION ${APPLICATION_SOURCE_DIR}/VERSION) - set(VERSION_TYPE KERNEL APP) + set(VERSION_FILE ${ZEPHYR_BASE}/VERSION) + set(VERSION_TYPE KERNEL) + if(DEFINED APPLICATION_SOURCE_DIR) + list(APPEND VERSION_FILE ${APPLICATION_SOURCE_DIR}/VERSION) + list(APPEND VERSION_TYPE APP) + endif() endif() foreach(type file IN ZIP_LISTS VERSION_TYPE VERSION_FILE)