Skip to content

Commit 6055c25

Browse files
tejlmandnashif
authored andcommitted
shield: cmake: using Kconfig.shield instead of looking for overlay files
Fixes: #26522 Now searching for Kconfig.shield instead of recursively looking for overlay files. Globbing recursively for overlay files also picks up board overlays, which leads to errors in the shield handling, as user could wrongly specify certain boards as shields. Also it led to wrongly list some board as shields, as reported in #26522. The folder containing a Kconfig.shield is then used when looking up overlay files, as all overlay files in that folder represents a shield. Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent cb1a629 commit 6055c25

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

cmake/app/boilerplate.cmake

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -306,61 +306,60 @@ set(SHIELD-NOTFOUND ${SHIELD_AS_LIST})
306306
# When found, use that path to infer the ARCH we are building for.
307307
foreach(root ${BOARD_ROOT})
308308
set(shield_dir ${root}/boards/shields)
309-
# Match the .overlay files in the shield directories to make sure we are
310-
# finding shields, e.g. x_nucleo_iks01a1/x_nucleo_iks01a1.overlay
311-
file(GLOB_RECURSE shields_refs_list
312-
RELATIVE ${shield_dir}
313-
${shield_dir}/*/*.overlay
314-
)
309+
# Match the Kconfig.shield files in the shield directories to make sure we are
310+
# finding shields, e.g. x_nucleo_iks01a1/Kconfig.shield
311+
file(GLOB_RECURSE shields_refs_list ${shield_dir}/*/Kconfig.shield)
315312

316313
# The above gives a list like
317-
# x_nucleo_iks01a1/x_nucleo_iks01a1.overlay;x_nucleo_iks01a2/x_nucleo_iks01a2.overlay
318-
# we construct a list of shield names by extracting file name and
319-
# removing the extension.
314+
# x_nucleo_iks01a1/Kconfig.shield;x_nucleo_iks01a2/Kconfig.shield
315+
# we construct a list of shield names by extracting the folder and find
316+
# and overlay files in there. Each overlay corresponds to a shield.
317+
# We obtain the shield name by removing the overlay extension.
320318
unset(SHIELD_LIST)
321-
foreach(shield_path ${shields_refs_list})
322-
get_filename_component(shield ${shield_path} NAME_WE)
323-
list(APPEND SHIELD_LIST ${shield})
319+
foreach(shields_refs ${shields_refs_list})
320+
get_filename_component(shield_path ${shields_refs} DIRECTORY)
321+
file(GLOB shield_overlays RELATIVE ${shield_path} ${shield_path}/*.overlay)
322+
foreach(overlay ${shield_overlays})
323+
get_filename_component(shield ${overlay} NAME_WE)
324+
list(APPEND SHIELD_LIST ${shield})
325+
set(SHIELD_DIR_${shield} ${shield_path})
326+
endforeach()
324327
endforeach()
325328

326329
if(DEFINED SHIELD)
327330
foreach(s ${SHIELD_AS_LIST})
328-
list(FIND SHIELD_LIST ${s} _idx)
329-
if (_idx EQUAL -1)
331+
if(NOT ${s} IN_LIST SHIELD_LIST)
330332
continue()
331333
endif()
332334

333335
list(REMOVE_ITEM SHIELD-NOTFOUND ${s})
334336

335-
list(GET shields_refs_list ${_idx} s_path)
336-
get_filename_component(s_dir ${s_path} DIRECTORY)
337-
338337
# if shield config flag is on, add shield overlay to the shield overlays
339338
# list and dts_fixup file to the shield fixup file
340339
list(APPEND
341340
shield_dts_files
342-
${shield_dir}/${s_path}
341+
${SHIELD_DIR_${s}}/${s}.overlay
343342
)
344343

345344
list(APPEND
346345
shield_dts_fixups
347-
${shield_dir}/${s_dir}/dts_fixup.h
346+
${SHIELD_DIR_${s}}/dts_fixup.h
348347
)
349348

350349
# search for shield/shield.conf file
351350
if(EXISTS ${shield_dir}/${s_dir}/${s}.conf)
352351
# add shield.conf to the shield config list
353352
list(APPEND
354353
shield_conf_files
355-
${shield_dir}/${s_dir}/${s}.conf
354+
${SHIELD_DIR_${s}}/${s}.conf
356355
)
357356
endif()
358357

359-
zephyr_file(CONF_FILES ${shield_dir}/${s_dir}/boards
358+
zephyr_file(CONF_FILES ${SHIELD_DIR_${s}}/boards
360359
DTS shield_dts_files
361360
KCONF shield_conf_files
362361
)
363-
zephyr_file(CONF_FILES ${shield_dir}/${s_dir}/boards/${s}
362+
zephyr_file(CONF_FILES ${SHIELD_DIR_${s}}/boards/${s}
364363
DTS shield_dts_files
365364
KCONF shield_conf_files
366365
)

0 commit comments

Comments
 (0)