Skip to content

Commit 02dc89c

Browse files
committed
[nrf fromlist] cmake: support directory as argument to zephyr_library_amend()
Extend `zephyr_library_amend()` to support an optional directory argument. The current `zephyr_library_amend()` works well when used inside a Zephyr module with same structure, but fails when the macro is called from Zephyr module integration code is located in a Zephyr `MODULE_EXT_ROOT` because in this case the CMake code being executed is not present in the Zephyr module itself, in which case the dir name creation based on relative to module dir give wrong result. For this use-case then support a base directory. This also allows for use-cases in Zephyr modules where the directory structure matching Zephyr's own structure is placed in a sub-folder. Upstream PR #: 87274 Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
1 parent e62a931 commit 02dc89c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

cmake/modules/extensions.cmake

+14-1
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,18 @@ endmacro()
463463

464464
# Provides amend functionality to a Zephyr library for out-of-tree usage.
465465
#
466+
# Usage:
467+
# zephyr_library_amend([<dir>])
468+
#
466469
# When called from a Zephyr module, the corresponding zephyr library defined
467470
# within Zephyr will be looked up.
468471
#
472+
# <dir>: Use '<dir>' as out-of-tree base directory from where the Zephyr
473+
# library name shall be generated.
474+
# <dir> can be used in cases where the structure for the library is not
475+
# placed directly at the ZEPHYR_MODULE's root directory or for cases
476+
# where the module integration file is located in a 'MODULE_EXT_ROOT'.
477+
#
469478
# Note, in order to ensure correct library when amending, the folder structure in the
470479
# Zephyr module must resemble the structure used in Zephyr, as example:
471480
#
@@ -496,7 +505,11 @@ macro(zephyr_library_amend)
496505
message(FATAL_ERROR "Function only available for Zephyr modules.")
497506
endif()
498507

499-
zephyr_library_get_current_dir_lib_name(${ZEPHYR_CURRENT_MODULE_DIR} lib_name)
508+
if(${ARGC} EQUAL 1)
509+
zephyr_library_get_current_dir_lib_name(${ARGV0} lib_name)
510+
else()
511+
zephyr_library_get_current_dir_lib_name(${ZEPHYR_CURRENT_MODULE_DIR} lib_name)
512+
endif()
500513

501514
set(ZEPHYR_CURRENT_LIBRARY ${lib_name})
502515
endmacro()

0 commit comments

Comments
 (0)