Skip to content

cmake: FindBabbleSim: Ensure BSIM variables are available everywhere#104598

Open
aescolar wants to merge 1 commit intozephyrproject-rtos:mainfrom
aescolar:FindBabbleSim
Open

cmake: FindBabbleSim: Ensure BSIM variables are available everywhere#104598
aescolar wants to merge 1 commit intozephyrproject-rtos:mainfrom
aescolar:FindBabbleSim

Conversation

@aescolar
Copy link
Member

@aescolar aescolar commented Feb 26, 2026

Ensure the two BSIM variables BSIM_OUT_PATH and BSIM_COMPONENTS_PATH are available everywhere also as a cmake variable as quite a few apps use them. (Some apps try to get them as an environment var, some as a cmake var).

When the user had them set in the environment, and the BabbleSim module uses zephyr_get() to try to find them, this also sets them globally. But otherwise, if we just deduced them in this module, we were only setting them in the enviroment, so apps which expected them globally would not build properly.

As bonus, add a cache variable to mark the module as found, so if
find_package(BabbleSim) is called again, we just skip it.

nordicjm
nordicjm previously approved these changes Feb 26, 2026
@aescolar aescolar marked this pull request as ready for review February 26, 2026 13:39
Comment on lines 67 to 68
set(BSIM_COMPONENTS_PATH ${BSIM_COMPONENTS_PATH} CACHE PATH "BabbleSim components folder")
set(BSIM_OUT_PATH ${BSIM_OUT_PATH} CACHE PATH "BabbleSim build output folder")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the zephyr_get() here:

zephyr_get(BSIM_COMPONENTS_PATH)
zephyr_get(BSIM_OUT_PATH)

will set those variables in local scope, meaning all code executed as part of find_package(Zephyr) will have those variable available as both env vars and normal CMake variables even if this code is not added.

Only code invoked in a CMake external project, or after find_package(Zephyr) may not have them available (depending on how they were set initially)

#
# If BabbleSim cannot be found we error right away with a message trying to guide users

if (DEFINED CACHE{BabbleSim_FOUND})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (DEFINED CACHE{BabbleSim_FOUND})
if(DEFINED CACHE{BabbleSim_FOUND})
Ensure the two BSIM variables BSIM_OUT_PATH and BSIM_COMPONENTS_PATH are
available everywhere also as a cmake variable as quite a few apps use
them. (Some apps try to get them as an environment var, some as a cmake
var).

When the user had them set in the environment, and the BabbleSim module
uses zephyr_get() to try to find them, this also sets them globally.
But otherwise, if we just deduced them in this module, we were only
setting them in the enviroment, so apps which expected them globally
would not build properly.

As bonus, add a cache variable to mark the module as found, so if
find_package(BabbleSim) is called again, we just skip it.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
@nordicjm nordicjm requested a review from tejlmand February 26, 2026 15:22
@sonarqubecloud
Copy link

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants