summaryrefslogtreecommitdiffstats
path: root/Source/cmNinjaTargetGenerator.cxx
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2022-11-17 20:25:23 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2022-11-17 20:26:55 (GMT)
commit008c09d6db60f7c24781b47414ffa26edbd0e22d (patch)
treec446897cffe32476948648bb66bb17bd1fd382b1 /Source/cmNinjaTargetGenerator.cxx
parentc5a945dce8e1a4fb1b1db91c2dae03795c74074b (diff)
downloadCMake-008c09d6db60f7c24781b47414ffa26edbd0e22d.zip
CMake-008c09d6db60f7c24781b47414ffa26edbd0e22d.tar.gz
CMake-008c09d6db60f7c24781b47414ffa26edbd0e22d.tar.bz2
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.
Diffstat (limited to 'Source/cmNinjaTargetGenerator.cxx')
-rw-r--r--Source/cmNinjaTargetGenerator.cxx115
1 files changed, 68 insertions, 47 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index fba0ff9..ce73c17 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -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.)"));
}
}