From e37ff5694c043507f133dc774dc8eeaeb923c56b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 23 Nov 2022 17:28:40 -0500 Subject: cmGeneratorTarget: factor out fileset info and scanning detection --- Source/cmGeneratorTarget.cxx | 82 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'Source/cmGeneratorTarget.cxx') diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index bf0aa8ec6f..27e31d4d54 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -8885,3 +8885,85 @@ bool cmGeneratorTarget::NeedDyndep(std::string const& lang, { return lang == "Fortran"_s || this->NeedCxxModuleSupport(lang, config); } + +cmFileSet const* cmGeneratorTarget::GetFileSetForSource( + std::string const& config, cmSourceFile const* sf) const +{ + this->BuildFileSetInfoCache(config); + + auto const& path = sf->GetFullPath(); + auto const& per_config = this->Configs[config]; + + auto const fsit = per_config.FileSetCache.find(path); + if (fsit == per_config.FileSetCache.end()) { + return nullptr; + } + return fsit->second; +} + +bool cmGeneratorTarget::NeedDyndepForSource(std::string const& lang, + std::string const& config, + cmSourceFile const* sf) const +{ + bool const needDyndep = this->NeedDyndep(lang, config); + if (!needDyndep) { + return false; + } + auto const* fs = this->GetFileSetForSource(config, sf); + if (fs && + (fs->GetType() == "CXX_MODULES"_s || + fs->GetType() == "CXX_MODULE_HEADER_UNITS"_s)) { + return true; + } + auto const sfProp = sf->GetProperty("CXX_SCAN_FOR_MODULES"); + if (sfProp.IsSet()) { + return sfProp.IsOn(); + } + auto const tgtProp = this->GetProperty("CXX_SCAN_FOR_MODULES"); + if (tgtProp.IsSet()) { + return tgtProp.IsOn(); + } + return true; +} + +void cmGeneratorTarget::BuildFileSetInfoCache(std::string const& config) const +{ + auto& per_config = this->Configs[config]; + + if (per_config.BuiltFileSetCache) { + return; + } + + auto const* tgt = this->Target; + + for (auto const& name : tgt->GetAllFileSetNames()) { + auto const* file_set = tgt->GetFileSet(name); + if (!file_set) { + tgt->GetMakefile()->IssueMessage( + MessageType::INTERNAL_ERROR, + cmStrCat("Target \"", tgt->GetName(), + "\" is tracked to have file set \"", name, + "\", but it was not found.")); + continue; + } + + auto fileEntries = file_set->CompileFileEntries(); + auto directoryEntries = file_set->CompileDirectoryEntries(); + auto directories = file_set->EvaluateDirectoryEntries( + directoryEntries, this->LocalGenerator, config, this); + + std::map> files; + for (auto const& entry : fileEntries) { + file_set->EvaluateFileEntry(directories, files, entry, + this->LocalGenerator, config, this); + } + + for (auto const& it : files) { + for (auto const& filename : it.second) { + per_config.FileSetCache[filename] = file_set; + } + } + } + + per_config.BuiltFileSetCache = true; +} -- cgit v1.2.1