diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index f873769cc9..fa68e1e39f 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -183,8 +183,8 @@ cmCommonTargetGenerator::GetLinkedTargetDirectories( this->GeneratorTarget->GetLinkInformation(config)) { auto findSyntheticTarget = - [this, - &config](cmGeneratorTarget const* linkee) -> cmGeneratorTarget const* { + [this, &config, + cli](cmGeneratorTarget const* linkee) -> cmGeneratorTarget const* { if (!linkee) { return nullptr; } @@ -196,7 +196,7 @@ cmCommonTargetGenerator::GetLinkedTargetDirectories( return it->second.front(); } - // Check linked targets to finding synthetic targets for transitive deps + // Check linked targets to find synthetic targets for transitive deps std::vector pending; std::set visited; for (auto const& dep : synthDeps) { @@ -207,6 +207,19 @@ cmCommonTargetGenerator::GetLinkedTargetDirectories( } } + // Also seed the search from direct linked targets that have + // CXX20 module sources, in case they hold synthetic deps for + // transitive dependencies that we need to inherit. Skip targets + // that already have synthetic substitutes in our own synthDeps + // (their transitive deps will be explored via the substitute). + for (auto const& item : cli->GetItems()) { + if (item.Target && item.Target->HaveCxx20ModuleSources() && + synthDeps.find(item.Target) == synthDeps.end() && + visited.insert(item.Target).second) { + pending.push_back(item.Target); + } + } + while (!pending.empty()) { auto const* current = pending.back(); pending.pop_back();