Skip to content

Commit

Permalink
nrf52_bsim: Find simulator thru west as fallback
Browse files Browse the repository at this point in the history
For developers ease, let's try to find the simulator
thru west if the environment variables that tell where
the simulator is are not set.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
  • Loading branch information
aescolar authored and carlescufi committed Apr 28, 2023
1 parent 14406cc commit 6758156
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 16 deletions.
21 changes: 5 additions & 16 deletions boards/posix/nrf52_bsim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
# SPDX-License-Identifier: Apache-2.0

if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH})
message(FATAL_ERROR "This board requires the BabbleSim simulator. Please set\
the environment variable BSIM_COMPONENTS_PATH to point to its components \
folder. More information can be found in\
https://babblesim.github.io/folder_structure_and_env.html")
endif()
if (NOT DEFINED ENV{BSIM_OUT_PATH})
message(FATAL_ERROR "This board requires the BabbleSim simulator. Please set\
the environment variable BSIM_OUT_PATH to point to the folder where the\
simulator is compiled to. More information can be found in\
https://babblesim.github.io/folder_structure_and_env.html")
endif()
find_package(BabbleSim)

zephyr_library()
zephyr_library_compile_definitions(NO_POSIX_CHEATS)
Expand All @@ -37,9 +26,9 @@ zephyr_include_directories(soc)
zephyr_include_directories(cmsis)

zephyr_library_include_directories(
$ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/
$ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/
$ENV{BSIM_COMPONENTS_PATH}/libRandv2/src/
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/
${BSIM_COMPONENTS_PATH}/libRandv2/src/
${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/posix/include
)
Expand All @@ -48,7 +37,7 @@ zephyr_ld_options(
-lm
)

set(libpath $ENV{BSIM_OUT_PATH}/lib)
set(libpath ${BSIM_OUT_PATH}/lib)
zephyr_library_import(bsim_libUtilv1 ${libpath}/libUtilv1.32.a)
zephyr_library_import(bsim_libPhyComv1 ${libpath}/libPhyComv1.32.a)
zephyr_library_import(bsim_lib2G4PhyComv1 ${libpath}/lib2G4PhyComv1.32.a)
Expand Down
62 changes: 62 additions & 0 deletions cmake/modules/FindBabbleSim.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright (c) 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

# FindBabbleSim module for locating BabbleSim
#
# The module defines the following variables:
#
# 'BSIM_COMPONENTS_PATH'
# Path to the BabbleSim components source folder
#
# 'BSIM_OUT_PATH'
# Path to the BabbleSim build output root path (under which libraries and binaries) are kept
#
# We first try to find it via the environment variables BSIM_OUT_PATH and BSIM_COMPONENTS_PATH.
# If these are not set, as a fallback we attempt to find it through west, in case the user
# fetched babblesim using the manifest.
# Note that what we find through the environment variables is meant to have precedence.
#
# If BabbleSim cannot be found we error right away with a message trying to guide users

zephyr_get(BSIM_COMPONENTS_PATH)
zephyr_get(BSIM_OUT_PATH)

if ((DEFINED WEST) AND (NOT DEFINED BSIM_COMPONENTS_PATH) AND (NOT DEFINED BSIM_OUT_PATH))
# Let's ask west for the bsim_project existence and its path
execute_process(COMMAND ${WEST}
status babblesim_base
OUTPUT_QUIET
ERROR_QUIET
RESULT_VARIABLE ret_val1)
execute_process(COMMAND ${WEST}
list babblesim_base -f {posixpath}
OUTPUT_VARIABLE BSIM_BASE_PATH
ERROR_QUIET
RESULT_VARIABLE ret_val2)
if (NOT (${ret_val1} OR ${ret_val2}))
string(STRIP ${BSIM_BASE_PATH} BSIM_COMPONENTS_PATH)
get_filename_component(BSIM_OUT_PATH ${BSIM_COMPONENTS_PATH}/.. ABSOLUTE)
endif()
endif()

message(STATUS "Using BSIM from BSIM_COMPONENTS_PATH=${BSIM_COMPONENTS_PATH}\
BSIM_OUT_PATH=${BSIM_OUT_PATH}")

if ((NOT DEFINED BSIM_COMPONENTS_PATH) OR (NOT DEFINED BSIM_OUT_PATH))
message(FATAL_ERROR "This board requires the BabbleSim simulator. Please either\n\
a) Enable the west babblesim group with\n\
west config manifest.group-filter +babblesim && west update\n\
and build it with\n\
cd ${ZEPHYR_BASE}/../tools/bsim\n\
make everything -j 8\n\
OR\n\
b) set the environment variable BSIM_COMPONENTS_PATH to point to your own bsim installation\n\
`components/` folder, *and* BSIM_OUT_PATH to point to the folder where the simulator\n\
is compiled to.\n\
More information can be found in https://babblesim.github.io/folder_structure_and_env.html"
)
endif()

#Many apps cmake files (in and out of tree) expect these environment variables. Lets provide them:
set(ENV{BSIM_COMPONENTS_PATH} ${BSIM_COMPONENTS_PATH})
set(ENV{BSIM_OUT_PATH} ${BSIM_OUT_PATH})

0 comments on commit 6758156

Please sign in to comment.