2021-12-16 13:55:09 +01:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
#
|
|
|
|
# Copyright (c) 2021, Nordic Semiconductor ASA
|
|
|
|
|
|
|
|
# Validate shields and setup shields target.
|
|
|
|
#
|
|
|
|
# This module will validate the SHIELD argument.
|
|
|
|
#
|
2023-01-07 23:47:42 +01:00
|
|
|
# If a shield implementation is not found for one of the specified shields, an
|
|
|
|
# error will be raised and a list of valid shields will be printed.
|
2021-12-16 13:55:09 +01:00
|
|
|
#
|
|
|
|
# Outcome:
|
|
|
|
# The following variables will be defined when this module completes:
|
2023-01-07 23:47:42 +01:00
|
|
|
# - shield_conf_files: List of shield-specific Kconfig fragments
|
|
|
|
# - shield_dts_files : List of shield-specific devicetree files
|
|
|
|
# - SHIELD_AS_LIST : A CMake list of shields created from the SHIELD variable.
|
2022-12-15 21:12:48 +01:00
|
|
|
# - SHIELD_DIRS : A CMake list of directories which contain shield definitions
|
2021-12-16 13:55:09 +01:00
|
|
|
#
|
2023-01-07 23:47:42 +01:00
|
|
|
# The following targets will be defined when this CMake module completes:
|
|
|
|
# - shields: when invoked, a list of valid shields will be printed
|
|
|
|
#
|
|
|
|
# If the SHIELD variable is changed after this module completes,
|
|
|
|
# a warning will be printed.
|
|
|
|
#
|
2021-12-16 13:55:09 +01:00
|
|
|
# Optional variables:
|
|
|
|
# - BOARD_ROOT: CMake list of board roots containing board implementations
|
|
|
|
#
|
2023-01-07 23:47:42 +01:00
|
|
|
# Variables set by this module and not mentioned above are for internal
|
|
|
|
# use only, and may be removed, renamed, or re-purposed without prior notice.
|
2021-12-16 13:55:09 +01:00
|
|
|
|
2021-12-16 17:13:54 +01:00
|
|
|
include_guard(GLOBAL)
|
|
|
|
|
|
|
|
include(extensions)
|
|
|
|
|
2021-12-16 13:55:09 +01:00
|
|
|
# Check that SHIELD has not changed.
|
|
|
|
zephyr_check_cache(SHIELD WATCH)
|
|
|
|
|
|
|
|
if(SHIELD)
|
|
|
|
message(STATUS "Shield(s): ${SHIELD}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(DEFINED SHIELD)
|
|
|
|
string(REPLACE " " ";" SHIELD_AS_LIST "${SHIELD}")
|
|
|
|
endif()
|
|
|
|
# SHIELD-NOTFOUND is a real CMake list, from which valid shields can be popped.
|
|
|
|
# After processing all shields, only invalid shields will be left in this list.
|
|
|
|
set(SHIELD-NOTFOUND ${SHIELD_AS_LIST})
|
|
|
|
|
|
|
|
foreach(root ${BOARD_ROOT})
|
|
|
|
set(shield_dir ${root}/boards/shields)
|
|
|
|
# Match the Kconfig.shield files in the shield directories to make sure we are
|
|
|
|
# finding shields, e.g. x_nucleo_iks01a1/Kconfig.shield
|
|
|
|
file(GLOB_RECURSE shields_refs_list ${shield_dir}/*/Kconfig.shield)
|
|
|
|
|
2022-12-15 21:12:48 +01:00
|
|
|
# The above gives a list of Kconfig.shield files, like this:
|
|
|
|
#
|
2021-12-16 13:55:09 +01:00
|
|
|
# x_nucleo_iks01a1/Kconfig.shield;x_nucleo_iks01a2/Kconfig.shield
|
2022-12-15 21:12:48 +01:00
|
|
|
#
|
|
|
|
# we construct a list of shield names by extracting the directories
|
|
|
|
# from each file and looking for <shield>.overlay files in there.
|
|
|
|
# Each overlay corresponds to a shield. We obtain the shield name by
|
|
|
|
# removing the .overlay extension.
|
2024-04-10 14:27:02 +02:00
|
|
|
# We also create a SHIELD_DIR_${name} variable for each shield's directory.
|
2021-12-16 13:55:09 +01:00
|
|
|
foreach(shields_refs ${shields_refs_list})
|
|
|
|
get_filename_component(shield_path ${shields_refs} DIRECTORY)
|
|
|
|
file(GLOB shield_overlays RELATIVE ${shield_path} ${shield_path}/*.overlay)
|
|
|
|
foreach(overlay ${shield_overlays})
|
|
|
|
get_filename_component(shield ${overlay} NAME_WE)
|
|
|
|
list(APPEND SHIELD_LIST ${shield})
|
|
|
|
set(SHIELD_DIR_${shield} ${shield_path})
|
|
|
|
endforeach()
|
boards/shields: re-work handling in cmake and west
Remove the boards and shields lists from the 'usage' target output.
That might have been readable at some point long ago in Zephyr's
history, when only a few boards were available, but right now it's
obscuring the high level targets we really want 'usage' to print.
Instead, add 'boards' and 'shields' targets which the user can run to
get those lists, and reference them from the 'usage' output. This
makes 'usage' squintable again. We use the new list_boards.py script
from the 'boards' target.
Reference the 'help' target from 'usage' as well, and drop the
recommendation that people run '--target help' from the 'west build
--help' output for the 'west build --target' option. The canonical
place to look is 'usage' now.
Use the new list_boards.py code from 'west boards' as well, which
allows us to add the board's directory as a format string key, in
addition to its name and architecture.
Keep west-completion.bash up to date. While doing that, I noticed that
a bunch of references to this file refer to a stale location, so fix
those too.
Finally, the 'usage' output is what we print for a failed board or
shield lookup, so that needs to be updated also. Handle that by
invoking boards.cmake and a new shields.cmake in CMake script mode to
print the relevant output.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-12-10 00:53:00 +01:00
|
|
|
endforeach()
|
2021-12-16 13:55:09 +01:00
|
|
|
endforeach()
|
|
|
|
|
2024-01-05 10:28:52 +01:00
|
|
|
# Process shields in-order
|
|
|
|
if(DEFINED SHIELD)
|
|
|
|
foreach(s ${SHIELD_AS_LIST})
|
2024-04-10 14:27:02 +02:00
|
|
|
if(NOT ${s} IN_LIST SHIELD_LIST)
|
|
|
|
continue()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(REMOVE_ITEM SHIELD-NOTFOUND ${s})
|
|
|
|
|
2024-01-05 10:28:52 +01:00
|
|
|
# Add <shield>.overlay to the shield_dts_files output variable.
|
|
|
|
list(APPEND
|
|
|
|
shield_dts_files
|
2024-04-10 14:27:02 +02:00
|
|
|
${SHIELD_DIR_${s}}/${s}.overlay
|
2024-01-05 10:28:52 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Add the shield's directory to the SHIELD_DIRS output variable.
|
|
|
|
list(APPEND
|
|
|
|
SHIELD_DIRS
|
|
|
|
${SHIELD_DIR_${s}}
|
|
|
|
)
|
|
|
|
|
2024-04-10 14:27:02 +02:00
|
|
|
# Search for shield/shield.conf file
|
|
|
|
if(EXISTS ${SHIELD_DIR_${s}}/${s}.conf)
|
2024-01-05 10:28:52 +01:00
|
|
|
list(APPEND
|
|
|
|
shield_conf_files
|
2024-04-10 14:27:02 +02:00
|
|
|
${SHIELD_DIR_${s}}/${s}.conf
|
2024-01-05 10:28:52 +01:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Add board-specific .conf and .overlay files to their
|
|
|
|
# respective output variables.
|
|
|
|
zephyr_file(CONF_FILES ${SHIELD_DIR_${s}}/boards
|
|
|
|
DTS shield_dts_files
|
|
|
|
KCONF shield_conf_files
|
|
|
|
)
|
|
|
|
zephyr_file(CONF_FILES ${SHIELD_DIR_${s}}/boards/${s}
|
|
|
|
DTS shield_dts_files
|
|
|
|
KCONF shield_conf_files
|
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
2021-12-16 13:55:09 +01:00
|
|
|
# Prepare shield usage command printing.
|
2022-03-16 22:07:43 +01:00
|
|
|
# This command prints all shields in the system in the following cases:
|
2021-12-16 13:55:09 +01:00
|
|
|
# - User specifies an invalid SHIELD
|
|
|
|
# - User invokes '<build-command> shields' target
|
|
|
|
list(SORT SHIELD_LIST)
|
|
|
|
|
|
|
|
if(DEFINED SHIELD AND NOT (SHIELD-NOTFOUND STREQUAL ""))
|
|
|
|
# Convert the list to pure string with newlines for printing.
|
|
|
|
string(REPLACE ";" "\n" shield_string "${SHIELD_LIST}")
|
|
|
|
|
|
|
|
foreach (s ${SHIELD-NOTFOUND})
|
|
|
|
message("No shield named '${s}' found")
|
boards/shields: re-work handling in cmake and west
Remove the boards and shields lists from the 'usage' target output.
That might have been readable at some point long ago in Zephyr's
history, when only a few boards were available, but right now it's
obscuring the high level targets we really want 'usage' to print.
Instead, add 'boards' and 'shields' targets which the user can run to
get those lists, and reference them from the 'usage' output. This
makes 'usage' squintable again. We use the new list_boards.py script
from the 'boards' target.
Reference the 'help' target from 'usage' as well, and drop the
recommendation that people run '--target help' from the 'west build
--help' output for the 'west build --target' option. The canonical
place to look is 'usage' now.
Use the new list_boards.py code from 'west boards' as well, which
allows us to add the board's directory as a format string key, in
addition to its name and architecture.
Keep west-completion.bash up to date. While doing that, I noticed that
a bunch of references to this file refer to a stale location, so fix
those too.
Finally, the 'usage' output is what we print for a failed board or
shield lookup, so that needs to be updated also. Handle that by
invoking boards.cmake and a new shields.cmake in CMake script mode to
print the relevant output.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-12-10 00:53:00 +01:00
|
|
|
endforeach()
|
2021-12-16 13:55:09 +01:00
|
|
|
message("Please choose from among the following shields:\n"
|
|
|
|
"${shield_string}"
|
|
|
|
)
|
|
|
|
unset(CACHED_SHIELD CACHE)
|
|
|
|
message(FATAL_ERROR "Invalid SHIELD; see above.")
|
boards/shields: re-work handling in cmake and west
Remove the boards and shields lists from the 'usage' target output.
That might have been readable at some point long ago in Zephyr's
history, when only a few boards were available, but right now it's
obscuring the high level targets we really want 'usage' to print.
Instead, add 'boards' and 'shields' targets which the user can run to
get those lists, and reference them from the 'usage' output. This
makes 'usage' squintable again. We use the new list_boards.py script
from the 'boards' target.
Reference the 'help' target from 'usage' as well, and drop the
recommendation that people run '--target help' from the 'west build
--help' output for the 'west build --target' option. The canonical
place to look is 'usage' now.
Use the new list_boards.py code from 'west boards' as well, which
allows us to add the board's directory as a format string key, in
addition to its name and architecture.
Keep west-completion.bash up to date. While doing that, I noticed that
a bunch of references to this file refer to a stale location, so fix
those too.
Finally, the 'usage' output is what we print for a failed board or
shield lookup, so that needs to be updated also. Handle that by
invoking boards.cmake and a new shields.cmake in CMake script mode to
print the relevant output.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-12-10 00:53:00 +01:00
|
|
|
endif()
|
2021-12-16 13:55:09 +01:00
|
|
|
|
|
|
|
# Prepend each shield with COMMAND <cmake> -E echo <shield>" for printing.
|
|
|
|
# Each shield is printed as new command because build files are not fond of newlines.
|
|
|
|
list(TRANSFORM SHIELD_LIST PREPEND "COMMAND;${CMAKE_COMMAND};-E;echo;"
|
|
|
|
OUTPUT_VARIABLE shields_target_cmd
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(shields ${shields_target_cmd} USES_TERMINAL)
|