The source of your confusion is probably the interpretation of quoted strings in CMake.
For example, the following: everyone iterates over the list of strings correctly:
(1) foreach(LETTER abc) [...] (2) foreach(LETTER a;b;c) [...] (3) set(MYLIST "a;b;c") foreach(LETTER ${MYLIST}) [...]
The only time this does not work is
(4) foreach(LETTER "a;b;c") [...]
The reason why work (1) and (2) is in the CMake language manual for unquoted arguments :
Unquoted content consists of all text in an adjacent block of allowed or escaped characters. Both sequences and variables of Escape Links are evaluated. The resulting value is divided into the same way. Lists are divided into elements . Each non-empty element is assigned the value of invoking the command as an argument. Therefore, an undefined argument can be assigned to a command call as zero or more arguments.
Note that this is different from the arguments given , which also evaluate Escape sequences and variable references, but do not expand the list. This explains why (4) fails.
An interesting question now is why (3) is still doing well. set will take both a single value and an argument to a list value. In fact, everything until closing ) or one of the keywords CACHE or PARENT_SCOPE is considered part of the value. Thus, the following two commands are equivalent:
set(MYLIST "a;b;c") set(MYLIST a;b;c)
In both cases, the MYLIST value will be a;b;c (without quotes).
When we now expand ${MYLIST} into another command, you may think that it performs a simple line replacement with the MYLIST value, which is a;b;c . The resulting command will then be expanded using the rules of quoted or unquoted arguments. That is, the following will work:
foreach(LETTER ${MYLIST}) [...]
until it is:
foreach(LETTER "${MYLIST}") [...]
ComicSansMS Jul 28 '14 at 8:48 2014-07-28 08:48
source share