Skip to content

Commit 2d3c4a6

Browse files
Gregory Shuelegrand-gregshue
authored andcommitted
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. Verified by passing all the following tests: ./scripts/twister -T tests/cmake/overlays/ Fixes #41830 Signed-off-by: Gregory Shue <[email protected]>
1 parent 2f2c017 commit 2d3c4a6

File tree

15 files changed

+79
-6
lines changed

15 files changed

+79
-6
lines changed

cmake/modules/configuration_files.cmake

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

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

cmake/modules/dts.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ set(dts_files
9292
if(SUPPORTS_DTS)
9393
if(DTC_OVERLAY_FILE)
9494
# Convert from space-separated files into file list
95-
string(REPLACE " " ";" DTC_OVERLAY_FILE_RAW_LIST "${DTC_OVERLAY_FILE}")
95+
string(CONFIGURE "${DTC_OVERLAY_FILE}" DTC_OVERLAY_FILE_EXPANDED)
96+
string(REPLACE " " ";" DTC_OVERLAY_FILE_RAW_LIST "${DTC_OVERLAY_FILE_EXPANDED}")
9697
foreach(file ${DTC_OVERLAY_FILE_RAW_LIST})
9798
file(TO_CMAKE_PATH "${file}" cmake_path_file)
9899
list(APPEND DTC_OVERLAY_FILE_AS_LIST ${cmake_path_file})

cmake/modules/kconfig.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ set(DOTCONFIG ${PROJECT_BINARY_DIR}/.config)
6969
set(PARSED_KCONFIG_SOURCES_TXT ${PROJECT_BINARY_DIR}/kconfig/sources.txt)
7070

7171
if(CONF_FILE)
72-
string(REPLACE " " ";" CONF_FILE_AS_LIST "${CONF_FILE}")
72+
string(CONFIGURE "${CONF_FILE}" CONF_FILE_EXPANDED)
73+
string(REPLACE " " ";" CONF_FILE_AS_LIST "${CONF_FILE_EXPANDED}")
7374
endif()
7475

7576
zephyr_get(OVERLAY_CONFIG SYSBUILD LOCAL)
7677
if(OVERLAY_CONFIG)
77-
string(REPLACE " " ";" OVERLAY_CONFIG_AS_LIST "${OVERLAY_CONFIG}")
78+
string(CONFIGURE "${OVERLAY_CONFIG}" OVERLAY_CONFIG_EXPANDED)
79+
string(REPLACE " " ";" OVERLAY_CONFIG_AS_LIST "${OVERLAY_CONFIG_EXPANDED}")
7880
endif()
7981

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

doc/build/dts/howtos.rst

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

227230
You can set :makevar:`DTC_OVERLAY_FILE` to contain exactly the files you want
228231
to use. Here is an :ref:`example <west-building-dtc-overlay-file>` using

doc/build/kconfig/setting.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ The application configuration can come from the sources below. By default,
170170

171171
All configuration files will be taken from the application's configuration
172172
directory except for files with an absolute path that are given with the
173-
``CONF_FILE`` argument.
173+
``CONF_FILE``, ``OVERLAY_CONFIG``, and ``DTC_OVERLAY_FILE`` arguments. For these,
174+
a file in a Zephyr module can be referred by escaping the Zephyr module dir
175+
variable like this ``\${ZEPHYR_<module>_MODULE_DIR}/<path-to>/<file>``
176+
when setting any of said variables in the application's :file:`CMakeLists.txt`.
174177

175178
See :ref:`Application Configuration Directory <application-configuration-directory>`
176179
on how the application configuration directory is defined.
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)