[CMake] Nested While Loops

Mike Jackson mike.jackson at bluequartz.net
Mon Sep 22 12:56:03 EDT 2008


Does cmake support nested while loops? I have a quadruple nested while  
loop and it looks as though only the inner most loop is being executed  
once.

HEre is a CMakeLists.txt file that illustrates the problem:

I tried this on CMake 2.6.1 and CMake CVS HEAD.. Any help would be  
appreciated. I am trying to generate a folder hierarchy in preparation  
for some cross platform tests.. other wise I would just use a shell  
script.


#------------------------------------------------
cmake_minimum_required(VERSION 2.6)
#  
--------------------------------------------------------------------------
macro (DataImportTestSetup name alt_name start count end  increment  
index)
     SET (${name}_name ${name} )
     SET (${name}_alt_name ${alt_name} )
     SET (${name}_start ${start} )
     SET (${name}_count ${count} )
     SET (${name}_end ${end} )
     SET (${name}_increment ${increment} )
     SET (${name}_index ${index})

endmacro (DataImportTestSetup name alt_name start count end increment  
index)
#  
--------------------------------------------------------------------------

DataImportTestSetup("Dim_0" "Vol Frac" 46 3 50 2 0)
DataImportTestSetup("Dim_1" "Rnd Seed" 1000 4 2500 400 1)
DataImportTestSetup("Dim_2" "TS" 95 5 99 1 2)
DataImportTestSetup("Dim_3" "Slice" 251 5 255 1 3)


#CONFIGURE_FILE(${MXA_TEST_SRC_DIR}/TestDataFileLocations.h.in
#           ${PROJECT_BINARY_DIR}/TestDataFileLocations.h @ONLY  
IMMEDIATE)


SET (Dim_0_index 0)
SET (Dim_1_index 0)
SET (Dim_2_index 0)
SET (Dim_3_index 0)

while (${Dim_0_index} LESS ${Dim_0_count} )
     message (STATUS "Dim_0_index: ${Dim_0_index}")
     #----
     while (${Dim_1_index} LESS ${Dim_1_count} )
         message (STATUS "Dim_1_index: ${Dim_1_index}")
         #----
         while (${Dim_2_index} LESS ${Dim_2_count} )
             message (STATUS "Dim_2_index: ${Dim_2_index}")
             #----
             while (${Dim_3_index} LESS ${Dim_3_count} )
                 message (STATUS "Dim_3_index: ${Dim_3_index}")
                 #----
                 SET (DIR_NAME "${MXA_TEMP_DIR}DataImportTest/ 
test_data/${Dim_0_name}-${Dim_0_start}/${Dim_1_name}-${Dim_1_start}/$ 
{Dim_2_name}-${Dim_2_start}/${Dim_3_name}-${Dim_3_start}")
                 message (STATUS "DIR_NAME: ${DIR_NAME}")

                 MATH(EXPR Dim_3_start "${Dim_3_start} + $ 
{Dim_3_increment}")
                 MATH(EXPR Dim_3_index "${Dim_3_index} + 1")
             endwhile (${Dim_3_index} LESS ${Dim_3_count} )

             MATH(EXPR Dim_2_start "${Dim_2_start} + $ 
{Dim_2_increment}")
             MATH(EXPR Dim_2_index "${Dim_2_index} + 1")
         endwhile (${Dim_2_index} LESS ${Dim_2_count} )

         MATH(EXPR Dim_1_start "${Dim_1_start} + ${Dim_1_increment}")
         MATH(EXPR Dim_1_index "${Dim_1_index} + 1")
     endwhile (${Dim_1_index} LESS ${Dim_1_count} )

     MATH(EXPR Dim_0_start "${Dim_0_start} + ${Dim_0_increment}")
     MATH(EXPR Dim_0_index "${Dim_0_index} + 1")
endwhile (${Dim_0_index} LESS ${Dim_0_count} )





  _________________________________________________
| Mike Jackson - Principal Software Engineer      |
| BlueQuartz Software                             |
| mike.jackson at bluequartz.net                     |
| www.bluequartz.net                              |
---------------------------------------------------



More information about the CMake mailing list