How about the following two examples for a table or 2d array.

In the first one, each column can have a name too.  Its like an array of 
pointers in C++.

set(fruits apple orange banana)
set(animals cat dog elephant)
set(columns fruits animals)

foreach(column ${columns})
  foreach(item ${${column}})
    message("${column} has item ${item}")
  endforeach()
endforeach()



Or if you have pairs, one fruit with one animal

set(tuples
  "apple\;cat"
  "orange\;dog"
  "banana\;elephant"
  )

foreach(pair ${tuples})
  message("pair has items ${pair}")
  foreach(component ${pair})
    message("component = ${component}")
  endforeach()
endforeach()


Both of those seem close enough to 2d array functionality using the cmake 
language.

Clint

On Nov 29, 2011, at 4:28 PM, 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
> 
> 
> On Mon, Nov 28, 2011 at 2:31 PM, Robert Dailey <rcdai...@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
> 
> <array2d.cmake>--
> 
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: 
> http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to