@@ -328,9 +328,11 @@ endfunction()
328328# :type [HEADERS]: bool
329329# :keyword [FILE_SETS]: Specify list of File sets to retrieve the files from
330330# :type [FILE_SETS]: list[string]
331+ # :keyword [EXCLUDED_IPS]: Exclude the IPs of the source file search.
332+ # :type [FILE_SETS]: list[string]
331333#]]
332334function (get_ip_sources OUTVAR IP_LIB LANGUAGE )
333- cmake_parse_arguments (ARG "NO_DEPS;HEADERS" "" "FILE_SETS" ${ARGN} )
335+ cmake_parse_arguments (ARG "NO_DEPS;HEADERS" "" "FILE_SETS;EXCLUDED_IPS " ${ARGN} )
334336 alias_dereference (_reallib ${IP_LIB} )
335337
336338 # Handle NO_DEPS flag
@@ -347,6 +349,15 @@ function(get_ip_sources OUTVAR IP_LIB LANGUAGE)
347349 set (property_type HEADERS)
348350 list (REMOVE_ITEM ARGN HEADERS)
349351 endif ()
352+
353+ if (ARG_EXCLUDED_IPS)
354+ # Clean ARGN from EXCLUDED_IPS and listed IPs
355+ foreach (ip ${ARG_EXCLUDED_IPS} )
356+ list (REMOVE_ITEM ARGN "${ip} " )
357+ endforeach ()
358+ list (REMOVE_ITEM ARGN "EXCLUDED_IPS" )
359+ set (ARG_EXCLUDED_IPS EXCLUDED_IPS ${ARG_EXCLUDED_IPS} )
360+ endif ()
350361
351362 # In case FILE_SETS function argument is not passed, return all file sets that were defined in IP or sub IPs
352363 # Otherwise return only files in listed in FILE_SETS argument
@@ -374,9 +385,11 @@ function(get_ip_sources OUTVAR IP_LIB LANGUAGE)
374385 if (_no_deps)
375386 set (ips ${_reallib} )
376387 else ()
377- get_ip_links (ips ${_reallib} )
388+ get_ip_links (ips ${_reallib} ${ARG_EXCLUDED_IPS} )
378389 endif ()
379390
391+ # message(STATUS "-- ${CMAKE_CURRENT_FUNCTION}: ")
392+
380393 set (asked_languges ${LANGUAGE} ${ARGN} )
381394 unset (SOURCES)
382395 # Get all the <LANGUAGE>_<FILE_SET>_SOURCES or <LANGUAGE>_<FILE_SET>_HEADERS lists in order
@@ -671,10 +684,9 @@ function(get_ip_property OUTVAR IP_LIB PROPERTY)
671684 set (OUT_LIST ${prop} )
672685 endif ()
673686 else ()
674- # Flatten the target graph to get all the dependencies in the correct order
675- flatten_graph_if_allowed (${_reallib} )
676- # Get all the dependencies
677- get_target_property (DEPS ${_reallib} FLAT_GRAPH )
687+ # Get all the IP dependencies
688+ ip_recursive_get_target_property (_linked_ips ${_reallib} INTERFACE_LINK_LIBRARIES ${ARG_EXCLUDED_IPS} )
689+ set (DEPS ${_linked_ips} ${_reallib} )
678690
679691 # Append the property of all the deps into a single list (e.g., the source files of an IP)
680692 foreach (d ${DEPS} )
@@ -812,15 +824,15 @@ function(get_ip_compile_definitions OUTVAR IP_LIB LANGUAGE)
812824endfunction ()
813825
814826#[[ [
815- # Get the IP link graph in a flat list
827+ # Get the IP link graph in a flat list, including the given IP.
816828#
817829# :param OUTVAR: Variable containing the link list.
818830# :type OUTVAR: string
819831# :keyword [NO_DEPS]: Only return the list off IPs that are immedieate childrean from the current IP
820832# :type [NO_DEPS]: bool
821833#]]
822834function (get_ip_links OUTVAR IP_LIB )
823- cmake_parse_arguments (ARG "NO_DEPS" "" "" ${ARGN} )
835+ cmake_parse_arguments (ARG "NO_DEPS" "" "EXCLUDED_IPS " ${ARGN} )
824836 if (ARG_UNPARSED_ARGUMENTS)
825837 message (FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} passed unrecognized argument " "${ARG_UNPARSED_ARGUMENTS} " )
826838 endif ()
@@ -830,12 +842,14 @@ function(get_ip_links OUTVAR IP_LIB)
830842 if (ARG_NO_DEPS)
831843 get_property (__flat_graph TARGET ${_reallib} PROPERTY INTERFACE_LINK_LIBRARIES )
832844 else ()
833- flatten_graph_if_allowed (${_reallib} )
845+ if (ARG_EXCLUDED_IPS)
846+ set (ARG_EXCLUDED_IPS EXCLUDED_IPS ${ARG_EXCLUDED_IPS} )
847+ endif ()
834848
835- get_property ( __flat_graph TARGET ${_reallib} PROPERTY FLAT_GRAPH )
849+ ip_recursive_get_target_property ( __linked_ips ${_reallib} INTERFACE_LINK_LIBRARIES ${ARG_EXCLUDED_IPS} )
836850 endif ()
837851
838- set (${OUTVAR} ${__flat_graph } PARENT_SCOPE )
852+ set (${OUTVAR} ${__linked_ips} ${_reallib } PARENT_SCOPE )
839853endfunction ()
840854
841855#[[ [
@@ -963,3 +977,65 @@ function(flatten_graph_if_allowed IP_LIB)
963977 flatten_graph (${IP_LIB} )
964978 endif ()
965979endfunction ()
980+
981+ #[[ [
982+ # This function recursively get the property PROPERTY from the target IP_LIB and
983+ # returns a list stored in OUTVAR.
984+ #
985+ # :param OUT_VAR: Variable containing the requested property.
986+ # :type OUT_VAR: string
987+ # :param IP_LIB: The target IP library name.
988+ # :type IP_LIB: string
989+ # :param PROPERTY: Property to search recursively.
990+ # :type PROPERTY: string
991+ #
992+ #]]
993+ function (ip_recursive_get_target_property OUTVAR IP_LIB PROPERTY )
994+ cmake_parse_arguments (ARG "" "" "EXCLUDED_IPS" ${ARGN} )
995+ if (ARG_UNPARSED_ARGUMENTS)
996+ message (FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} passed unrecognized argument " "${ARG_UNPARSED_ARGUMENTS} " )
997+ endif ()
998+
999+ if (ARG_EXCLUDED_IPS)
1000+ set (ARG_EXCLUDED_IPS EXCLUDED_IPS ${ARG_EXCLUDED_IPS} )
1001+ endif ()
1002+
1003+ set (_seen_values)
1004+
1005+ alias_dereference (_reallib ${IP_LIB} )
1006+
1007+ foreach (excl_ip ${ARG_EXCLUDED_IPS} )
1008+ alias_dereference (_excl_ip_reallib ${excl_ip} )
1009+ set (_excluded_ips_reallib_list ${_excluded_ips_reallib_list} ${_excl_ip_reallib} )
1010+ endforeach ()
1011+
1012+ # Get the value of the specified property for the current target
1013+ get_target_property (_current_value ${_reallib} ${PROPERTY} )
1014+
1015+ if (_current_value AND NOT _current_value STREQUAL "<${PROPERTY} >-NOTFOUND" )
1016+ # Check every entry
1017+ foreach (_subtarget ${_current_value} )
1018+ # Recursively process sub-targets if they exist
1019+ if (TARGET ${_subtarget} )
1020+ # Stop the recursive search if the IP is excluded
1021+ if (ARG_EXCLUDED_IPS AND NOT ${_subtarget} IN_LIST _excluded_ips_reallib_list)
1022+ # Add the current target to the list
1023+ list (APPEND _seen_values ${_subtarget} )
1024+ # Recusrive call to search for the property in the sub-target
1025+ ip_recursive_get_target_property (_recursive_values ${_subtarget} ${PROPERTY} ${ARG_EXCLUDED_IPS} )
1026+ # Add the recursively collected target to the list
1027+ list (APPEND _seen_values ${_recursive_values} )
1028+ # Remove duplicates keeping the first appearing instance
1029+ list (REMOVE_DUPLICATES _seen_values)
1030+ else ()
1031+ message (DEBUG "-- ${CMAKE_CURRENT_FUNCTION} : ip target ${_subtarget} is excluded from search" )
1032+ endif ()
1033+ endif ()
1034+ endforeach ()
1035+ endif ()
1036+
1037+ message (DEBUG "-- ${CMAKE_CURRENT_FUNCTION} : ${_reallib} _seen_values: ${_seen_values} " )
1038+
1039+ # Return the collected values
1040+ set (${OUTVAR} ${_seen_values} PARENT_SCOPE )
1041+ endfunction ()
0 commit comments