xref: /llvm-project/cmake/Modules/SortSubset.cmake (revision 06400a0142af8297b5d39b8f34a7c59db6f9910c)
1# Sort a subset of a list according to the ordering in the full list.
2#
3# Given a list and a subset of that list, this function sorts the subset
4# according to the order in the full list, and returns that in the given
5# output variable.
6#
7# full_list:
8#   The list containing the desired order of elements in the sub-list.
9#
10# sub_list:
11#   A subset of the elements in `full_list`. Those elements will be sorted
12#   according to the order in `full_list`.
13#
14# out_var:
15#   A variable to store the resulting sorted sub-list in.
16function(sort_subset full_list sub_list out_var)
17  set(result "${full_list}")
18  foreach(project IN LISTS full_list)
19    if (NOT project IN_LIST sub_list)
20      list(REMOVE_ITEM result ${project})
21    endif()
22  endforeach()
23
24  set(${out_var} "${result}" PARENT_SCOPE)
25endfunction()
26