From 8edb6adb91191ef329b6044ea298d74b11c7835d Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Thu, 26 Feb 2026 19:45:16 -0500 Subject: fix: No Longer Resourcing Defconfig during build When building, the cmake environment would rerun the configuration stage, including sourcing the original defconfig and overriding the local .config. Now the config.cmake is generated when the defconfig is sourced, and if it exists already, then the defconfig is ignored. --- cmake/Kconfig.cmake | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/cmake/Kconfig.cmake b/cmake/Kconfig.cmake index 232a11f..47f8295 100644 --- a/cmake/Kconfig.cmake +++ b/cmake/Kconfig.cmake @@ -7,25 +7,44 @@ set(TOOL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools) set(KCONFIG_DIR ${TOOL_DIR}/Kconfiglib) set(LOCAL_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/.config) -if(DEFCONFIG) +if(DEFCONFIG AND NOT EXISTS ${CMAKE_BINARY_DIR}/config.cmake) execute_process( COMMAND ${KCONFIG_DIR}/defconfig.py ${CMAKE_CURRENT_SOURCE_DIR}/configs/${DEFCONFIG} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + + execute_process( + COMMAND ${KCONFIG_DIR}/genconfig.py --header-path ${CMAKE_BINARY_DIR}/generated.h --config-out + ${CMAKE_BINARY_DIR}/config.make + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + execute_process( + COMMAND ${TOOL_DIR}/make-cmake-config ${CMAKE_BINARY_DIR}/config.make + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS + ${CMAKE_BINARY_DIR}/config.cmake + ) + +elseif(EXISTS ${CMAKE_BINARY_DIR}/config.cmake) + message("Ignoring DEFCONFIG") else() message(FATAL_ERROR "DEFCONFIG not set.") endif() +include(${CMAKE_BINARY_DIR}/config.cmake) + add_custom_target(menuconfig COMMAND ${KCONFIG_DIR}/menuconfig.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) -add_custom_target(genconfig +add_custom_command(TARGET menuconfig POST_BUILD COMMAND ${KCONFIG_DIR}/genconfig.py --header-path ${CMAKE_BINARY_DIR}/generated.h --config-out ${CMAKE_BINARY_DIR}/config.make COMMAND ${TOOL_DIR}/make-cmake-config ${CMAKE_BINARY_DIR}/config.make - COMMAND cmake -B ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) -- cgit v1.2.3