From c5321c1dbed9c09e24de3d09284b3ffac4bf6226 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Thu, 4 Jan 2024 14:22:22 +0100 Subject: [PATCH] cmake: make SoC optional for boards containing a single SoC Allowing users to omit the SoC when building for a board containing a single SoC make less typing required when building. Full identifier is still supported. This means that if board 'plank' contains a single SoC 'foo', then the following input are equivalent: -DBOARD=plank -DBOARD=plank/foo When building for variants on single SoC boards, a `//` can be used to indicate SoC field and build system will insert the SoC if the board has just a single SoC, as example build the 'bar' variant for 'plank' board can be specified as: -DBOARD=plank//bar -DBOARD=plank/foo/bar The enhancement allows all boards to specify the SoC on the board without forcing users to type the SoC as part of BOARD input. As example, -DBOARD=bbc_microbit, is allowed in addition to -DBOARD=bbc_microbit/nrf52822. Signed-off-by: Torsten Rasmussen --- cmake/modules/boards.cmake | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmake/modules/boards.cmake b/cmake/modules/boards.cmake index eb7444b6228..cd4b4fd710f 100644 --- a/cmake/modules/boards.cmake +++ b/cmake/modules/boards.cmake @@ -153,7 +153,7 @@ if(NOT BOARD_DIR) set(format_str "{NAME}\;{DIR}\;{HWM}\;") set(format_str "${format_str}{REVISION_FORMAT}\;{REVISION_DEFAULT}\;{REVISION_EXACT}\;") - set(format_str "${format_str}{REVISIONS}\;{IDENTIFIERS}") + set(format_str "${format_str}{REVISIONS}\;{SOCS}\;{IDENTIFIERS}") execute_process(${list_boards_commands} --board=${BOARD} --cmakeformat=${format_str} @@ -166,7 +166,7 @@ if(NOT BOARD_DIR) endif() string(STRIP "${ret_board}" ret_board) set(single_val "NAME;DIR;HWM;REVISION_FORMAT;REVISION_DEFAULT;REVISION_EXACT") - set(multi_val "REVISIONS;IDENTIFIERS") + set(multi_val "REVISIONS;SOCS;IDENTIFIERS") cmake_parse_arguments(BOARD "" "${single_val}" "${multi_val}" ${ret_board}) set(BOARD_DIR ${BOARD_DIR} CACHE PATH "Board directory for board (${BOARD})" FORCE) @@ -220,6 +220,14 @@ elseif(HWMv2) endif() if(BOARD_IDENTIFIERS) + # Allow users to omit the SoC when building for a board with a single SoC. + list(LENGTH BOARD_SOCS socs_length) + if(NOT DEFINED BOARD_IDENTIFIER AND socs_length EQUAL 1) + set(BOARD_IDENTIFIER "/${BOARD_SOCS}") + elseif("${BOARD_IDENTIFIER}" MATCHES "^//.*" AND socs_length EQUAL 1) + string(REGEX REPLACE "^//" "/${BOARD_SOCS}/" BOARD_IDENTIFIER "${BOARD_IDENTIFIER}") + endif() + if(NOT ("${BOARD}${BOARD_IDENTIFIER}" IN_LIST BOARD_IDENTIFIERS)) string(REPLACE ";" "\n" BOARD_IDENTIFIERS "${BOARD_IDENTIFIERS}") message(FATAL_ERROR "Board identifier `${BOARD_IDENTIFIER}` for board \