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

Brad King brad.king at kitware.com
Mon Aug 20 08:00:53 EDT 2012


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.

-Brad



More information about the cmake-developers mailing list