How do I manipulate CMake lists as sets?

做~自己de王妃 提交于 2020-02-04 22:18:16

问题


In CMake, lists are used extensively. Sometimes you have two lists of items (strings, basically), and you want to consider their intersection, difference or union. Like in this case that just came up for me.

How do I produce such intersection, difference or union lists?

Note: The outputs need to have no duplicates, the inputs not really


回答1:


Suppose our lists are in variables S and T.

For the union, write:

list(APPEND union_list ${S} ${T})
list(REMOVE_DUPLICATES union_list)

For set difference, write:

list(APPEND S_minus_T ${S})
list(REMOVE_ITEM S_minus_T ${T})

And then we use some set identities to obtain the intersection through the symmetric difference:

  • S∩T = (S∪T) ∖ (S∆T)
  • S∆T = (S∖T) ∪ (T\S)


来源:https://stackoverflow.com/questions/59578248/how-do-i-manipulate-cmake-lists-as-sets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!