@@ -248,78 +248,58 @@ function(__project_build_tools_recursive_scan_unwrap OUTPUT_VAR INPUT_VAR)
248248 endif ()
249249endfunction ()
250250
251- macro (__project_build_tools_recursive_scan_imported_locations)
252- if (NOT DEFINED __project_build_tools_recursive_call_level)
253- set (__project_build_tools_recursive_call_level 1)
254- else ()
255- math (EXPR __project_build_tools_recursive_call_level
256- "${__project_build_tools_recursive_call_level} + 1" )
257- endif ()
258- foreach (TARGET_NAME_ORIGIN_${__project_build_tools_recursive_call_level}
259- ${ARGN} )
260- if (TARGET_NAME_ORIGIN_${__project_build_tools_recursive_call_level} MATCHES
261- "^\\\$ <.*>?$" )
262- __project_build_tools_recursive_scan_unwrap(
263- TARGET_NAME
264- "${TARGET_NAME_ORIGIN_${__project_build_tools_recursive_call_level} }" )
251+ function (project_build_tools_unwrap_interface_link_libraries OUTPUT_VAR)
252+ set (optionArgs)
253+ set (oneValueArgs)
254+ set (multiValueArgs TARGET_NAME TARGET_MATCH)
255+ cmake_parse_arguments (__SCAN_OPTION "${optionArgs} " "${oneValueArgs} "
256+ "${multiValueArgs} " "${ARGN} " )
257+ set (__OUTPUT_VAR)
258+
259+ set (__TARGET_CHECK_NAMES)
260+ foreach (TARGET_NAME_ORIGIN ${__SCAN_OPTION_TARGET_NAME} )
261+ if (TARGET_NAME_ORIGIN MATCHES "^\\\$ <.*>?$" )
262+ __project_build_tools_recursive_scan_unwrap(TARGET_NAME
263+ "${TARGET_NAME_ORIGIN} " )
265264 else ()
266- set (TARGET_NAME
267- "${TARGET_NAME_ORIGIN_${__project_build_tools_recursive_call_level} }" )
265+ set (TARGET_NAME "${TARGET_NAME_ORIGIN} " )
268266 endif ()
269- if (NOT DEFINED
270- __project_build_tools_recursive_scan_imported_locations_${TARGET_NAME}
271- AND TARGET ${TARGET_NAME} )
272- set (__project_build_tools_recursive_scan_imported_locations_${TARGET_NAME}
273- TRUE )
274- set (__lib_path)
275- project_build_tools_get_imported_location(__lib_path ${TARGET_NAME} )
276- if (__lib_path)
277- list (APPEND __OUTPUT_VAR ${__lib_path} )
267+
268+ if (TARGET ${TARGET_NAME} )
269+ # Get the imported location of the target
270+ project_build_tools_get_imported_location(__TARGET_IMPORTED_LOCATION
271+ ${TARGET_NAME} )
272+ if (__TARGET_IMPORTED_LOCATION)
273+ list (APPEND __TARGET_CHECK_NAMES ${__TARGET_IMPORTED_LOCATION} )
278274 endif ()
279275
276+ # Get the interface link libraries of the target
280277 set (__TARGET_LINK_LIBRARIES)
281278 get_target_property (__TARGET_LINK_LIBRARIES ${TARGET_NAME}
282279 INTERFACE_LINK_LIBRARIES)
283- if (__SCAN_OPTION_TARGET_MATCH)
284- set (__TARGET_LINK_LIBRARIES_SELECTED)
285- foreach (__TARGET_LINK_LIBRARIES_ITEM IN LISTS __TARGET_LINK_LIBRARIES)
286- set (__TARGET_MATCHED FALSE )
287- foreach (__MATCH_RULE ${__SCAN_OPTION_TARGET_MATCH} )
288- if (__TARGET_LINK_LIBRARIES_ITEM MATCHES "${__MATCH_RULE} " )
289- set (__TARGET_MATCHED TRUE )
290- break ()
291- endif ()
292- endforeach ()
293- if (__TARGET_MATCHED)
294- list (APPEND __TARGET_LINK_LIBRARIES_SELECTED
295- ${__TARGET_LINK_LIBRARIES_ITEM} )
296- endif ()
297- endforeach (__TARGET_LINK_LIBRARIES_ITEM IN LISTS
298- __TARGET_LINK_LIBRARIES)
299- else ()
300- set (__TARGET_LINK_LIBRARIES_SELECTED ${__TARGET_LINK_LIBRARIES} )
301- endif ()
280+ list (APPEND __TARGET_CHECK_NAMES ${__TARGET_LINK_LIBRARIES} )
302281
303- if (__TARGET_LINK_LIBRARIES_SELECTED)
304- __project_build_tools_recursive_scan_imported_locations(
305- ${__TARGET_LINK_LIBRARIES_SELECTED} )
306- endif ()
307282 endif ()
308283 endforeach ()
309- math (EXPR __project_build_tools_recursive_call_level
310- "${__project_build_tools_recursive_call_level} - 1" )
311- endmacro ()
312-
313- function (project_build_tools_recursive_scan_imported_locations OUTPUT_VAR)
314- set (optionArgs)
315- set (oneValueArgs)
316- set (multiValueArgs TARGET_NAME TARGET_MATCH)
317- cmake_parse_arguments (__SCAN_OPTION "${optionArgs} " "${oneValueArgs} "
318- "${multiValueArgs} " "${ARGN} " )
319- set (__OUTPUT_VAR)
320284
321- __project_build_tools_recursive_scan_imported_locations(
322- ${__SCAN_OPTION_TARGET_NAME} )
285+ list (REMOVE_DUPLICATES __TARGET_CHECK_NAMES)
286+ # If the target match option is set, filter the link names
287+ if (__SCAN_OPTION_TARGET_MATCH)
288+ foreach (__LINK_NAME IN LISTS __TARGET_CHECK_NAMES)
289+ set (__TARGET_MATCHED FALSE )
290+ foreach (__MATCH_RULE ${__SCAN_OPTION_TARGET_MATCH} )
291+ if (__LINK_NAME MATCHES "${__MATCH_RULE} " )
292+ set (__TARGET_MATCHED TRUE )
293+ break ()
294+ endif ()
295+ endforeach ()
296+ if (__TARGET_MATCHED)
297+ list (APPEND __OUTPUT_VAR ${__LINK_NAME} )
298+ endif ()
299+ endforeach ()
300+ else ()
301+ set (__OUTPUT_VAR ${__TARGET_CHECK_NAMES} )
302+ endif ()
323303
324304 set (${OUTPUT_VAR}
325305 ${__OUTPUT_VAR}
0 commit comments