mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 14:20:06 -06:00
cmNinjaTargetGenerator: factor out determining the fileset of a source
This information is now needed in more than one place, so factor the logic out and use it to build a cache.
This commit is contained in:
@@ -173,6 +173,64 @@ bool cmNinjaTargetGenerator::NeedDyndep(std::string const& lang,
|
||||
return lang == "Fortran" || this->NeedCxxModuleSupport(lang, config);
|
||||
}
|
||||
|
||||
void cmNinjaTargetGenerator::BuildFileSetInfoCache(std::string const& config)
|
||||
{
|
||||
auto& per_config = this->Configs[config];
|
||||
|
||||
if (per_config.BuiltFileSetCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto const* tgt = this->GeneratorTarget->Target;
|
||||
|
||||
for (auto const& name : tgt->GetAllFileSetNames()) {
|
||||
auto const* file_set = tgt->GetFileSet(name);
|
||||
if (!file_set) {
|
||||
this->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->GeneratorTarget);
|
||||
|
||||
std::map<std::string, std::vector<std::string>> files;
|
||||
for (auto const& entry : fileEntries) {
|
||||
file_set->EvaluateFileEntry(directories, files, entry,
|
||||
this->LocalGenerator, config,
|
||||
this->GeneratorTarget);
|
||||
}
|
||||
|
||||
for (auto const& it : files) {
|
||||
for (auto const& filename : it.second) {
|
||||
per_config.FileSetCache[filename] = file_set;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
per_config.BuiltFileSetCache = true;
|
||||
}
|
||||
|
||||
cmFileSet const* cmNinjaTargetGenerator::GetFileSetForSource(
|
||||
std::string const& config, cmSourceFile const* sf)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
std::string cmNinjaTargetGenerator::OrderDependsTargetForTarget(
|
||||
const std::string& config)
|
||||
{
|
||||
@@ -256,54 +314,17 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
|
||||
flags, genexInterpreter.Evaluate(pchOptions, COMPILE_OPTIONS));
|
||||
}
|
||||
|
||||
auto const& path = source->GetFullPath();
|
||||
auto const* tgt = this->GeneratorTarget->Target;
|
||||
|
||||
std::string file_set_type;
|
||||
|
||||
for (auto const& name : tgt->GetAllFileSetNames()) {
|
||||
auto const* file_set = tgt->GetFileSet(name);
|
||||
if (!file_set) {
|
||||
auto const* fs = this->GetFileSetForSource(config, source);
|
||||
if (fs &&
|
||||
(fs->GetType() == "CXX_MODULES"_s ||
|
||||
fs->GetType() == "CXX_MODULE_HEADER_UNITS"_s)) {
|
||||
if (source->GetLanguage() != "CXX"_s) {
|
||||
this->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->GeneratorTarget);
|
||||
|
||||
std::map<std::string, std::vector<std::string>> files;
|
||||
for (auto const& entry : fileEntries) {
|
||||
file_set->EvaluateFileEntry(directories, files, entry,
|
||||
this->LocalGenerator, config,
|
||||
this->GeneratorTarget);
|
||||
}
|
||||
|
||||
for (auto const& it : files) {
|
||||
for (auto const& filename : it.second) {
|
||||
if (filename == path) {
|
||||
file_set_type = file_set->GetType();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (file_set_type == "CXX_MODULES"_s ||
|
||||
file_set_type == "CXX_MODULE_HEADER_UNITS"_s) {
|
||||
if (source->GetLanguage() != "CXX"_s) {
|
||||
this->GetMakefile()->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat(
|
||||
"Target \"", tgt->GetName(), "\" contains the source\n ", path,
|
||||
"\nin a file set of type \"", file_set_type,
|
||||
R"(" but the source is not classified as a "CXX" source.)"));
|
||||
continue;
|
||||
}
|
||||
MessageType::FATAL_ERROR,
|
||||
cmStrCat("Target \"", this->GeneratorTarget->Target->GetName(),
|
||||
"\" contains the source\n ", source->GetFullPath(),
|
||||
"\nin a file set of type \"", fs->GetType(),
|
||||
R"(" but the source is not classified as a "CXX" source.)"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,10 @@ protected:
|
||||
|
||||
cmMakefile* GetMakefile() const { return this->Makefile; }
|
||||
|
||||
void BuildFileSetInfoCache(std::string const& config);
|
||||
cmFileSet const* GetFileSetForSource(std::string const& config,
|
||||
cmSourceFile const* sf);
|
||||
|
||||
std::string LanguageCompilerRule(const std::string& lang,
|
||||
const std::string& config) const;
|
||||
std::string LanguagePreprocessAndScanRule(std::string const& lang,
|
||||
@@ -223,6 +227,8 @@ private:
|
||||
std::vector<cmCustomCommand const*> CustomCommands;
|
||||
cmNinjaDeps ExtraFiles;
|
||||
std::unique_ptr<MacOSXContentGeneratorType> MacOSXContentGenerator;
|
||||
bool BuiltFileSetCache = false;
|
||||
std::map<std::string, cmFileSet const*> FileSetCache;
|
||||
};
|
||||
|
||||
std::map<std::string, ByConfig> Configs;
|
||||
|
||||
Reference in New Issue
Block a user