@@ -223,6 +223,7 @@ def __init__(self, target: CMakeTarget, env: 'Environment', for_machine: Machine
223223 self .install = target .install
224224 self .install_dir : T .Optional [Path ] = None
225225 self .link_libraries = target .link_libraries
226+ self .link_targets : T .List [str ] = []
226227 self .link_flags = target .link_flags + target .link_lang_flags
227228 self .public_link_flags : T .List [str ] = []
228229 self .depends_raw : T .List [str ] = []
@@ -363,6 +364,8 @@ def postprocess(self, output_target_map: OutputTargetMap, root_src_dir: Path, su
363364 self .public_link_flags += rtgt .public_link_flags
364365 self .public_compile_opts += rtgt .public_compile_opts
365366 self .link_libraries += rtgt .libraries
367+ self .depends_raw += rtgt .target_dependencies
368+ self .link_targets += rtgt .target_dependencies
366369
367370 elif self .type .upper () not in ['EXECUTABLE' , 'OBJECT_LIBRARY' ]:
368371 mlog .warning ('CMake: Target' , mlog .bold (self .cmake_name ), 'not found in CMake trace. This can lead to build errors' )
@@ -957,17 +960,27 @@ def analyse(self) -> None:
957960 object_libs += [tgt ]
958961 self .languages += [x for x in tgt .languages if x not in self .languages ]
959962
960- # Second pass: Detect object library dependencies
963+ # Second pass: Populate link_with project internal targets
964+ for tgt in self .targets :
965+ for i in tgt .link_targets :
966+ # Handle target-based link libraries
967+ link_with = self .output_target_map .target (i )
968+ if not link_with or isinstance (link_with , ConverterCustomTarget ):
969+ # Generated file etc.
970+ continue
971+ tgt .link_with .append (link_with )
972+
973+ # Third pass: Detect object library dependencies
961974 for tgt in self .targets :
962975 tgt .process_object_libs (object_libs , self ._object_lib_workaround )
963976
964- # Third pass: Reassign dependencies to avoid some loops
977+ # Fourth pass: Reassign dependencies to avoid some loops
965978 for tgt in self .targets :
966979 tgt .process_inter_target_dependencies ()
967980 for ctgt in self .custom_targets :
968981 ctgt .process_inter_target_dependencies ()
969982
970- # Fourth pass: Remove rassigned dependencies
983+ # Fifth pass: Remove reassigned dependencies
971984 for tgt in self .targets :
972985 tgt .cleanup_dependencies ()
973986
0 commit comments