cmake: deprecation of board names

This commit introduces boards/deprecated.cmake to allow deprecation
of existing boards, when a board is renamed.

This allows users to still specify the old board name, and let Zephyr
build system to select the new board name.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
diff --git a/CODEOWNERS b/CODEOWNERS
index 1ac415f..e94dbc5 100644
--- a/CODEOWNERS
+++ b/CODEOWNERS
@@ -99,6 +99,7 @@
 /boards/arm/stm32f3_disco/                @ydamigos
 /boards/arm/stm32*_eval/                  @erwango
 /boards/common/                           @mbolivar-nordic
+/boards/deprecated.cmake                  @tejlmand
 /boards/nios2/                            @wentongwu
 /boards/nios2/altera_max10/               @wentongwu
 /boards/arm/stm32_min_dev/                @cbsiddharth
diff --git a/boards/deprecated.cmake b/boards/deprecated.cmake
new file mode 100644
index 0000000..fe618b5
--- /dev/null
+++ b/boards/deprecated.cmake
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: Apache-2.0
+
+# This file contains boards in Zephyr which has been replaced with a new board
+# name.
+# This allows the system to automatically change the board while at the same
+# time prints a warning to the user, that the board name is deprecated.
+#
+# To add a board rename, add a line in following format:
+# set(<old_board_name>_DEPRECATED <new_board_name>)
+
+set(nrf51_pca10028_DEPRECATED nrf51dk_nrf51422)
diff --git a/cmake/app/boilerplate.cmake b/cmake/app/boilerplate.cmake
index 51b521e..7cc79d4 100644
--- a/cmake/app/boilerplate.cmake
+++ b/cmake/app/boilerplate.cmake
@@ -158,7 +158,7 @@
   # Warn the user if it looks like he is trying to change the board
   # without cleaning first
   if(board_cli_argument)
-    if(NOT (CACHED_BOARD STREQUAL board_cli_argument))
+    if(NOT ((CACHED_BOARD STREQUAL board_cli_argument) OR (BOARD_DEPRECATED STREQUAL board_cli_argument)))
       message(WARNING "The build directory must be cleaned pristinely when changing boards")
       # TODO: Support changing boards without requiring a clean build
     endif()
@@ -181,6 +181,13 @@
 assert(BOARD "BOARD not set")
 message(STATUS "Board: ${BOARD}")
 
+include(${ZEPHYR_BASE}/boards/deprecated.cmake)
+if(${BOARD}_DEPRECATED)
+  set(BOARD_DEPRECATED ${BOARD} CACHE STRING "Deprecated board name, provided by user")
+  set(BOARD ${${BOARD}_DEPRECATED})
+  message(WARNING "Deprecated BOARD=${BOARD_DEPRECATED} name specified, board automatically changed to: ${BOARD}.")
+endif()
+
 # Store the selected board in the cache
 set(CACHED_BOARD ${BOARD} CACHE STRING "Selected board")