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