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 <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata
2025-11-04 07:48:12 +01:00
parent f1063363f3
commit d0c5bbe0fc
+6 -3
View File
@@ -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.")