Skip to content

Commit 6384f28

Browse files
tejlmandkartben
authored andcommitted
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. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
1 parent 7ed7cd1 commit 6384f28

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

cmake/modules/extensions.cmake

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,21 @@ endmacro()
464464

465465
# Provides amend functionality to a Zephyr library for out-of-tree usage.
466466
#
467+
# Usage:
468+
# zephyr_library_amend([<dir>])
469+
#
467470
# When called from a Zephyr module, the corresponding zephyr library defined
468471
# within Zephyr will be looked up.
469472
#
470-
# Note, in order to ensure correct library when amending, the folder structure in the
471-
# Zephyr module must resemble the structure used in Zephyr, as example:
473+
# <dir>: Use '<dir>' as out-of-tree base directory from where the Zephyr
474+
# library name shall be generated.
475+
# <dir> can be used in cases where the structure for the library is not
476+
# placed directly at the ZEPHYR_MODULE's root directory or for cases
477+
# where the module integration file is located in a 'MODULE_EXT_ROOT'.
478+
#
479+
# Note, in order to ensure correct library when amending, the folder structure
480+
# in the Zephyr module or '<dir>' base directory must resemble the structure
481+
# used in Zephyr, as example:
472482
#
473483
# Example: to amend the zephyr library created in
474484
# ZEPHYR_BASE/drivers/entropy/CMakeLists.txt
@@ -497,7 +507,11 @@ macro(zephyr_library_amend)
497507
message(FATAL_ERROR "Function only available for Zephyr modules.")
498508
endif()
499509

500-
zephyr_library_get_current_dir_lib_name(${ZEPHYR_CURRENT_MODULE_DIR} lib_name)
510+
if(${ARGC} EQUAL 1)
511+
zephyr_library_get_current_dir_lib_name(${ARGV0} lib_name)
512+
else()
513+
zephyr_library_get_current_dir_lib_name(${ZEPHYR_CURRENT_MODULE_DIR} lib_name)
514+
endif()
501515

502516
set(ZEPHYR_CURRENT_LIBRARY ${lib_name})
503517
endmacro()

0 commit comments

Comments
 (0)