Commit 4959a024 authored by Torsten Rasmussen's avatar Torsten Rasmussen Committed by Alberto Escolar
Browse files

cmake: fix issue with parsing version file located in `/VERSION`



Fixes: #71384

A VERSION file placed in `/` or `<drive>:\` 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 `<app>/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: default avatarTorsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
parent e1ef3e41
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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)