[CMake] 2D arrays
Michael Hertling
mhertling at online.de
Tue Nov 29 18:57:37 EST 2011
On 11/30/2011 12:28 AM, Robert Dailey wrote:
> I have created a pretty clean solution to this until there is native
> support for multi-dimensional arrays in CMake. I have attached the module,
> hopefully it will prove useful to others. Here is an example of how to use
> it:
>
> set( two_dee_array
> apple cat
> orange dog
> banana elephant
> )
>
> array2d_begin_loop( advanced "${two_dee_array}" 2 "fruit;animal" )
> while( advanced )
> message( "Fruit: ${fruit}" )
> message( "Animal: ${animal}" )
> array2d_advance()
> endwhile()
>
> ---------
> Robert Dailey
Just some spontaneous questions/remarks:
- Why do you use macros instead of functions?
- What's about cleaning up the numerous helper variables,
e.g. by an additional array2d_cleanup() function or the like?
- In array2d_begin_loop(), couldn't you rearrange the parameters,
array2d_begin_loop(advanced "fruit;animal" ${two_dee_array}), use
LIST(LENGTH var_names _array2d_width) and take ARGN as the array?
Regards,
Michael
> On Mon, Nov 28, 2011 at 2:31 PM, Robert Dailey <rcdailey at gmail.com> wrote:
>
>> Is it possible to have 2D arrays in CMake? As far as the core syntax is
>> concerned, it seems like only 1D arrays are supported. So far I've had to
>> work around this issue by using a flat array and skipping over elements
>> using foreach() with a range and step.
>>
>> Any ideas? Thanks.
>>
>> ---------
>> Robert Dailey
More information about the CMake
mailing list