Cmake: Improved setconfig support for setting multiple parameters

Improved setconfig support for setting multiple parameters for the .config

Added Cmake and Ninja version info

Modified savedefconfig now behaves with the same logic as the tools/refresh.sh script used for the update stage (make build) on GitHub.
This commit is contained in:
simbit18 2024-10-03 12:15:59 +02:00 committed by Xiang Xiao
parent 69f58de304
commit 7db9b47465
4 changed files with 120 additions and 86 deletions

View file

@ -204,9 +204,7 @@ set(ENV{HOST_BSD} n)
set(ENV{HOST_WINDOWS} n)
set(ENV{HOST_OTHER} n)
# We define host
include(nuttx_sethost)
nuttx_sethost()
include(nuttx_parse_function_args)
include(nuttx_add_subdirectory)
@ -321,12 +319,7 @@ if(NOT EXISTS ${CMAKE_BINARY_DIR}/.config OR NOT "${NUTTX_DEFCONFIG}" STREQUAL
set(ENV{KCONFIG_CONFIG} ${CMAKE_BINARY_DIR}/.config.compressed)
# Do olddefconfig step to expand the abbreviated defconfig into normal config
execute_process(
COMMAND olddefconfig
ERROR_VARIABLE KCONFIG_ERROR
OUTPUT_VARIABLE KCONFIG_OUTPUT
RESULT_VARIABLE KCONFIG_STATUS
WORKING_DIRECTORY ${NUTTX_DIR})
nuttx_olddefconfig()
file(RENAME ${CMAKE_BINARY_DIR}/.config.compressed
${CMAKE_BINARY_DIR}/.config)
@ -335,22 +328,23 @@ if(NOT EXISTS ${CMAKE_BINARY_DIR}/.config OR NOT "${NUTTX_DEFCONFIG}" STREQUAL
# store original expanded .config
configure_file(${CMAKE_BINARY_DIR}/.config ${CMAKE_BINARY_DIR}/.config.orig
COPYONLY)
if(KCONFIG_ERROR)
message(WARNING "Kconfig Configuration Error: ${KCONFIG_ERROR}")
endif()
if(KCONFIG_STATUS AND NOT KCONFIG_STATUS EQUAL 0)
message(
FATAL_ERROR
"Failed to initialize Kconfig configuration: ${KCONFIG_OUTPUT}")
endif()
# We define host
nuttx_sethost()
set(NUTTX_DEFCONFIG_SAVED
${NUTTX_DEFCONFIG}
CACHE INTERNAL "Saved defconfig path" FORCE)
# Print configuration choices
message(STATUS " CMake ${CMAKE_VERSION}")
if(CMAKE_GENERATOR MATCHES "Ninja")
execute_process(
COMMAND ninja --version
OUTPUT_VARIABLE ninja_version
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS " Ninja ${ninja_version}")
endif()
message(STATUS " Board: ${NUTTX_BOARD}")
message(STATUS " Config: ${NUTTX_CONFIG}")
message(STATUS " Appdir: ${NUTTX_APPS_DIR}")

View file

@ -24,16 +24,9 @@
# changes)
set(KCONFIG_ENV
"KCONFIG_CONFIG=${CMAKE_BINARY_DIR}/.config"
"EXTERNALDIR=dummy"
"APPSDIR=${NUTTX_APPS_DIR}"
"DRIVERS_PLATFORM_DIR=dummy"
"APPSBINDIR=${NUTTX_APPS_BINDIR}"
"BINDIR=${CMAKE_BINARY_DIR}"
"HOST_LINUX=$<IF:$<BOOL:{LINUX}>,y,n>"
"HOST_MACOS=$<IF:$<BOOL:${APPLE}>,y,n>"
"HOST_WINDOWS=$<IF:$<BOOL:${WIN32}>,y,n>"
"HOST_OTHER=$<IF:$<BOOL:${OTHER_OS}>,y,n>")
"KCONFIG_CONFIG=${CMAKE_BINARY_DIR}/.config" "EXTERNALDIR=dummy"
"APPSDIR=${NUTTX_APPS_DIR}" "DRIVERS_PLATFORM_DIR=dummy"
"APPSBINDIR=${NUTTX_APPS_BINDIR}" "BINDIR=${CMAKE_BINARY_DIR}")
# Use qconfig instead of menuconfig since PowerShell not support curses
# redirection
@ -66,16 +59,6 @@ add_custom_target(
WORKING_DIRECTORY ${NUTTX_DIR}
USES_TERMINAL)
add_custom_target(
savedefconfig
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} savedefconfig --out
${CMAKE_BINARY_DIR}/defconfig.tmp
COMMAND ${CMAKE_COMMAND} -P ${NUTTX_DIR}/cmake/savedefconfig.cmake
${CMAKE_BINARY_DIR}/.config ${CMAKE_BINARY_DIR}/defconfig.tmp
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/defconfig
${NUTTX_DEFCONFIG}
WORKING_DIRECTORY ${NUTTX_DIR})
# utility target to restore .config from board's defconfig
add_custom_target(
resetconfig
@ -86,3 +69,21 @@ add_custom_target(
${CMAKE_BINARY_DIR}/.config.orig
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_PARENT_LIST_FILE}
WORKING_DIRECTORY ${NUTTX_DIR})
# utility target to refresh .config from board's defconfig for GITHUB
add_custom_target(
savedefconfig
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/SAVEconfig
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/.config
${CMAKE_BINARY_DIR}/SAVEconfig
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/.config
COMMAND ${CMAKE_COMMAND} -E copy ${NUTTX_DEFCONFIG}
${CMAKE_BINARY_DIR}/.config
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} olddefconfig
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} savedefconfig --out
${CMAKE_BINARY_DIR}/defconfig.tmp
COMMAND ${CMAKE_COMMAND} -P ${NUTTX_DIR}/cmake/savedefconfig.cmake
${CMAKE_BINARY_DIR}/.config ${CMAKE_BINARY_DIR}/defconfig.tmp
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/defconfig
${NUTTX_DEFCONFIG}
WORKING_DIRECTORY ${NUTTX_DIR})

View file

@ -159,9 +159,43 @@ function(nuttx_generate_kconfig)
endif()
endfunction()
function(nuttx_setconfig)
function(nuttx_olddefconfig)
execute_process(
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} setconfig ${ARGN}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_QUIET ERROR_QUIET)
COMMAND olddefconfig
ERROR_VARIABLE KCONFIG_ERROR
OUTPUT_VARIABLE KCONFIG_OUTPUT
RESULT_VARIABLE KCONFIG_STATUS
WORKING_DIRECTORY ${NUTTX_DIR})
if(KCONFIG_ERROR)
message(WARNING "Kconfig Configuration Error: ${KCONFIG_ERROR}")
endif()
if(KCONFIG_STATUS AND NOT KCONFIG_STATUS EQUAL 0)
message(
FATAL_ERROR
"nuttx_olddefconfig: Failed to initialize Kconfig configuration: ${KCONFIG_OUTPUT}"
)
endif()
endfunction()
function(nuttx_setconfig)
set(ENV{KCONFIG_CONFIG} ${CMAKE_BINARY_DIR}/.config)
execute_process(
COMMAND setconfig ${ARGN} --kconfig ${NUTTX_DIR}/Kconfig
ERROR_VARIABLE KCONFIG_ERROR
OUTPUT_VARIABLE KCONFIG_OUTPUT
RESULT_VARIABLE KCONFIG_STATUS
WORKING_DIRECTORY ${NUTTX_DIR})
if(KCONFIG_ERROR)
message(WARNING "Kconfig Configuration Error: ${KCONFIG_ERROR}")
endif()
if(KCONFIG_STATUS AND NOT KCONFIG_STATUS EQUAL 0)
message(
FATAL_ERROR
"nuttx_setconfig: Failed to initialize Kconfig configuration: ${KCONFIG_OUTPUT}"
)
endif()
endfunction()

View file

