From 90875ec49205f8418f06a85465cdd4b43d06e1ea Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Mon, 16 Feb 2026 10:04:24 +0100 Subject: [PATCH] fix(cmake): Fall back to version from components when git describe fails When version.txt does not exist and git describe fails (e.g. in release archives or environments without git), IDF_VER was set to the raw git_describe output which resolves to "-128-NOTFOUND", causing esp_get_idf_version() to return a garbled string. Add a fallback that constructs the version string from the IDF_VERSION_MAJOR, IDF_VERSION_MINOR and IDF_VERSION_PATCH variables when git describe is not available. Closes https://github.com/espressif/esp-idf/issues/18240 Co-Authored-By: Claude Opus 4.6 Signed-off-by: Frantisek Hrbata --- tools/cmake/build.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 52c6b9bd0e..54d01ba4f5 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -147,8 +147,10 @@ function(__build_get_idf_git_revision) if(EXISTS "${idf_path}/version.txt") file(STRINGS "${idf_path}/version.txt" idf_ver_t) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${idf_path}/version.txt") - else() + elseif(idf_ver_git) set(idf_ver_t ${idf_ver_git}) + else() + set(idf_ver_t "v${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}.${IDF_VERSION_PATCH}") endif() # cut IDF_VER to required 32 characters. string(SUBSTRING "${idf_ver_t}" 0 31 idf_ver)