Skip to content

Commit

Permalink
cmake: add support for user-defined board aliases
Browse files Browse the repository at this point in the history
Zephyr board names must be globally unique which requires that they
encode all necessary information to identify a specific target.
Typing in these names can be inconvenient to developers working on
multiple targets within a single workspace.

Extend the cmake infrastructure to read an optional board aliases file
that will map custom aliases to the corresponding canonical Zephyr
board name.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
  • Loading branch information
pabigot committed Apr 7, 2020
1 parent cf2131d commit 75e6e23
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmake/app/boilerplate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ endif()
assert(BOARD "BOARD not set")
message(STATUS "Board: ${BOARD}")

if(DEFINED ENV{ZEPHYR_BOARD_ALIASES})
include($ENV{ZEPHYR_BOARD_ALIASES})
if(${BOARD}_BOARD_ALIAS)
set(BOARD_ALIAS ${BOARD} CACHE STRING "Board alias, provided by user")
set(BOARD ${${BOARD}_BOARD_ALIAS})
message(STATUS "Aliased BOARD=${BOARD_ALIAS} changed to ${BOARD}")
endif()
endif()
include(${ZEPHYR_BASE}/boards/deprecated.cmake)
if(${BOARD}_DEPRECATED)
set(BOARD_DEPRECATED ${BOARD} CACHE STRING "Deprecated board name, provided by user")
Expand Down
20 changes: 20 additions & 0 deletions doc/guides/beyond-GSG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ Export Zephyr CMake package
The :ref:`cmake_pkg` can be exported to CMake's user package registry if it has
not already been done as part of :ref:`getting_started`.

Board Aliases
*************

Developers who work with multiple boards may find explicit board names
cumbersome and want to use aliases for common targets. This is
supported by a CMake file with content like this:

.. code-block:: cmake
# Variable foo_BOARD_ALIAS=bar replaces BOARD=foo with BOARD=bar and
# sets BOARD_ALIAS=foo in the CMake cache.
set(pca10028_BOARD_ALIAS nrf51dk_nrf51422)
set(pca10056_BOARD_ALIAS nrf52840dk_nrf52840)
set(k64f_BOARD_ALIAS frdm_k64f)
set(sltb004a_BOARD_ALIAS efr32mg_sltb004a)
and specifying its location in :envvar:`ZEPHYR_BOARD_ALIASES`. This
enables use of aliases ``pca10028`` in contexts like
``cmake -DBOARD=pca10028`` and ``west -b pca10028``.

Build and Run an Application
****************************

Expand Down

0 comments on commit 75e6e23

Please sign in to comment.