Skip to content

Commit 9d19e26

Browse files
committed
cmake: normalize .config on reconfigure
olddefconfig only ran when .config was generated from the defconfig, so changes applied to an existing .config (e.g. with kconfig-tweak) never got their dependent defaults. Run olddefconfig on reconfigure as well, as the Make flow does on every build. Signed-off-by: raiden00pl <raiden00@railab.me> Assisted-by: Claude Code
1 parent 659f47a commit 9d19e26

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ if(NOT EXISTS ${CMAKE_BINARY_DIR}/.config OR NOT "${NUTTX_DEFCONFIG}" STREQUAL
367367
# Do olddefconfig step to expand the abbreviated defconfig into normal config
368368
nuttx_olddefconfig()
369369

370+
# save the orig compressed formatted defconfig at the very beginning
371+
nuttx_save_defconfig_orig()
372+
370373
file(RENAME ${CMAKE_BINARY_DIR}/.config.compressed
371374
${CMAKE_BINARY_DIR}/.config)
372375
set(ENV{KCONFIG_CONFIG} ${CMAKE_BINARY_DIR}/.config)
@@ -384,9 +387,11 @@ if(NOT EXISTS ${CMAKE_BINARY_DIR}/.config OR NOT "${NUTTX_DEFCONFIG}" STREQUAL
384387
endif()
385388
file(WRITE ${CMAKE_BINARY_DIR}/.config "${_config_init_content}")
386389

387-
# store original expanded .config
388-
configure_file(${CMAKE_BINARY_DIR}/.config ${CMAKE_BINARY_DIR}/.config.orig
389-
COPYONLY)
390+
# store original expanded .config; plain copy so .config does not become a
391+
# configure dependency: the compiler cannot change after the first configure,
392+
# so a modified .config must not reconfigure mid-build
393+
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/.config
394+
${CMAKE_BINARY_DIR}/.config.orig)
390395

391396
set(NUTTX_DEFCONFIG_SAVED
392397
${NUTTX_DEFCONFIG}
@@ -410,6 +415,11 @@ if(NOT EXISTS ${CMAKE_BINARY_DIR}/.config OR NOT "${NUTTX_DEFCONFIG}" STREQUAL
410415
message(STATUS " Board: ${NUTTX_BOARD}")
411416
message(STATUS " Config: ${NUTTX_CONFIG}")
412417
message(STATUS " Appdir: ${NUTTX_APPS_DIR}")
418+
else()
419+
# Normalize user modifications to .config (e.g. kconfig-tweak) so dependent
420+
# defaults materialize, as the Make flow does on each build
421+
set(ENV{KCONFIG_CONFIG} ${CMAKE_BINARY_DIR}/.config)
422+
nuttx_olddefconfig()
413423
endif()
414424

415425
# declare global custom targets at very beginning `nuttx_global` is used to hold

cmake/nuttx_kconfig.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,12 @@ function(nuttx_olddefconfig)
216216
"nuttx_olddefconfig: Failed to initialize Kconfig configuration: ${KCONFIG_OUTPUT}"
217217
)
218218
endif()
219+
endfunction()
220+
221+
# save the orig compressed formatted defconfig at the very beginning; only valid
222+
# during the initial configure while .config.compressed exists
219223

220-
# save the orig compressed formatted defconfig at the very beginning
224+
function(nuttx_save_defconfig_orig)
221225
execute_process(COMMAND savedefconfig --out ${CMAKE_BINARY_DIR}/defconfig.tmp
222226
WORKING_DIRECTORY ${NUTTX_DIR})
223227

@@ -227,7 +231,6 @@ function(nuttx_olddefconfig)
227231
${CMAKE_BINARY_DIR}/.config.compressed ${CMAKE_BINARY_DIR}/defconfig.tmp
228232
${CMAKE_BINARY_DIR}/defconfig.orig
229233
WORKING_DIRECTORY ${NUTTX_DIR})
230-
231234
endfunction()
232235

233236
function(nuttx_setconfig)

0 commit comments

Comments
 (0)