[CMake] Confusion with range-based FOREACH logic
Robert Dailey
rcdailey.lists at gmail.com
Tue Jan 23 12:27:36 EST 2018
I am doing the following:
```
set( CS_THIRD_PARTY_REFERENCES
Iconic.Zip ${CMAKE_CURRENT_SOURCE_DIR}/DotNetZip/Iconic.Zip.dll
)
if( CS_THIRD_PARTY_REFERENCES )
list( LENGTH CS_THIRD_PARTY_REFERENCES len )
message( STATUS "len: ${len}" )
foreach( i RANGE 0 ${len} 2 )
message( STATUS "i: ${i}" )
list( GET CS_THIRD_PARTY_REFERENCES ${i} assembly_name )
math( EXPR i "${i}+1" )
list( GET CS_THIRD_PARTY_REFERENCES ${i} assembly_path )
set_property( TARGET ${target_name} PROPERTY
VS_DOTNET_REFERENCE_${assembly_name} ${assembly_path}
)
message( STATUS "i: ${i}" )
message( STATUS "assembly_name: ${assembly_name}" )
message( STATUS "assembly_path: ${assembly_path}" )
endforeach()
endif()
```
I am finding that the foreach() loops 2 times when ${len} is 2. What I
expect during the 2nd iteration is that it does ${i}+STEP (0+2) which
would equal 2, and so long as 2<${len} (2<2), then it would continue
to iterate. In this case, it should stop after the first iteration.
I'm thinking that this should work like a C++ for loop. Is this not
the case? How should I be iterating over a list of 2 times at a time?
More information about the CMake
mailing list