From d0c5bbe0fcc3055685b57b6a343de432fdc59653 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Sun, 10 Aug 2025 20:34:49 +0200 Subject: [PATCH] fix(cmakev2/idf): fix IDF_TARGET initialization Currently, the target consistency check with sdkconfig is performed even if sdkconfig is not present, by comparing the selected target with the target defined in sdkconfig.defaults. This results in an inconsistency report when a different target is set in the IDF_TARGET environment or cmake variable compared to sdkconfig.defaults. The behavior in cmakev1 is to prioritize IDF_TARGET and ignore values in sdkconfig.defaults. Perform the consistency check only if the sdkconfig file exists. Additionally, skip this consistency check if a set-target action is taking place, as the old target in sdkconfig is being replaced with a new value anyway. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/idf.cmake | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/cmakev2/idf.cmake b/tools/cmakev2/idf.cmake index 0489055a5b0..77886909998 100644 --- a/tools/cmakev2/idf.cmake +++ b/tools/cmakev2/idf.cmake @@ -202,9 +202,12 @@ function(__init_idf_target) endif() # Verify that the chosen target aligns with the sdkconfig. - if(sdkconfig_target) - if(NOT "${sdkconfig_target}" STREQUAL "${target}") - idf_die("Target '${sdkconfig_target}' in sdkconfig '${sdkconfig_file}' " + if(EXISTS "${sdkconfig}") + if("$ENV{_IDF_PY_SET_TARGET_ACTION}" STREQUAL "1") + idf_dbg("The target consistency check for the target specified in ${sdkconfig} " + "was skipped because the set-target action is being executed.") + elseif(NOT "${sdkconfig_target}" STREQUAL "${target}") + idf_die("Target '${sdkconfig_target}' in sdkconfig '${sdkconfig}' " "does not match currently selected IDF_TARGET '${target}'. " "To change the target, clear the build directory and sdkconfig file, " "and build the project again.")