From 7db9b47465edd7afdda4ccc90c38a40702333d1d 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 Modified savedefconfig now behaves with the same logic as the tools/refresh.sh script used for the update stage (make build) on GitHub. --- CMakeLists.txt | 28 +++++------- cmake/menuconfig.cmake | 41 ++++++++--------- cmake/nuttx_kconfig.cmake | 42 +++++++++++++++-- cmake/nuttx_sethost.cmake | 95 ++++++++++++++++++++------------------- 4 files changed, 120 insertions(+), 86 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a3c52fa15..62ca601c07 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,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}") diff --git a/cmake/menuconfig.cmake b/cmake/menuconfig.cmake index 6a8b0efc4c..7dfd4a6c99 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 @@ -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}) diff --git a/cmake/nuttx_kconfig.cmake b/cmake/nuttx_kconfig.cmake index 371bf2b08a..76b65e3387 100644 --- a/cmake/nuttx_kconfig.cmake +++ b/cmake/nuttx_kconfig.cmake @@ -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() diff --git a/cmake/nuttx_sethost.cmake b/cmake/nuttx_sethost.cmake index 308b11f41a..e51f832316 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()