diff --git a/cmake/modules/kconfig.cmake b/cmake/modules/kconfig.cmake index b87e08e6f12..f7f17f07246 100644 --- a/cmake/modules/kconfig.cmake +++ b/cmake/modules/kconfig.cmake @@ -313,6 +313,18 @@ foreach(f ${merge_config_files}) set(merge_config_files_checksum "${merge_config_files_checksum}${checksum}") endforeach() +# Add to the checksum all the Kconfig files which were used last time +set(merge_kconfig_checksum "") +if(EXISTS ${PARSED_KCONFIG_SOURCES_TXT}) + file(STRINGS ${PARSED_KCONFIG_SOURCES_TXT} parsed_kconfig_sources_list ENCODING UTF-8) + foreach(f ${parsed_kconfig_sources_list}) + if(EXISTS ${f}) + file(MD5 ${f} checksum) + set(merge_kconfig_checksum "${merge_kconfig_checksum}${checksum}") + endif() + endforeach() +endif() + # Create a new .config if it does not exists, or if the checksum of # the dependencies has changed set(merge_config_files_checksum_file ${PROJECT_BINARY_DIR}/.cmake.dotconfig.checksum) @@ -326,7 +338,7 @@ if(EXISTS ${DOTCONFIG} AND EXISTS ${merge_config_files_checksum_file}) merge_config_files_checksum_prev ) if( - ${merge_config_files_checksum} STREQUAL + ${merge_config_files_checksum}${merge_kconfig_checksum} STREQUAL ${merge_config_files_checksum_prev} ) # Checksum is the same as before @@ -373,17 +385,17 @@ if(NOT "${ret}" STREQUAL "0") message(FATAL_ERROR "command failed with return code: ${ret}") endif() -if(CREATE_NEW_DOTCONFIG) - # Write the new configuration fragment checksum. Only do this if kconfig.py - # succeeds, to avoid marking zephyr/.config as up-to-date when it hasn't been - # regenerated. - file(WRITE ${merge_config_files_checksum_file} - ${merge_config_files_checksum}) -endif() - # Read out the list of 'Kconfig' sources that were used by the engine. file(STRINGS ${PARSED_KCONFIG_SOURCES_TXT} parsed_kconfig_sources_list ENCODING UTF-8) +# Recalculate the Kconfig files' checksum, since the list of files may have +# changed. +set(merge_kconfig_checksum "") +foreach(f ${parsed_kconfig_sources_list}) + file(MD5 ${f} checksum) + set(merge_kconfig_checksum "${merge_kconfig_checksum}${checksum}") +endforeach() + # Force CMAKE configure when the Kconfig sources or configuration files changes. foreach(kconfig_input ${merge_config_files} @@ -393,6 +405,14 @@ foreach(kconfig_input set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${kconfig_input}) endforeach() +if(CREATE_NEW_DOTCONFIG) + # Write the new configuration fragment checksum. Only do this if kconfig.py + # succeeds, to avoid marking zephyr/.config as up-to-date when it hasn't been + # regenerated. + file(WRITE ${merge_config_files_checksum_file} + ${merge_config_files_checksum}${merge_kconfig_checksum}) +endif() + add_custom_target(config-twister DEPENDS ${DOTCONFIG}) # Remove the CLI Kconfig symbols from the namespace and