[cmake-developers] foreach(IN LISTS) or not

Rolf Eike Beer eike at sf-mail.de
Mon Aug 20 08:24:46 EDT 2012


Am 2012-08-20 14:00, schrieb Brad King:
> On 08/19/2012 08:09 AM, Rolf Eike Beer wrote:
>> I'm wondering if it makes sense to do a mass replace of
>>
>> foreach(listvar ${somevar})
>>
>> to
>>
>> foreach(listvar IN LISTS somevar)
>>
>> From what I see this should be more efficient as the variable is not 
>> first
>> expanded and then parsed again, it could save from potential trouble 
>> if e.g.
>> somevar includes elements with spaces, and it should not introduce 
>> any further
>> hassle.
>
> The main difference in behavior is when the list contains empty 
> elements.
> The former will remove them.  The latter will include them.
>
> Try running some timings in isolated test cases to see if there is 
> really
> much difference in efficiency.

The gain in efficiency would be just a bonus. My main concern is that 
the current use may happily cause trouble in most cases when an input 
path contains spaces or semicolons because of missing quoting and 
escaping. And most of them build up those lists by hand anyway so we are 
sure on most cases that empty elements are not present anyway.

Eike



More information about the cmake-developers mailing list