From ec7a45cc44a40de6da6c2665bd37baa450158b97 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Mon, 18 Aug 2025 12:17:15 +0200 Subject: [PATCH] feat(cmakev2/utilities): add BASE_DIR option to __get_absolute_paths Add an optional BASE_DIR option to specify a directory that will serve as the base directory for evaluating input paths. This can be useful, for example, when collecting component sources. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/utilities.cmake | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/cmakev2/utilities.cmake b/tools/cmakev2/utilities.cmake index 7eedd2d77e2..c5520ac6e77 100644 --- a/tools/cmakev2/utilities.cmake +++ b/tools/cmakev2/utilities.cmake @@ -134,16 +134,20 @@ endfunction() #[[ __get_absolute_paths(PATHS ... + BASE_DIR OUTPUT ) :PATHS[in]: List of paths to convert to absolute paths. + :BASE_DIR[in,opt]: Evaluate relative paths based on the specified + ````. If not provided, use CMAKE_CURRENT_SOURCE_DIR + instead. :OUTPUT[out]: Output variable to store absolute paths. For a given ``PATHS``, return the absolute paths in ``OUTPUT``. #]] function(__get_absolute_paths) set(options) - set(one_value OUTPUT) + set(one_value BASE_DIR OUTPUT) set(multi_value PATHS) cmake_parse_arguments(ARG "${options}" "${one_value}" "${multi_value}" ${ARGN}) @@ -157,7 +161,11 @@ function(__get_absolute_paths) set(absolute_paths "") foreach(path IN LISTS ARG_PATHS) - get_filename_component(path_abs ${path} ABSOLUTE) + if(DEFINED ARG_BASE_DIR) + get_filename_component(path_abs ${path} ABSOLUTE BASE_DIR "${ARG_BASE_DIR}") + else() + get_filename_component(path_abs ${path} ABSOLUTE) + endif() list(APPEND absolute_paths "${path_abs}") endforeach()