@@ -180,8 +180,8 @@ macro(_properties_parse content namespace)
180180
181181endmacro ()
182182
183- function (_properties_expand_value value return_value namespace
184- expanded_prop_list )
183+ # Utility function to expand the embedded variables
184+ function (_properties_expand_value value return_value namespace )
185185
186186 set (_value "${value} " )
187187
@@ -191,47 +191,52 @@ function(_properties_expand_value value return_value namespace
191191 return ()
192192 endif ()
193193
194- set (_result_value "" )
195- while (TRUE )
196- string (FIND "${_value} " "{" var_start_pos)
197- string (SUBSTRING "${_value} " 0 ${var_start_pos} val_prefix)
198- string_append(_result_value "${val_prefix} " )
199- if (var_start_pos EQUAL -1)
200- break ()
201- ENDIF ()
202- math (EXPR var_start_pos "${var_start_pos} + 1" )
203- string (SUBSTRING "${_value} " ${var_start_pos} -1 val_suffix)
204- string (FIND "${val_suffix} " "}" var_end_pos)
205- if (var_end_pos EQUAL -1)
206- string_append(_result_value "{${val_suffix} " )
207- break ()
208- ENDIF ()
209- string (SUBSTRING "${val_suffix} " 0 ${var_end_pos} var_name)
210- if (DEFINED "${namespace} .${var_name} " )
211- list (FIND "${expanded_prop_list} " "${var_name} " _found_idx)
212- if ("${_found_idx} " EQUAL -1)
213- list (APPEND "${expanded_prop_list} " "${var_name} " )
214- # message("=> Resolve *** ${var_name} *** : ${${namespace}.${var_name}}")
215- _properties_expand_value("${${namespace} .${var_name} }"
216- _var_value "${namespace} " "${expanded_prop_list} " )
217- set ("${namespace} .${var_name} " "${_var_value} " )
218- # message("=> EXPANDED ${var_name}: ${_var_value}")
219- string_append(_result_value "${_var_value} " )
220- else ()
221- string_append(_result_value "${${namespace} .${var_name} }" )
222- endif ()
223- else ()
224- string_append(_result_value "{${var_name} }" )
194+ # Set previous value to nothing so that there is at least one iteration
195+ set (_previous_value "" )
196+ while (NOT "${_previous_value} " STREQUAL "${_value} " )
197+ set (_previous_value "${_value} " )
198+
199+ # Get the variables list
200+ string (REGEX MATCHALL "{[^{}/]+}" _var_list "${_value} " )
201+ if (NOT "${_var_list} " STREQUAL "" )
202+ list (REMOVE_DUPLICATES _var_list)
225203 endif ()
226- math (EXPR var_end_pos "${var_end_pos} + 1" )
227- string (SUBSTRING "${val_suffix} " ${var_end_pos} -1 _value)
204+ foreach (_var_str IN LISTS _var_list)
205+
206+ # Get the variable name
207+ string (REGEX MATCH "^{(.*)}$" _match "${_var_str} " )
208+ set (_var_name "${CMAKE_MATCH_1} " )
209+
210+ # Check if not resolved already
211+ if (NOT DEFINED "/prop_int_resolved.${_var_name} " )
212+ # If such a variable is not in the namespace, no need to resolve
213+ if (NOT DEFINED "${namespace} .${_var_name} " )
214+ properties_set_value("/prop_int_unresolved" ${_var_name} "" )
215+ continue ()
216+ endif ()
217+
218+ # Temporarily resolve it to the same variable to handle recursive
219+ # references
220+ properties_set_value("/prop_int_resolved" "${_var_name} "
221+ "{${_var_name} }" )
222+
223+ # message("=> Resolve *** ${_var_name} *** : "
224+ # "${${namespace}.${_var_name}}")
225+ _properties_expand_value("${${namespace} .${_var_name} }"
226+ _var_value "${namespace} " )
227+ properties_set_value("/prop_int_resolved" "${_var_name} "
228+ "${_var_value} " )
229+ # message("=> EXPANDED ${_var_name}: ${_var_value}")
230+ endif ()
231+
232+ string (REPLACE "${_var_str} " "${/prop_int_resolved.${_var_name} }"
233+ _value "${_value} " )
234+
235+ endforeach ()
228236 endwhile ()
229237
230- set ("${expanded_prop_list} " "${${expanded_prop_list} }" PARENT_SCOPE)
231- foreach (_prop IN LISTS ${expanded_prop_list} )
232- set ("${namespace} .${_prop} " "${${namespace} .${_prop} }" PARENT_SCOPE)
233- endforeach ()
234- set ("${return_value} " "${_result_value} " PARENT_SCOPE)
238+ properties_set_parent_scope("/prop_int_resolved" )
239+ properties_set_parent_scope("/prop_int_unresolved" )
240+ set ("${return_value} " "${_value} " PARENT_SCOPE)
235241
236242endfunction ()
237-
0 commit comments