ENH: In cmSourceFile::GetLanguage use the file extension (if not ambiguous) to determine the language without requiring the source file to exist.
This commit is contained in:
parent
19aafdb355
commit
3344ce9197
@ -46,10 +46,28 @@ std::string const& cmSourceFile::GetExtension() const
|
|||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
const char* cmSourceFile::GetLanguage()
|
const char* cmSourceFile::GetLanguage()
|
||||||
{
|
{
|
||||||
// Compute the final location of the file if necessary.
|
// If the language was set explicitly by the user then use it.
|
||||||
if(this->FullPath.empty())
|
if(const char* lang = this->GetProperty("LANGUAGE"))
|
||||||
{
|
{
|
||||||
this->GetFullPath();
|
return lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform computation needed to get the language if necessary.
|
||||||
|
if(this->FullPath.empty() && this->Language.empty())
|
||||||
|
{
|
||||||
|
if(this->Location.ExtensionIsAmbiguous())
|
||||||
|
{
|
||||||
|
// Finalize the file location to get the extension and set the
|
||||||
|
// language.
|
||||||
|
this->GetFullPath();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Use the known extension to get the language if possible.
|
||||||
|
std::string ext =
|
||||||
|
cmSystemTools::GetFilenameLastExtension(this->Location.GetName());
|
||||||
|
this->CheckLanguage(ext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now try to determine the language.
|
// Now try to determine the language.
|
||||||
@ -252,8 +270,19 @@ void cmSourceFile::CheckExtension()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to identify the source file language from the extension.
|
// Try to identify the source file language from the extension.
|
||||||
|
if(this->Language.empty())
|
||||||
|
{
|
||||||
|
this->CheckLanguage(this->Extension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void cmSourceFile::CheckLanguage(std::string const& ext)
|
||||||
|
{
|
||||||
|
// Try to identify the source file language from the extension.
|
||||||
|
cmMakefile* mf = this->Location.GetMakefile();
|
||||||
cmGlobalGenerator* gg = mf->GetLocalGenerator()->GetGlobalGenerator();
|
cmGlobalGenerator* gg = mf->GetLocalGenerator()->GetGlobalGenerator();
|
||||||
if(const char* l = gg->GetLanguageFromExtension(this->Extension.c_str()))
|
if(const char* l = gg->GetLanguageFromExtension(ext.c_str()))
|
||||||
{
|
{
|
||||||
this->Language = l;
|
this->Language = l;
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,7 @@ private:
|
|||||||
bool FindFullPath();
|
bool FindFullPath();
|
||||||
bool TryFullPath(const char* tryPath, const char* ext);
|
bool TryFullPath(const char* tryPath, const char* ext);
|
||||||
void CheckExtension();
|
void CheckExtension();
|
||||||
|
void CheckLanguage(std::string const& ext);
|
||||||
|
|
||||||
std::vector<std::string> Depends;
|
std::vector<std::string> Depends;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user