Skip to content

cmake: zephyr_module.cmake included before ZEPHYR_EXTRA_MODULES is evaluated #30673

@cfriedt

Description

@cfriedt

Describe the bug
I was having some usual difficulty trying to build a module using the approach mentioned here:
https://docs.zephyrproject.org/latest/guides/modules.html

Dug into it a bit more and found that ZEPHYR_EXTRA_MODULES was empty inside of cmake/zephyr_module.cmake.

This was without initialising using west init previously (which was working fine in the CI for my external module), but if I was just building using local directories it failed (presumably because the .west/config file did not include the module in question).

To Reproduce

  1. define an external module as described here
  2. Set some environment variables
WS=${HOME}/workspace
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=${HOME}/zephyr-sdk-0.11.4
export ZEPHYR_BASE=${WS}/zephyrproject/zephyr
export PATH=${ZEPHYR_BASE}/scripts:${PATH}
ZEM=${WS}/zephyr-example-module
export ZEPHYR_EXTRA_MODULES=${ZEM}
  1. Build a sample application
cd ${ZEPHYR_BASE}
west build -p always -b native_posix_64 -t run ${ZEM}/tests/zephyr_example_module
  1. See error

Expected behavior
Module build without issue

Impact
Showstopper (for local builds that hope to avoid checking out zephyr sources again and again)

Logs and console output
Looks like the ordering of cmake files is a bit weird. I just inserted the line below into the main two files under cmake/ that mentioned ZEPHYR_EXTRA_MODULES and the output is this:

message(STATUS "${CMAKE_CURRENT_LIST_FILE}: ZEPHYR_EXTRA_MODULES: ${ZEPHYR_EXTRA_MODULES}")
-- west build: making build dir /home/cfriedt/workspace/zephyrproject/zephyr/build pristine
-- west build: generating a build system
Including boilerplate (Zephyr base): /home/cfriedt/workspace/zephyrproject/zephyr/cmake/app/boilerplate.cmake
-- Application: /home/cfriedt/workspace/zephyr-example-module/tests/zephyr_example_module
-- Zephyr version: 2.4.99 (/home/cfriedt/workspace/zephyrproject/zephyr)
-- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.5") found components: Interpreter 
-- Found west (found suitable version "0.8.0", minimum required is "0.7.1")
-- /home/cfriedt/workspace/zephyrproject/zephyr/cmake/zephyr_module.cmake: ZEPHYR_EXTRA_MODULES: 
-- Board: native_posix_64
-- /home/cfriedt/workspace/zephyrproject/zephyr/cmake/app/boilerplate.cmake: ZEPHYR_EXTRA_MODULES: /home/cfriedt/workspace/zephyr-example-module

So it appears that ZEPHYR_EXTRA_MODULES is evaluated too early inside of cmake/zephyr_module.cmake before the environment variable has even been checked.
cmake/app/boilerplate.cmake is where the variable is read from the environment.

cmake/app/boilerplate.cmake includes cmake/zephyr_module.cmake at line 168 but does not actually check the environment until line 549.

Environment (please complete the following information):

  • OS: Ubuntu Focal
  • Toolchain: Zephyr SDK 0.11.4
  • Commit: b517b1f

Additional context
Just trying to build an external module as described in the documentation, so it should Just Work™.

A trivial fix worked for me and I'll submit a PR.

Metadata

Metadata

Assignees

Labels

bugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions