From 99b3fc8001693e906214b7e6840cc5e19dd2c251 Mon Sep 17 00:00:00 2001 From: simbit18 <101105604+simbit18@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:15:59 +0200 Subject: [PATCH] Cmake: Improved setconfig support for setting multiple parameters Improved setconfig support for setting multiple parameters for the .config Added Cmake and Ninja version info Added utility target to check .config from board's defconfig for refresh stage on GITHUB --- CMakeLists.txt | 26 ++++------- cmake/menuconfig.cmake | 31 ++++++++----- cmake/nuttx_kconfig.cmake | 40 +++++++++++++++-- cmake/nuttx_sethost.cmake | 95 ++++++++++++++++++++------------------- tools/testbuild.sh | 4 +- 5 files changed, 119 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b11486ef62a49..2311ff1c9a25c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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,21 @@ 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}") diff --git a/cmake/menuconfig.cmake b/cmake/menuconfig.cmake index 6a8b0efc4c776..544b9e4e3e50d 100644 --- a/cmake/menuconfig.cmake +++ b/cmake/menuconfig.cmake @@ -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=$,y,n>" - "HOST_MACOS=$,y,n>" - "HOST_WINDOWS=$,y,n>" - "HOST_OTHER=$,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 @@ -86,3 +79,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( + nuttx_job_refresh + 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}) diff --git a/cmake/nuttx_kconfig.cmake b/cmake/nuttx_kconfig.cmake index 371bf2b08aea2..76b65e3387b35 100644 --- a/cmake/nuttx_kconfig.cmake +++ b/cmake/nuttx_kconfig.cmake @@ -159,9 +159,43 @@ function(nuttx_generate_kconfig) endif() endfunction() +function(nuttx_olddefconfig) + execute_process( + 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 ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} setconfig ${ARGN} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - OUTPUT_QUIET ERROR_QUIET) + 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() diff --git a/cmake/nuttx_sethost.cmake b/cmake/nuttx_sethost.cmake index 308b11f41a8ae..e51f832316a22 100644 --- a/cmake/nuttx_sethost.cmake +++ b/cmake/nuttx_sethost.cmake @@ -29,11 +29,11 @@ function(nuttx_sethost) if(DEFINED ENV{PROCESSOR_ARCHITEW6432}) set(CMAKE_HOST_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITEW6432}") message( - STATUS "ENV{PROCESSOR_ARCHITEW6432} = $ENV{PROCESSOR_ARCHITEW6432}") + STATUS " ENV{PROCESSOR_ARCHITEW6432} = $ENV{PROCESSOR_ARCHITEW6432}") else() set(CMAKE_HOST_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}") message( - STATUS "ENV{PROCESSOR_ARCHITECTURE} = $ENV{PROCESSOR_ARCHITECTURE}") + STATUS " ENV{PROCESSOR_ARCHITECTURE} = $ENV{PROCESSOR_ARCHITECTURE}") endif() else() execute_process( @@ -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) + message(" Select 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) + message(" Select 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) + message(" Select 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) + message(" Select HOST_WINDOWS=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) + message(" Select 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) + message(" Select 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) + message(" Select 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) + message(" Select HOST_OTHER=y") + list(APPEND NUTTX_SYSTEM_SETHOST "HOST_OTHER=y") + # nuttx_setconfig(OTHER_OS=y) endif() - if(ARCHITECTURE STREQUAL "x86_64") - message(" Select HOST_X86_64=y") - nuttx_setconfig(HOST_X86_64=y) - elseif(ARCHITECTURE STREQUAL "x86") - message(" Select HOST_X86=y") - nuttx_setconfig(HOST_X86=y) - elseif(ARCHITECTURE STREQUAL "arm") - message(" Select HOST_ARM=y") - nuttx_setconfig(HOST_ARM=y) - elseif(ARCHITECTURE STREQUAL "arm64") - message(" Select HOST_ARM64=y") - nuttx_setconfig(HOST_ARM64=y) + if("${NUTTX_BOARD}" STREQUAL "sim") + if(ARCHITECTURE STREQUAL "x86_64") + message(" Select 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") + list(APPEND NUTTX_SYSTEM_SETHOST "HOST_X86=y") + elseif(ARCHITECTURE STREQUAL "arm") + message(" Select HOST_ARM=y") + list(APPEND NUTTX_SYSTEM_SETHOST "HOST_ARM=y") + elseif(ARCHITECTURE STREQUAL "arm64") + message(" Select 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() diff --git a/tools/testbuild.sh b/tools/testbuild.sh index 91820c383ef46..92308e889d1cd 100755 --- a/tools/testbuild.sh +++ b/tools/testbuild.sh @@ -450,8 +450,8 @@ function refresh_cmake { kconfig-tweak --file $nuttx/build/.config -d $toolchain fi - if ! cmake --build build -t savedefconfig 1>/dev/null; then - cmake --build build -t savedefconfig + if ! cmake --build build -t nuttx_job_refresh 1>/dev/null; then + cmake --build build -t nuttx_job_refresh fail=1 fi