cmake: Fall back to ZEPHYR_BASE when the board is not in BOARD_ROOT
It is very inconvenient to maintain an application that both runs on a Zephyr board and an out-of-tree board. It forces one to write build scripts like this in the app: if(BOARD STREQUAL my_out_of_tree_board) set(BOARD_ROOT some/out/of/tree/board/path) endif() To avoid this we change the semantics of BOARD_ROOT. Instead of it being a path to the board root it is now a prioritized list of board root directories. Zephyr will append ZEPHYR_BASE to BOARD_ROOT. This ensures that Zephyr boards can be used when the out-of-tree board directory can not supply the requested board. Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
This commit is contained in:
parent
fd8022ae16
commit
d6de4c7a99
|
@ -2,7 +2,7 @@
|
|||
# error if it is missing
|
||||
|
||||
if(EXISTS ${BOARD_DIR}/CMakeLists.txt)
|
||||
if(BOARD_ROOT)
|
||||
if(USING_OUT_OF_TREE_BOARD)
|
||||
set(build_dir boards/${ARCH}/${BOARD})
|
||||
else()
|
||||
unset(build_dir)
|
||||
|
|
|
@ -189,12 +189,9 @@ message(STATUS "Selected BOARD ${BOARD}")
|
|||
# Store the selected board in the cache
|
||||
set(CACHED_BOARD ${BOARD} CACHE STRING "Selected board")
|
||||
|
||||
# Use BOARD to search zephyr/boards/** for a _defconfig file,
|
||||
# e.g. zephyr/boards/arm/96b_carbon_nrf51/96b_carbon_nrf51_defconfig. When
|
||||
# found, use that path to infer the ARCH we are building for.
|
||||
if(NOT BOARD_ROOT)
|
||||
set(BOARD_ROOT ${ZEPHYR_BASE})
|
||||
endif()
|
||||
# 'BOARD_ROOT' is a prioritized list of directories where boards may
|
||||
# be found. It always includes ${ZEPHYR_BASE} at the lowest priority.
|
||||
list(APPEND BOARD_ROOT ${ZEPHYR_BASE})
|
||||
|
||||
if(NOT SOC_ROOT)
|
||||
set(SOC_DIR ${ZEPHYR_BASE}/soc)
|
||||
|
@ -202,7 +199,21 @@ else()
|
|||
set(SOC_DIR ${SOC_ROOT}/soc)
|
||||
endif()
|
||||
|
||||
find_path(BOARD_DIR NAMES "${BOARD}_defconfig" PATHS ${BOARD_ROOT}/boards/*/* NO_DEFAULT_PATH)
|
||||
# Use BOARD to search for a '_defconfig' file.
|
||||
# e.g. zephyr/boards/arm/96b_carbon_nrf51/96b_carbon_nrf51_defconfig.
|
||||
# When found, use that path to infer the ARCH we are building for.
|
||||
foreach(root ${BOARD_ROOT})
|
||||
# NB: find_path will return immediately if the output variable is
|
||||
# already set
|
||||
find_path(BOARD_DIR
|
||||
NAMES ${BOARD}_defconfig
|
||||
PATHS ${root}/boards/*/*
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
if(BOARD_DIR AND NOT (${root} STREQUAL ${ZEPHYR_BASE}))
|
||||
set(USING_OUT_OF_TREE_BOARD 1)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
assert_with_usage(BOARD_DIR "No board named '${BOARD}' found")
|
||||
|
||||
|
|
|
@ -1091,10 +1091,11 @@ macro(assert_with_usage test comment)
|
|||
if(NOT ${test})
|
||||
message(${comment})
|
||||
message("see usage:")
|
||||
string(REPLACE ";" " " BOARD_ROOT_SPACE_SEPARATED "${BOARD_ROOT}")
|
||||
execute_process(
|
||||
COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
-DBOARD_ROOT=${BOARD_ROOT}
|
||||
-DBOARD_ROOT_SPACE_SEPARATED=${BOARD_ROOT_SPACE_SEPARATED}
|
||||
-P ${ZEPHYR_BASE}/cmake/usage/usage.cmake
|
||||
)
|
||||
message(FATAL_ERROR "Invalid usage")
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
string(REPLACE ";" " " BOARD_ROOT_SPACE_SEPARATED "${BOARD_ROOT}")
|
||||
|
||||
add_custom_target(
|
||||
usage
|
||||
${CMAKE_COMMAND}
|
||||
-DBOARD_ROOT=${BOARD_ROOT}
|
||||
-DBOARD_ROOT_SPACE_SEPARATED=${BOARD_ROOT_SPACE_SEPARATED}
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/usage.cmake
|
||||
)
|
||||
|
||||
|
|
|
@ -12,27 +12,29 @@ set(arch_list
|
|||
xtensa
|
||||
)
|
||||
|
||||
set(board_dir ${BOARD_ROOT}/boards)
|
||||
string(REPLACE " " ";" BOARD_ROOT "${BOARD_ROOT_SPACE_SEPARATED}")
|
||||
|
||||
foreach(arch ${arch_list})
|
||||
set(board_arch_dir ${board_dir}/${arch})
|
||||
foreach(root ${BOARD_ROOT})
|
||||
set(board_arch_dir ${root}/boards/${arch})
|
||||
|
||||
# Match the .yanl files in the board directories to make sure we are
|
||||
# finding boards, e.g. qemu_xtensa/qemu_xtensa.yaml
|
||||
file(GLOB_RECURSE yamls_for_${arch}
|
||||
RELATIVE ${board_arch_dir}
|
||||
${board_arch_dir}/*.yaml
|
||||
)
|
||||
# Match the .yanl files in the board directories to make sure we are
|
||||
# finding boards, e.g. qemu_xtensa/qemu_xtensa.yaml
|
||||
file(GLOB_RECURSE yamls_for_${arch}
|
||||
RELATIVE ${board_arch_dir}
|
||||
${board_arch_dir}/*.yaml
|
||||
)
|
||||
|
||||
# The above gives a list like
|
||||
# nrf51_blenano/nrf51_blenano_yaml;nrf51_pca10028/nrf51_pca10028_yaml
|
||||
# we construct a list of board names by removing both the .yaml
|
||||
# suffix and the path.
|
||||
set(boards_for_${arch} "")
|
||||
foreach(yaml_path ${yamls_for_${arch}})
|
||||
get_filename_component(board ${yaml_path} NAME_WE)
|
||||
# The above gives a list like
|
||||
# nrf51_blenano/nrf51_blenano_yaml;nrf51_pca10028/nrf51_pca10028_yaml
|
||||
# we construct a list of board names by removing both the .yaml
|
||||
# suffix and the path.
|
||||
set(boards_for_${arch} "")
|
||||
foreach(yaml_path ${yamls_for_${arch}})
|
||||
get_filename_component(board ${yaml_path} NAME_WE)
|
||||
|
||||
list(APPEND boards_for_${arch} ${board})
|
||||
list(APPEND boards_for_${arch} ${board})
|
||||
endforeach()
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ sample:
|
|||
tests:
|
||||
boards.out_of_tree:
|
||||
tags: out_of_tree
|
||||
platform_whitelist: nrf52840_pca10056
|
||||
platform_whitelist: nrf52840_pca10056 nrf52_pca10040
|
||||
harness: console
|
||||
harness_config:
|
||||
type: one_line
|
||||
|
|
Loading…
Reference in New Issue