Skip to content

Commit e253c1b

Browse files
committed
cmake: shields: skip validing SHIELD if its not defined
When SHIELD is not set, no shield are applied but list_shields.py still runs which takes around 140ms. Then additional 100ms are spent on string operations in CMake. This reduces the build configuration time by ~250ms on my machine. Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
1 parent b439029 commit e253c1b

File tree

1 file changed

+41
-42
lines changed

1 file changed

+41
-42
lines changed

‎cmake/modules/shields.cmake‎

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ include(python)
3636
# Check that SHIELD has not changed.
3737
zephyr_check_cache(SHIELD WATCH)
3838

39-
if(SHIELD)
40-
message(STATUS "Shield(s): ${SHIELD}")
39+
if(NOT DEFINED SHIELD)
40+
# No shields required for the build, skip unnecessary work
41+
return()
4142
endif()
4243

43-
if(DEFINED SHIELD)
44-
string(REPLACE " " ";" SHIELD_AS_LIST "${SHIELD}")
45-
endif()
44+
message(STATUS "Shield(s): ${SHIELD}")
45+
46+
string(REPLACE " " ";" SHIELD_AS_LIST "${SHIELD}")
4647
# SHIELD-NOTFOUND is a real CMake list, from which valid shields can be popped.
4748
# After processing all shields, only invalid shields will be left in this list.
4849
set(SHIELD-NOTFOUND ${SHIELD_AS_LIST})
@@ -85,56 +86,54 @@ if(shields_length GREATER 0)
8586
endif()
8687

8788
# Process shields in-order
88-
if(DEFINED SHIELD)
89-
foreach(s ${SHIELD_AS_LIST})
90-
if(NOT ${s} IN_LIST SHIELD_LIST)
91-
continue()
92-
endif()
89+
foreach(s ${SHIELD_AS_LIST})
90+
if(NOT ${s} IN_LIST SHIELD_LIST)
91+
continue()
92+
endif()
9393

94-
list(REMOVE_ITEM SHIELD-NOTFOUND ${s})
94+
list(REMOVE_ITEM SHIELD-NOTFOUND ${s})
9595

96-
# Add <shield>.overlay to the shield_dts_files output variable.
97-
list(APPEND
98-
shield_dts_files
99-
${SHIELD_DIR_${s}}/${s}.overlay
100-
)
96+
# Add <shield>.overlay to the shield_dts_files output variable.
97+
list(APPEND
98+
shield_dts_files
99+
${SHIELD_DIR_${s}}/${s}.overlay
100+
)
101+
102+
# Add the shield's directory to the SHIELD_DIRS output variable.
103+
list(APPEND
104+
SHIELD_DIRS
105+
${SHIELD_DIR_${s}}
106+
)
101107

102-
# Add the shield's directory to the SHIELD_DIRS output variable.
108+
include(${SHIELD_DIR_${s}}/pre_dt_shield.cmake OPTIONAL)
109+
110+
# Search for shield/shield.conf file
111+
if(EXISTS ${SHIELD_DIR_${s}}/${s}.conf)
103112
list(APPEND
104-
SHIELD_DIRS
105-
${SHIELD_DIR_${s}}
113+
shield_conf_files
114+
${SHIELD_DIR_${s}}/${s}.conf
106115
)
116+
endif()
107117

108-
include(${SHIELD_DIR_${s}}/pre_dt_shield.cmake OPTIONAL)
109-
110-
# Search for shield/shield.conf file
111-
if(EXISTS ${SHIELD_DIR_${s}}/${s}.conf)
112-
list(APPEND
113-
shield_conf_files
114-
${SHIELD_DIR_${s}}/${s}.conf
115-
)
116-
endif()
117-
118-
# Add board-specific .conf and .overlay files to their
119-
# respective output variables.
120-
zephyr_file(CONF_FILES ${SHIELD_DIR_${s}}/boards
121-
DTS shield_dts_files
122-
KCONF shield_conf_files
123-
)
124-
zephyr_file(CONF_FILES ${SHIELD_DIR_${s}}/boards/${s}
125-
DTS shield_dts_files
126-
KCONF shield_conf_files
127-
)
128-
endforeach()
129-
endif()
118+
# Add board-specific .conf and .overlay files to their
119+
# respective output variables.
120+
zephyr_file(CONF_FILES ${SHIELD_DIR_${s}}/boards
121+
DTS shield_dts_files
122+
KCONF shield_conf_files
123+
)
124+
zephyr_file(CONF_FILES ${SHIELD_DIR_${s}}/boards/${s}
125+
DTS shield_dts_files
126+
KCONF shield_conf_files
127+
)
128+
endforeach()
130129

131130
# Prepare shield usage command printing.
132131
# This command prints all shields in the system in the following cases:
133132
# - User specifies an invalid SHIELD
134133
# - User invokes '<build-command> shields' target
135134
list(SORT SHIELD_LIST)
136135

137-
if(DEFINED SHIELD AND NOT (SHIELD-NOTFOUND STREQUAL ""))
136+
if(NOT (SHIELD-NOTFOUND STREQUAL ""))
138137
# Convert the list to pure string with newlines for printing.
139138
string(REPLACE ";" "\n" shield_string "${SHIELD_LIST}")
140139

0 commit comments

Comments
 (0)