Skip to content

Commit

Permalink
cmake: extensions: add dt_alias()
Browse files Browse the repository at this point in the history
This is a helper function for looking up the path to a devicetree
alias. It is analogous to dt_chosen(). It has to exist as a separate
function from dt_prop() for similar reasons that dt_chosen() does:
the edtlib APIs for interacting with /aliases are special-cased in the
same way they are for /chosen.

Signed-off-by: Martí Bolívar <[email protected]>
  • Loading branch information
mbolivar-nordic authored and cfriedt committed Dec 6, 2021
1 parent e05810d commit a9f5578
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions cmake/extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,49 @@ function(dt_nodelabel var)
set(${var} ${${var}} PARENT_SCOPE)
endfunction()

# Usage:
# dt_alias(<var> PROPERTY <prop>)
#
# Get a node path for an /aliases node property.
#
# Example usage:
#
# # The full path to the 'led0' alias is returned in 'path'.
# dt_alias(path PROPERTY "led0")
#
# # The variable 'path' will be left undefined for a nonexistent
# # alias "does-not-exist".
# dt_alias(path PROPERTY "does-not-exist")
#
# The node's path will be returned in the <var> parameter. The
# variable will be left undefined if the alias does not exist.
#
# <var> : Return variable where the node path will be stored
# PROPERTY <prop> : The alias to check
function(dt_alias var)
set(req_single_args "PROPERTY")
cmake_parse_arguments(DT_ALIAS "" "${req_single_args}" "" ${ARGN})

if(${ARGV0} IN_LIST req_single_args)
message(FATAL_ERROR "dt_alias(${ARGV0} ...) missing return parameter.")
endif()

foreach(arg ${req_single_args})
if(NOT DEFINED DT_ALIAS_${arg})
message(FATAL_ERROR "dt_alias(${ARGV0} ...) "
"missing required argument: ${arg}"
)
endif()
endforeach()

get_target_property(${var} devicetree_target "DT_ALIAS|${DT_ALIAS_PROPERTY}")
if(${${var}} STREQUAL ${var}-NOTFOUND)
set(${var})
endif()

set(${var} ${${var}} PARENT_SCOPE)
endfunction()

# Usage:
# dt_node_exists(<var> PATH <path>)
#
Expand Down

0 comments on commit a9f5578

Please sign in to comment.