summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2022-11-23 17:28:40 -0500
committerBen Boeckel <ben.boeckel@kitware.com>2022-11-23 18:52:36 -0500
commite37ff5694c043507f133dc774dc8eeaeb923c56b (patch)
tree62cba34fb63634c635730d40ff862f12ba87d7c0
parent9e61fc3d6d71ebb1935fde39b011bf8167bd40d1 (diff)
downloadcmake-e37ff5694c043507f133dc774dc8eeaeb923c56b.tar.gz
cmGeneratorTarget: factor out fileset info and scanning detection
-rw-r--r--Source/cmGeneratorTarget.cxx82
-rw-r--r--Source/cmGeneratorTarget.h14
-rw-r--r--Source/cmNinjaTargetGenerator.cxx89
-rw-r--r--Source/cmNinjaTargetGenerator.h9
4 files changed, 99 insertions, 95 deletions
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<std::string, std::vector<std::string>> 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;
+}
diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h
index 858be3681d..96eda2c225 100644
--- a/Source/cmGeneratorTarget.h
+++ b/Source/cmGeneratorTarget.h
@@ -26,6 +26,7 @@
enum class cmBuildStep;
class cmComputeLinkInformation;
class cmCustomCommand;
+class cmFileSet;
class cmGlobalGenerator;
class cmLocalGenerator;
class cmMakefile;
@@ -1233,4 +1234,17 @@ public:
bool NeedCxxModuleSupport(std::string const& lang,
std::string const& config) const;
bool NeedDyndep(std::string const& lang, std::string const& config) const;
+ cmFileSet const* GetFileSetForSource(std::string const& config,
+ cmSourceFile const* sf) const;
+ bool NeedDyndepForSource(std::string const& lang, std::string const& config,
+ cmSourceFile const* sf) const;
+
+private:
+ void BuildFileSetInfoCache(std::string const& config) const;
+ struct InfoByConfig
+ {
+ bool BuiltFileSetCache = false;
+ std::map<std::string, cmFileSet const*> FileSetCache;
+ };
+ mutable std::map<std::string, InfoByConfig> Configs;
};
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 68757b860d..095bf4094b 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -157,90 +157,6 @@ std::string cmNinjaTargetGenerator::LanguageDyndepRule(
'_', 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;
-}
-
-bool cmNinjaTargetGenerator::NeedDyndepForSource(std::string const& lang,
- std::string const& config,
- cmSourceFile const* sf)
-{
- bool const needDyndep = this->GetGeneratorTarget()->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->GeneratorTarget->GetProperty("CXX_SCAN_FOR_MODULES");
- if (tgtProp.IsSet()) {
- return tgtProp.IsOn();
- }
- return true;
-}
-
std::string cmNinjaTargetGenerator::OrderDependsTargetForTarget(
const std::string& config)
{
@@ -324,7 +240,7 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
flags, genexInterpreter.Evaluate(pchOptions, COMPILE_OPTIONS));
}
- auto const* fs = this->GetFileSetForSource(config, source);
+ auto const* fs = this->GeneratorTarget->GetFileSetForSource(config, source);
if (fs &&
(fs->GetType() == "CXX_MODULES"_s ||
fs->GetType() == "CXX_MODULE_HEADER_UNITS"_s)) {
@@ -1370,7 +1286,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
!(language == "RC" || (language == "CUDA" && !flag));
int const commandLineLengthLimit =
((lang_supports_response && this->ForceResponseFile())) ? -1 : 0;
- bool const needDyndep = this->NeedDyndepForSource(language, config, source);
+ bool const needDyndep =
+ this->GeneratorTarget->NeedDyndepForSource(language, config, source);
cmNinjaBuild objBuild(this->LanguageCompilerRule(
language, config, needDyndep ? WithScanning::Yes : WithScanning::No));
diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h
index 04d6bd7739..b5abb362a9 100644
--- a/Source/cmNinjaTargetGenerator.h
+++ b/Source/cmNinjaTargetGenerator.h
@@ -19,7 +19,6 @@
#include "cmOSXBundleGenerator.h"
class cmCustomCommand;
-class cmFileSet;
class cmGeneratedFileStream;
class cmGeneratorTarget;
class cmLocalNinjaGenerator;
@@ -64,10 +63,6 @@ protected:
cmMakefile* GetMakefile() const { return this->Makefile; }
- void BuildFileSetInfoCache(std::string const& config);
- cmFileSet const* GetFileSetForSource(std::string const& config,
- cmSourceFile const* sf);
-
enum class WithScanning
{
No,
@@ -82,8 +77,6 @@ protected:
const std::string& config) const;
std::string LanguageDyndepRule(std::string const& lang,
const std::string& config) const;
- bool NeedDyndepForSource(std::string const& lang, std::string const& config,
- cmSourceFile const* sf);
bool NeedExplicitPreprocessing(std::string const& lang) const;
bool CompileWithDefines(std::string const& lang) const;
@@ -235,8 +228,6 @@ 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;