Skip to content

Commit 84e809d

Browse files
author
Gregory Shue
committed
build: Overlay build vars expand ${ZEPHYR_<module>_MODULE_DIR}
Support referencing module directories by name in CONF_FILE, OVERLAY_CONFIG, and DTC_OVERLAY_FILE so that projects can reference overlay files in arbitrary modules. Fixes #41830 Signed-off-by: Gregory Shue <[email protected]>
1 parent 4446272 commit 84e809d

File tree

15 files changed

+84
-6
lines changed

15 files changed

+84
-6
lines changed

cmake/app/boilerplate.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ if(DEFINED CONF_FILE)
444444

445445
# In order to support a `prj_<name>.conf pattern for auto inclusion of board
446446
# overlays, then we must first ensure only a single conf file is provided.
447-
string(REPLACE " " ";" CONF_FILE_AS_LIST "${CONF_FILE}")
447+
string(CONFIGURE "${CONF_FILE}" CONF_FILE_EXPANDED)
448+
string(REPLACE " " ";" CONF_FILE_AS_LIST "${CONF_FILE_EXPANDED}")
448449
list(LENGTH CONF_FILE_AS_LIST CONF_FILE_LENGTH)
449450
if(${CONF_FILE_LENGTH} EQUAL 1)
450451
# Need the file name to look for match.

cmake/dts.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ set(dts_files
6969
if(SUPPORTS_DTS)
7070
if(DTC_OVERLAY_FILE)
7171
# Convert from space-separated files into file list
72-
string(REPLACE " " ";" DTC_OVERLAY_FILE_RAW_LIST "${DTC_OVERLAY_FILE}")
72+
string(CONFIGURE "${DTC_OVERLAY_FILE}" DTC_OVERLAY_FILE_EXPANDED)
73+
string(REPLACE " " ";" DTC_OVERLAY_FILE_RAW_LIST "${DTC_OVERLAY_FILE_EXPANDED}")
7374
foreach(file ${DTC_OVERLAY_FILE_RAW_LIST})
7475
file(TO_CMAKE_PATH "${file}" cmake_path_file)
7576
list(APPEND DTC_OVERLAY_FILE_AS_LIST ${cmake_path_file})

cmake/kconfig.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ set(DOTCONFIG ${PROJECT_BINARY_DIR}/.config)
5252
set(PARSED_KCONFIG_SOURCES_TXT ${PROJECT_BINARY_DIR}/kconfig/sources.txt)
5353

5454
if(CONF_FILE)
55-
string(REPLACE " " ";" CONF_FILE_AS_LIST "${CONF_FILE}")
55+
string(CONFIGURE "${CONF_FILE}" CONF_FILE_EXPANDED)
56+
string(REPLACE " " ";" CONF_FILE_AS_LIST "${CONF_FILE_EXPANDED}")
5657
endif()
5758

5859
if(OVERLAY_CONFIG)
59-
string(REPLACE " " ";" OVERLAY_CONFIG_AS_LIST "${OVERLAY_CONFIG}")
60+
string(CONFIGURE "${OVERLAY_CONFIG}" OVERLAY_CONFIG_EXPANDED)
61+
string(REPLACE " " ";" OVERLAY_CONFIG_AS_LIST "${OVERLAY_CONFIG_EXPANDED}")
6062
endif()
6163

6264
if((DEFINED BOARD_REVISION) AND EXISTS ${BOARD_DIR}/${BOARD}_${BOARD_REVISION_STRING}.conf)

doc/application/index.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,10 @@ Application Configuration Directory
478478
Zephyr will use configuration files from the application's configuration
479479
directory except for files with an absolute path provided by the arguments
480480
described earlier, for example ``CONF_FILE``, ``OVERLAY_CONFIG``, and
481-
``DTC_OVERLAY_FILE``.
481+
``DTC_OVERLAY_FILE``. A file in a Zephyr module can be referred by
482+
escaping the Zephyr module dir variable like this
483+
``\${ZEPHYR_<modulename>_MODULE_DIR}/<path-to>/<file>``
484+
when setting any of said variables.
482485

483486
The application configuration directory is defined by the
484487
``APPLICATION_CONFIG_DIR`` variable.

doc/guides/dts/howtos.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ Set devicetree overlays
202202
Devicetree overlays are explained in :ref:`devicetree-intro`. The CMake
203203
variable :makevar:`DTC_OVERLAY_FILE` contains a space- or semicolon-separated
204204
list of overlay files to use. If :makevar:`DTC_OVERLAY_FILE` specifies multiple
205-
files, they are included in that order by the C preprocessor.
205+
files, they are included in that order by the C preprocessor. A file in a
206+
Zephyr module can be referred to by escaping the Zephyr module dir variable
207+
like `\${ZEPHYR_<modulename>_MODULE_DIR}/<path-to>/dts.overlay`
208+
when setting the DTC_OVERLAY_FILE variable.
206209

207210
You can set :makevar:`DTC_OVERLAY_FILE` to contain exactly the files you want
208211
to use. Here is an :ref:`example <west-building-dtc-overlay-file>` using
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
set(ZEPHYR_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/my_module")
6+
set(ZEPHYR_EXTRA_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/my_extra_module")
7+
8+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
9+
project(overlay_var_expansions)
10+
11+
FILE(GLOB app_sources src/*.c)
12+
target_sources(app PRIVATE ${app_sources})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: my_extra_module_name
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2022 Legrand, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
/* This file is intentionally empty */
9+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# extra-overlay-empty.conf
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: my_module_name

0 commit comments

Comments
 (0)