Skip to content

Commit

Permalink
Cmake: Improved setconfig support for setting multiple parameters
Browse files Browse the repository at this point in the history
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
  • Loading branch information
simbit18 committed Oct 3, 2024
1 parent 51d6e8f commit 99b3fc8
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 77 deletions.
26 changes: 9 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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}")
Expand Down
31 changes: 21 additions & 10 deletions cmake/menuconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
40 changes: 37 additions & 3 deletions cmake/nuttx_kconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
95 changes: 50 additions & 45 deletions cmake/nuttx_sethost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
4 changes: 2 additions & 2 deletions tools/testbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 99b3fc8

Please sign in to comment.