Skip to content

Commit

Permalink
cmake: add proper dependency tracking for config.h
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Aug 29, 2024
1 parent b1f3be6 commit adfaa7d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
20 changes: 1 addition & 19 deletions cmake/menuconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
#
# ##############################################################################

# menuconfig target this triggers a reconfiguration (TODO: do only if config
# changes)
# menuconfig target this triggers a reconfiguration

set(KCONFIG_ENV
"KCONFIG_CONFIG=${CMAKE_BINARY_DIR}/.config"
Expand All @@ -45,10 +44,6 @@ endif()
add_custom_target(
menuconfig
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} ${MENUCONFIG}
COMMAND ${CMAKE_COMMAND} -E remove -f
${CMAKE_BINARY_DIR}/include/nuttx/config.h # invalidate existing
# config
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_PARENT_LIST_FILE}
WORKING_DIRECTORY ${NUTTX_DIR}
USES_TERMINAL)

Expand All @@ -57,10 +52,6 @@ add_custom_target(
add_custom_target(
qconfig
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} guiconfig
COMMAND ${CMAKE_COMMAND} -E remove -f
${CMAKE_BINARY_DIR}/include/nuttx/config.h # invalidate existing
# config
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_PARENT_LIST_FILE}
WORKING_DIRECTORY ${NUTTX_DIR}
USES_TERMINAL)

Expand All @@ -77,20 +68,12 @@ add_custom_target(
add_custom_target(
oldconfig
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} oldconfig
COMMAND ${CMAKE_COMMAND} -E remove -f
${CMAKE_BINARY_DIR}/include/nuttx/config.h # invalidate existing
# config
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_PARENT_LIST_FILE}
WORKING_DIRECTORY ${NUTTX_DIR}
USES_TERMINAL) # stdin access required to prompt for new config keys

add_custom_target(
olddefconfig
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} olddefconfig
COMMAND ${CMAKE_COMMAND} -E remove -f
${CMAKE_BINARY_DIR}/include/nuttx/config.h # invalidate existing
# config
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_PARENT_LIST_FILE}
WORKING_DIRECTORY ${NUTTX_DIR})

# utility target to restore .config from board's defconfig
Expand All @@ -101,5 +84,4 @@ add_custom_target(
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} olddefconfig
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/.config
${CMAKE_BINARY_DIR}/.config.orig
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_PARENT_LIST_FILE}
WORKING_DIRECTORY ${NUTTX_DIR})
13 changes: 12 additions & 1 deletion cmake/nuttx_generate_headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ if(NOT EXISTS ${CMAKE_BINARY_DIR}/include/nuttx)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include/nuttx)
endif()

include(nuttx_mkconfig)
include(nuttx_mkversion)

# Setup symbolic link generation
Expand Down Expand Up @@ -137,6 +136,18 @@ else()
file(REMOVE ${CMAKE_BINARY_DIR}/include/setjmp.h)
endif()

# Generate config.h. This is done through add_custom_command rather than
# include(nuttx_mkconfig) to be able to mark .config as a dependency of
# config.h. Otherwise, changes in .config would not cause config.h to be
# re-generated during incremental builds.

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/include/nuttx/config.h
COMMAND
${CMAKE_COMMAND} -D NUTTX_DIR=${NUTTX_DIR} -D NUTTX_BOARD=${NUTTX_BOARD} -D
NUTTX_CONFIG=${NUTTX_CONFIG} -P ${NUTTX_DIR}/cmake/nuttx_mkconfig.cmake
DEPENDS ${CMAKE_BINARY_DIR}/.config ${CMAKE_BINARY_DIR}/.config.orig)

# Add final context target that ties together all of the above The context
# target is invoked on each target build to assure that NuttX is properly
# configured. The basic configuration steps include creation of the the
Expand Down
29 changes: 13 additions & 16 deletions cmake/nuttx_mkconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,24 @@
#
# ##############################################################################

# !!! READ BEFORE CHANGING THIS FILE !!!
#
# This file is not included by the rest of the CMake configuration, but it is
# instead invoked separately through `cmake -P`.
#
# This means most variables, functions and macros defined in the rest of the
# CMake configuration are NOT available here. To add missing modules, add the
# include() declarations below. To add missing variables, change the command
# execution in nuttx_generate_headers.cmake to add -D flags.

set(CMAKE_MODULE_PATH "${NUTTX_DIR}/cmake")
include(nuttx_kconfig)

if(NOT EXISTS ${CMAKE_BINARY_DIR}/.config)
return()
endif()

if(NOT EXISTS ${CMAKE_BINARY_DIR}/.config.prev)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/.config
${CMAKE_BINARY_DIR}/.config.prev
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()

execute_process(
COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_BINARY_DIR}/.config
${CMAKE_BINARY_DIR}/.config.prev
RESULT_VARIABLE COMPARE_RESULT
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

set(CONFIG_H ${CMAKE_BINARY_DIR}/include/nuttx/config.h)
if(COMPARE_RESULT EQUAL 0 AND EXISTS ${CONFIG_H})
return()
endif()

set(BASE_DEFCONFIG "${NUTTX_BOARD}/${NUTTX_CONFIG}")
execute_process(
Expand Down

0 comments on commit adfaa7d

Please sign in to comment.