From 49ff83fcef270c2a4317b5c95524c08a26120074 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 21 Sep 2023 09:15:39 +0200 Subject: [PATCH] CMake: Use while instead of foreach in qt_evaluate_config_expression By using a while loop instead of a foreach(RANGE), we can simplify the code and remove the skipNext variable. Also, we need to access the last used iteration index in a future commit. This is not possible with a foreach loop without saving the index in another variable. Change-Id: I39306a0105fb31a6a8f39e9d4c47ee3424599a2b Reviewed-by: Alexandru Croitor Reviewed-by: Amir Masoud Abdol --- cmake/QtFeature.cmake | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index 0f2b55b8ce..2c6fa94c25 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -84,17 +84,13 @@ endfunction() function(qt_evaluate_config_expression resultVar) set(result "") set(nestingLevel 0) - set(skipNext OFF) set(expression "${ARGN}") list(LENGTH expression length) + set(memberIdx -1) math(EXPR length "${length}-1") - foreach(memberIdx RANGE ${length}) - if(${skipNext}) - set(skipNext OFF) - continue() - endif() - + while(memberIdx LESS ${length}) + math(EXPR memberIdx "${memberIdx} + 1") list(GET expression ${memberIdx} member) if("${member}" STREQUAL "(") @@ -140,7 +136,7 @@ function(qt_evaluate_config_expression resultVar) set(lhs "${${lhs}}") math(EXPR rhsIndex "${memberIdx}+1") - set(skipNext ON) + set(memberIdx ${rhsIndex}) list(GET expression ${rhsIndex} rhs) # We can't pass through an empty string with double quotes through various @@ -160,7 +156,7 @@ function(qt_evaluate_config_expression resultVar) list(APPEND result ${member}) endif() - endforeach() + endwhile() # The 'TARGET Gui' case is handled by qt_evaluate_to_boolean, by passing those tokens verbatim # to if().