cmake: shields: Simplify shield processing, print shields from modules

Fix issue #67244 in which boards from external modules where not
printed in the help message (displayed for `shields` target or
when trying to build with unknown shield). The SHIELD_LIST variable
was reset for each BOARD_ROOT discovered.

Simplify discovery logic. Discover all shields and set relevant
variables (SHIELD_LIST and SHIELD_DIR_${name}) in one step and
process all the expected boards in the next step.

Signed-off-by: Marek Metelski <marek@metelski.dev>
This commit is contained in:
Marek Metelski 2024-04-10 12:27:02 +00:00 committed by Alberto Escolar
parent 2f1a254eae
commit 1c8ea0a941

View file

@ -60,7 +60,7 @@ foreach(root ${BOARD_ROOT})
# from each file and looking for <shield>.overlay files in there. # from each file and looking for <shield>.overlay files in there.
# Each overlay corresponds to a shield. We obtain the shield name by # Each overlay corresponds to a shield. We obtain the shield name by
# removing the .overlay extension. # removing the .overlay extension.
unset(SHIELD_LIST) # We also create a SHIELD_DIR_${name} variable for each shield's directory.
foreach(shields_refs ${shields_refs_list}) foreach(shields_refs ${shields_refs_list})
get_filename_component(shield_path ${shields_refs} DIRECTORY) get_filename_component(shield_path ${shields_refs} DIRECTORY)
file(GLOB shield_overlays RELATIVE ${shield_path} ${shield_path}/*.overlay) file(GLOB shield_overlays RELATIVE ${shield_path} ${shield_path}/*.overlay)
@ -70,7 +70,9 @@ foreach(root ${BOARD_ROOT})
set(SHIELD_DIR_${shield} ${shield_path}) set(SHIELD_DIR_${shield} ${shield_path})
endforeach() endforeach()
endforeach() endforeach()
endforeach()
# Process shields in-order
if(DEFINED SHIELD) if(DEFINED SHIELD)
foreach(s ${SHIELD_AS_LIST}) foreach(s ${SHIELD_AS_LIST})
if(NOT ${s} IN_LIST SHIELD_LIST) if(NOT ${s} IN_LIST SHIELD_LIST)
@ -79,25 +81,10 @@ foreach(root ${BOARD_ROOT})
list(REMOVE_ITEM SHIELD-NOTFOUND ${s}) list(REMOVE_ITEM SHIELD-NOTFOUND ${s})
# Add <shield>.overlay to a temporary variable
set(shield_${s}_dts_file ${SHIELD_DIR_${s}}/${s}.overlay)
# Search for shield/shield.conf file
if(EXISTS ${SHIELD_DIR_${s}}/${s}.conf)
# Add <shield>.conf to a temporary variable
set(shield_${s}_conf_file ${SHIELD_DIR_${s}}/${s}.conf)
endif()
endforeach()
endif()
endforeach()
# Process shields in-order
if(DEFINED SHIELD)
foreach(s ${SHIELD_AS_LIST})
# Add <shield>.overlay to the shield_dts_files output variable. # Add <shield>.overlay to the shield_dts_files output variable.
list(APPEND list(APPEND
shield_dts_files shield_dts_files
${shield_${s}_dts_file} ${SHIELD_DIR_${s}}/${s}.overlay
) )
# Add the shield's directory to the SHIELD_DIRS output variable. # Add the shield's directory to the SHIELD_DIRS output variable.
@ -106,10 +93,11 @@ if(DEFINED SHIELD)
${SHIELD_DIR_${s}} ${SHIELD_DIR_${s}}
) )
if(DEFINED shield_${s}_conf_file) # Search for shield/shield.conf file
if(EXISTS ${SHIELD_DIR_${s}}/${s}.conf)
list(APPEND list(APPEND
shield_conf_files shield_conf_files
${shield_${s}_conf_file} ${SHIELD_DIR_${s}}/${s}.conf
) )
endif() endif()