cmGeneratorTarget: factor out fileset info and scanning detection

This commit is contained in:
Ben Boeckel
2022-11-23 17:28:40 -05:00
parent 9e61fc3d6d
commit e37ff5694c
4 changed files with 99 additions and 95 deletions

View File

@@ -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;
}

View File

@@ -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;
};

View File

@@ -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));

View File

@@ -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;