cmGlobalGenerator: Change parameter to string_view

This commit is contained in:
John Franklin Rickard
2026-02-06 12:27:12 -05:00
committed by Brad King
parent d979f3df74
commit c3c3b10d60
7 changed files with 16 additions and 16 deletions
+1 -1
View File
@@ -575,7 +575,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
for (auto const& source : sources) {
auto const& si = source.first;
std::string ext = cmSystemTools::GetFilenameLastExtension(si);
std::string lang = gg->GetLanguageFromExtension(ext.c_str());
std::string lang = gg->GetLanguageFromExtension(ext);
if (!lang.empty()) {
testLangs.insert(lang);
} else {
+8 -7
View File
@@ -1100,17 +1100,18 @@ std::string cmGlobalGenerator::GetLanguageOutputExtension(
return "";
}
std::string cmGlobalGenerator::GetLanguageFromExtension(char const* ext) const
std::string cmGlobalGenerator::GetLanguageFromExtension(
cm::string_view ext) const
{
// if there is an extension and it starts with . then move past the
// . because the extensions are not stored with a . in the map
if (!ext) {
if (ext.empty()) {
return "";
}
if (*ext == '.') {
++ext;
if (ext.front() == '.') {
ext = ext.substr(1);
}
auto const it = this->ExtensionToLanguage.find(ext);
auto const it = this->ExtensionToLanguage.find(std::string(ext));
if (it != this->ExtensionToLanguage.end()) {
return it->second;
}
@@ -1239,12 +1240,12 @@ std::string cmGlobalGenerator::GetSafeGlobalSetting(
return this->Makefiles[0]->GetDefinition(name);
}
bool cmGlobalGenerator::IgnoreFile(char const* ext) const
bool cmGlobalGenerator::IgnoreFile(cm::string_view ext) const
{
if (!this->GetLanguageFromExtension(ext).empty()) {
return false;
}
return (this->IgnoreExtensions.count(ext) > 0);
return (this->IgnoreExtensions.count(std::string(ext)) > 0);
}
bool cmGlobalGenerator::GetLanguageEnabled(std::string const& l) const
+2 -2
View File
@@ -359,9 +359,9 @@ public:
bool GetToolSupportsColor() const { return this->ToolSupportsColor; }
//! return the language for the given extension
std::string GetLanguageFromExtension(char const* ext) const;
std::string GetLanguageFromExtension(cm::string_view ext) const;
//! is an extension to be ignored
bool IgnoreFile(char const* ext) const;
bool IgnoreFile(cm::string_view ext) const;
//! What is the preference for linkers and this language (None or Preferred)
int GetLinkerPreference(std::string const& lang) const;
//! What is the object file extension for a given source file?
+1 -1
View File
@@ -1487,7 +1487,7 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
cmLVS7GFileConfig fc;
std::string lang =
lg->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
lg->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension());
std::string const& sourceLang = lg->GetSourceFileLanguage(sf);
bool needForceLang = false;
// source file does not match its extension language
+1 -1
View File
@@ -287,7 +287,7 @@ void cmSourceFile::CheckLanguage(std::string const& ext)
// Try to identify the source file language from the extension.
cmMakefile const* mf = this->Location.GetMakefile();
cmGlobalGenerator* gg = mf->GetGlobalGenerator();
std::string l = gg->GetLanguageFromExtension(ext.c_str());
std::string l = gg->GetLanguageFromExtension(ext);
if (!l.empty()) {
this->Language = l;
}
+1 -1
View File
@@ -112,7 +112,7 @@ void cmSourceFileLocation::UpdateExtension(std::string const& name)
cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
cmMakefile const* mf = this->Makefile;
auto* cm = mf->GetCMakeInstance();
if (!gg->GetLanguageFromExtension(ext.c_str()).empty() ||
if (!gg->GetLanguageFromExtension(ext).empty() ||
cm->IsAKnownExtension(ext)) {
// This is a known extension. Use the given filename with extension.
this->Name = cmSystemTools::GetFilenameName(name);
+2 -3
View File
@@ -2835,9 +2835,8 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
// Force language if the file extension does not match.
// Note that MSVC treats the upper-case '.C' extension as C and not C++.
std::string const ext = sf.GetExtension();
std::string const extLang = ext == "C"_s
? "C"
: this->GlobalGenerator->GetLanguageFromExtension(ext.c_str());
std::string const extLang =
ext == "C"_s ? "C" : this->GlobalGenerator->GetLanguageFromExtension(ext);
std::string lang = this->LocalGenerator->GetSourceFileLanguage(sf);
char const* compileAs = nullptr;
if (lang != extLang) {