feat(cmakev2/utilities): add remove_duplicated_flags function

This function is primarily used by the toolchain files.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata
2025-11-04 07:48:13 +01:00
parent 71f5ee5bf6
commit 38fc8380c5
+20
View File
@@ -473,3 +473,23 @@ function(__get_compile_options)
endforeach()
set(${ARG_OUTPUT} "${compile_options}" PARENT_SCOPE)
endfunction()
#[[
remove_duplicated_flags(<flags> <uniq_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()