@ -42,61 +42,66 @@ function(nuttx_sethost)
OUTPUT_VARIABLE ARCHITECTURE)
endif()
set(NUTTX_SYSTEM_SETHOST)
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|Darwin|FreeBSD")
nuttx_setconfig(HOST_WINDOWS=n)
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
message(" Select HOST_LINUX=y")
nuttx_setconfig(HOST_LINUX=y)
list(APPEND NUTTX_SYSTEM_SETHOST "HOST_LINUX=y")
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
message(" Select HOST_MACOS=y")
nuttx_setconfig(HOST_MACOS=y)
list(APPEND NUTTX_SYSTEM_SETHOST "HOST_MACOS=y")
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "FreeBSD")
message(" Select HOST_BSD=y")
nuttx_setconfig(HOST_BSD=y)
list(APPEND NUTTX_SYSTEM_SETHOST "HOST_BSD=y")
endif()
# Enable the System V ABI
nuttx_setconfig(SIM_X8664_SYSTEMV=y)
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "MSYS|CYGWIN|Windows")
# Enable Windows and the Microsoft ABI
message(" Select HOST_WINDOWS=y")
nuttx_setconfig(HOST_LINUX=n)
nuttx_setconfig(HOST_MACOS=n)
nuttx_setconfig(HOST_BSD=n)
nuttx_setconfig(HOST_WINDOWS=y)
nuttx_setconfig(SIM_X8664_MICROSOFT=y)
list(APPEND NUTTX_SYSTEM_SETHOST "HOST_WINDOWS=y")
if(CMAKE_HOST_SYSTEM_NAME MATCHES "CYGWIN")
message(" Select WINDOWS_CYGWIN=y")
nuttx_setconfig(WINDOWS_CYGWIN=y)
list(APPEND NUTTX_SYSTEM_SETHOST "WINDOWS_CYGWIN=y")
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "MSYS")
message(" Select WINDOWS_MSYS=y")
nuttx_setconfig(WINDOWS_MSYS=y)
list(APPEND NUTTX_SYSTEM_SETHOST "WINDOWS_MSYS=y")
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
message(" Select WINDOWS_NATIVE=y")
nuttx_setconfig(EXPERIMENTAL=y)
nuttx_setconfig(WINDOWS_NATIVE=y)
if(NOT MSVC)
list(APPEND NUTTX_SYSTEM_SETHOST "EXPERIMENTAL=y")
list(APPEND NUTTX_SYSTEM_SETHOST "WINDOWS_NATIVE=y")
else()
message(" MSVC toolchain")
endif()
endif()
else()
message(" Select HOST_OTHER=y")
nuttx_setconfig(HOST_LINUX=n)
nuttx_setconfig(HOST_MACOS=n)
nuttx_setconfig(HOST_BSD=n)
nuttx_setconfig(HOST_WINDOWS=n)
nuttx_setconfig(HOST_OTHER=y)
nuttx_setconfig(OTHER_OS=y)
list(APPEND NUTTX_SYSTEM_SETHOST "HOST_OTHER=y")
# nuttx_setconfig(OTHER_OS=y)
endif()
if("${NUTTX_BOARD}" STREQUAL "sim")
if(ARCHITECTURE STREQUAL "x86_64")
message(" Select HOST_X86_64=y")
nuttx_setconfig(HOST_X86_64=y)
list(APPEND NUTTX_SYSTEM_SETHOST "HOST_X86_64=y")
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|Darwin|FreeBSD")
# Enable the System V ABI
list(APPEND NUTTX_SYSTEM_SETHOST "SIM_X8664_SYSTEMV=y")
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "MSYS|CYGWIN|Windows")
# Enable Microsoft ABI and the System V ABI
list(APPEND NUTTX_SYSTEM_SETHOST "SIM_X8664_SYSTEMV=y")
list(APPEND NUTTX_SYSTEM_SETHOST "SIM_X8664_MICROSOFT=y")
endif()
elseif(ARCHITECTURE STREQUAL "x86")
message(" Select HOST_X86=y")
nuttx_setconfig(HOST_X86=y)
list(APPEND NUTTX_SYSTEM_SETHOST "HOST_X86=y")
elseif(ARCHITECTURE STREQUAL "arm")
message(" Select HOST_ARM=y")
nuttx_setconfig(HOST_ARM=y)
list(APPEND NUTTX_SYSTEM_SETHOST "HOST_ARM=y")
elseif(ARCHITECTURE STREQUAL "arm64")
message(" Select HOST_ARM64=y")
nuttx_setconfig(HOST_ARM64=y)
list(APPEND NUTTX_SYSTEM_SETHOST "HOST_ARM64=y")
endif()
endif()
# message(" nuttx_setconfig: ${NUTTX_SYSTEM_SETHOST}")
nuttx_setconfig("${NUTTX_SYSTEM_SETHOST}")
endfunction()