如何将CMake列表设置为集合? [英] How do I manipulate CMake lists as sets?

查看:168
本文介绍了如何将CMake列表设置为集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CMake中,列表被广泛使用.有时,您有两个项目列表(基本上是字符串),并且您想考虑它们的交集,差值或并集.就像在这种情况刚出现在我身上一样.

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

推荐答案

假设我们的列表位于变量ST中.

Suppose our lists are in variables S and T.

对于工会,写:

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)

这篇关于如何将CMake列表设置为集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