From 38fc8380c55f96d5bc903c2bc341f66b402966d0 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Tue, 19 Aug 2025 10:16:51 +0200 Subject: [PATCH] feat(cmakev2/utilities): add remove_duplicated_flags function This function is primarily used by the toolchain files. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/utilities.cmake | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/cmakev2/utilities.cmake b/tools/cmakev2/utilities.cmake index 290ee7a2323..7eedd2d77e2 100644 --- a/tools/cmakev2/utilities.cmake +++ b/tools/cmakev2/utilities.cmake @@ -473,3 +473,23 @@ function(__get_compile_options) endforeach() set(${ARG_OUTPUT} "${compile_options}" PARENT_SCOPE) endfunction() + +#[[ + remove_duplicated_flags( ) + + :flags[in]: Input string with compilation flags. + :uniq_flags[out]: Output string with unified compilation flags. + + Remove duplicate entries from a string of compilation flags. +#]] +function(remove_duplicated_flags FLAGS UNIQFLAGS) + set(FLAGS_LIST "${FLAGS}") + # Convert the given flags, as a string, into a CMake list type + separate_arguments(FLAGS_LIST) + # Remove all the duplicated flags + list(REMOVE_DUPLICATES FLAGS_LIST) + # Convert the list back to a string + string(REPLACE ";" " " FLAGS_LIST "${FLAGS_LIST}") + # Return that string to the caller + set(${UNIQFLAGS} "${FLAGS_LIST}" PARENT_SCOPE) +endfunction()