Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I manipulate CMake lists as sets?

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

like image 912
einpoklum Avatar asked Jan 03 '20 11:01

einpoklum


People also ask

How to set list in CMake?

A list in cmake is a ; separated group of strings. To create a list the set command can be used. For example, set(var a b c d e) creates a list with a;b;c;d;e , and set(var "a b c d e") creates a string or a list with one item in it.

What is ${} in CMake?

You access a variable by using ${} , such as ${MY_VARIABLE} . 1. CMake has the concept of scope; you can access the value of the variable after you set it as long as you are in the same scope. If you leave a function or a file in a sub directory, the variable will no longer be defined.


1 Answers

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)
like image 156
einpoklum Avatar answered Oct 19 '22 06:10

einpoklum