stringapi: Use strings for the languages

This commit is contained in:
Ben Boeckel 2014-02-03 21:20:56 -05:00 committed by Brad King
parent 83a5e453f8
commit ce5114354c
44 changed files with 246 additions and 253 deletions

View File

@ -268,7 +268,7 @@ cmComputeLinkInformation
// Get the language used for linking this target. // Get the language used for linking this target.
this->LinkLanguage = this->Target->GetLinkerLanguage(config, headTarget); this->LinkLanguage = this->Target->GetLinkerLanguage(config, headTarget);
if(!this->LinkLanguage) if(this->LinkLanguage.empty())
{ {
// The Compute method will do nothing, so skip the rest of the // The Compute method will do nothing, so skip the rest of the
// initialization. // initialization.
@ -496,7 +496,7 @@ bool cmComputeLinkInformation::Compute()
} }
// We require a link language for the target. // We require a link language for the target.
if(!this->LinkLanguage) if(this->LinkLanguage.empty())
{ {
cmSystemTools:: cmSystemTools::
Error("CMake can not determine linker language for target: ", Error("CMake can not determine linker language for target: ",

View File

@ -50,7 +50,7 @@ public:
std::vector<std::string> const& GetDirectories(); std::vector<std::string> const& GetDirectories();
std::vector<std::string> const& GetDepends(); std::vector<std::string> const& GetDepends();
std::vector<std::string> const& GetFrameworkPaths(); std::vector<std::string> const& GetFrameworkPaths();
const char* GetLinkLanguage() const { return this->LinkLanguage; } std::string GetLinkLanguage() const { return this->LinkLanguage; }
std::vector<std::string> const& GetRuntimeSearchPath(); std::vector<std::string> const& GetRuntimeSearchPath();
std::string const& GetRuntimeFlag() const { return this->RuntimeFlag; } std::string const& GetRuntimeFlag() const { return this->RuntimeFlag; }
std::string const& GetRuntimeSep() const { return this->RuntimeSep; } std::string const& GetRuntimeSep() const { return this->RuntimeSep; }
@ -83,7 +83,7 @@ private:
// Configuration information. // Configuration information.
const char* Config; const char* Config;
const char* LinkLanguage; std::string LinkLanguage;
bool LinkDependsNoShared; bool LinkDependsNoShared;
// Modes for dealing with dependent shared libraries. // Modes for dealing with dependent shared libraries.

View File

@ -249,7 +249,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
si != sources.end(); ++si) si != sources.end(); ++si)
{ {
std::string ext = cmSystemTools::GetFilenameLastExtension(*si); std::string ext = cmSystemTools::GetFilenameLastExtension(*si);
if(const char* lang = gg->GetLanguageFromExtension(ext.c_str())) std::string lang = gg->GetLanguageFromExtension(ext.c_str());
if(!lang.empty())
{ {
testLangs.insert(lang); testLangs.insert(lang);
} }

View File

@ -297,7 +297,7 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends,
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmDepends::SetIncludePathFromLanguage(const char* lang) void cmDepends::SetIncludePathFromLanguage(const std::string& lang)
{ {
// Look for the new per "TARGET_" variant first: // Look for the new per "TARGET_" variant first:
const char * includePath = 0; const char * includePath = 0;

View File

@ -41,7 +41,7 @@ public:
void SetLocalGenerator(cmLocalGenerator* lg) { this->LocalGenerator = lg; } void SetLocalGenerator(cmLocalGenerator* lg) { this->LocalGenerator = lg; }
/** Set the specific language to be scanned. */ /** Set the specific language to be scanned. */
void SetLanguage(const char* lang) { this->Language = lang; } void SetLanguage(const std::string& lang) { this->Language = lang; }
/** Set the target build directory. */ /** Set the target build directory. */
void SetTargetDirectory(const char* dir) { this->TargetDirectory = dir; } void SetTargetDirectory(const char* dir) { this->TargetDirectory = dir; }
@ -114,7 +114,7 @@ protected:
// The include file search path. // The include file search path.
std::vector<std::string> IncludePath; std::vector<std::string> IncludePath;
void SetIncludePathFromLanguage(const char* lang); void SetIncludePathFromLanguage(const std::string& lang);
private: private:
cmDepends(cmDepends const&); // Purposely not implemented. cmDepends(cmDepends const&); // Purposely not implemented.

View File

@ -37,7 +37,7 @@ cmDependsC::cmDependsC()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmDependsC::cmDependsC(cmLocalGenerator* lg, cmDependsC::cmDependsC(cmLocalGenerator* lg,
const char* targetDir, const char* targetDir,
const char* lang, const std::string& lang,
const std::map<std::string, DependencyVector>* validDeps) const std::map<std::string, DependencyVector>* validDeps)
: cmDepends(lg, targetDir) : cmDepends(lg, targetDir)
, ValidDeps(validDeps) , ValidDeps(validDeps)

View File

@ -25,7 +25,8 @@ public:
/** Checking instances need to know the build directory name and the /** Checking instances need to know the build directory name and the
relative path from the build directory to the target file. */ relative path from the build directory to the target file. */
cmDependsC(); cmDependsC();
cmDependsC(cmLocalGenerator* lg, const char* targetDir, const char* lang, cmDependsC(cmLocalGenerator* lg, const char* targetDir,
const std::string& lang,
const std::map<std::string, DependencyVector>* validDeps); const std::map<std::string, DependencyVector>* validDeps);
/** Virtual destructor to cleanup subclasses properly. */ /** Virtual destructor to cleanup subclasses properly. */

View File

@ -411,7 +411,8 @@ void cmExtraCodeBlocksGenerator
// check whether it is a C/C++ implementation file // check whether it is a C/C++ implementation file
bool isCFile = false; bool isCFile = false;
if ((*si)->GetLanguage() && (*(*si)->GetLanguage() == 'C')) std::string lang = (*si)->GetLanguage();
if (lang == "C" || lang == "CXX")
{ {
for(std::vector<std::string>::const_iterator for(std::vector<std::string>::const_iterator
ext = mf->GetSourceExtensions().begin(); ext = mf->GetSourceExtensions().begin();

View File

@ -220,7 +220,8 @@ void cmExtraCodeLiteGenerator
{ {
// check whether it is a C/C++ implementation file // check whether it is a C/C++ implementation file
bool isCFile = false; bool isCFile = false;
if ((*si)->GetLanguage() && (*(*si)->GetLanguage() == 'C')) std::string lang = (*si)->GetLanguage();
if (lang == "C" || lang == "CXX")
{ {
for(std::vector<std::string>::const_iterator for(std::vector<std::string>::const_iterator
ext = mf->GetSourceExtensions().begin(); ext = mf->GetSourceExtensions().begin();

View File

@ -369,8 +369,8 @@ cmExtraSublimeTextGenerator::ComputeFlagsForObject(cmSourceFile* source,
std::string flags; std::string flags;
cmMakefile *makefile = lg->GetMakefile(); cmMakefile *makefile = lg->GetMakefile();
const char* language = source->GetLanguage(); std::string language = source->GetLanguage();
if (language == NULL) if (language.empty())
{ {
language = "C"; language = "C";
} }
@ -423,11 +423,7 @@ ComputeDefines(cmSourceFile *source, cmLocalGenerator* lg, cmTarget *target,
{ {
std::set<std::string> defines; std::set<std::string> defines;
cmMakefile *makefile = lg->GetMakefile(); cmMakefile *makefile = lg->GetMakefile();
const char* language = source->GetLanguage(); const std::string& language = source->GetLanguage();
if (language == NULL)
{
language = "";
}
const char* config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); const char* config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
// Add the export symbol definition for shared library objects. // Add the export symbol definition for shared library objects.

View File

@ -990,8 +990,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
"link libraries for a static library"); "link libraries for a static library");
return std::string(); return std::string();
} }
const char *lang = target->GetLinkerLanguage(context->Config); return target->GetLinkerLanguage(context->Config);
return lang ? lang : "";
} }
cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace, cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace,

View File

@ -168,7 +168,7 @@ struct TagVisitor
this->BadObjLibFiles.push_back(sf); this->BadObjLibFiles.push_back(sf);
} }
} }
else if(sf->GetLanguage()) else if(!sf->GetLanguage().empty())
{ {
DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf); DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf);
} }

View File

@ -35,7 +35,7 @@ bool cmGetSourceFilePropertyCommand
{ {
if(args[2] == "LANGUAGE") if(args[2] == "LANGUAGE")
{ {
this->Makefile->AddDefinition(var, sf->GetLanguage()); this->Makefile->AddDefinition(var, sf->GetLanguage().c_str());
return true; return true;
} }
const char *prop = sf->GetPropertyForUser(args[2].c_str()); const char *prop = sf->GetPropertyForUser(args[2].c_str());

View File

@ -722,7 +722,7 @@ cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGlobalGenerator::PrintCompilerAdvice(std::ostream& os, void cmGlobalGenerator::PrintCompilerAdvice(std::ostream& os,
std::string lang, std::string const& lang,
const char* envVar) const const char* envVar) const
{ {
// Subclasses override this method if they do not support this advice. // Subclasses override this method if they do not support this advice.
@ -744,7 +744,7 @@ void cmGlobalGenerator::PrintCompilerAdvice(std::ostream& os,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGlobalGenerator::CheckCompilerIdCompatibility(cmMakefile* mf, void cmGlobalGenerator::CheckCompilerIdCompatibility(cmMakefile* mf,
std::string lang) const std::string const& lang) const
{ {
std::string compilerIdVar = "CMAKE_" + lang + "_COMPILER_ID"; std::string compilerIdVar = "CMAKE_" + lang + "_COMPILER_ID";
const char* compilerId = mf->GetDefinition(compilerIdVar.c_str()); const char* compilerId = mf->GetDefinition(compilerIdVar.c_str());
@ -817,17 +817,18 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility(cmMakefile* mf,
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const char* std::string
cmGlobalGenerator::GetLanguageOutputExtension(cmSourceFile const& source) const cmGlobalGenerator::GetLanguageOutputExtension(cmSourceFile const& source) const
{ {
if(const char* lang = source.GetLanguage()) const std::string& lang = source.GetLanguage();
if(!lang.empty())
{ {
std::map<cmStdString, cmStdString>::const_iterator it = std::map<cmStdString, cmStdString>::const_iterator it =
this->LanguageToOutputExtension.find(lang); this->LanguageToOutputExtension.find(lang);
if(it != this->LanguageToOutputExtension.end()) if(it != this->LanguageToOutputExtension.end())
{ {
return it->second.c_str(); return it->second;
} }
} }
else else
@ -840,7 +841,7 @@ cmGlobalGenerator::GetLanguageOutputExtension(cmSourceFile const& source) const
{ {
if(this->OutputExtensions.count(ext)) if(this->OutputExtensions.count(ext))
{ {
return ext.c_str(); return ext;
} }
} }
} }
@ -848,7 +849,7 @@ cmGlobalGenerator::GetLanguageOutputExtension(cmSourceFile const& source) const
} }
const char* cmGlobalGenerator::GetLanguageFromExtension(const char* ext) const std::string cmGlobalGenerator::GetLanguageFromExtension(const char* ext) const
{ {
// if there is an extension and it starts with . then move past the // if there is an extension and it starts with . then move past the
// . because the extensions are not stored with a . in the map // . because the extensions are not stored with a . in the map
@ -860,9 +861,9 @@ const char* cmGlobalGenerator::GetLanguageFromExtension(const char* ext) const
= this->ExtensionToLanguage.find(ext); = this->ExtensionToLanguage.find(ext);
if(it != this->ExtensionToLanguage.end()) if(it != this->ExtensionToLanguage.end())
{ {
return it->second.c_str(); return it->second;
} }
return 0; return "";
} }
/* SetLanguageEnabled() is now split in two parts: /* SetLanguageEnabled() is now split in two parts:
@ -877,13 +878,15 @@ files could change the object file extension
(CMAKE_<LANG>_OUTPUT_EXTENSION) before the CMake variables were copied (CMAKE_<LANG>_OUTPUT_EXTENSION) before the CMake variables were copied
to the C++ maps. to the C++ maps.
*/ */
void cmGlobalGenerator::SetLanguageEnabled(const char* l, cmMakefile* mf) void cmGlobalGenerator::SetLanguageEnabled(const std::string& l,
cmMakefile* mf)
{ {
this->SetLanguageEnabledFlag(l, mf); this->SetLanguageEnabledFlag(l, mf);
this->SetLanguageEnabledMaps(l, mf); this->SetLanguageEnabledMaps(l, mf);
} }
void cmGlobalGenerator::SetLanguageEnabledFlag(const char* l, cmMakefile* mf) void cmGlobalGenerator::SetLanguageEnabledFlag(const std::string& l,
cmMakefile* mf)
{ {
this->LanguageEnabled[l] = true; this->LanguageEnabled[l] = true;
@ -895,7 +898,8 @@ void cmGlobalGenerator::SetLanguageEnabledFlag(const char* l, cmMakefile* mf)
this->FillExtensionToLanguageMap(l, mf); this->FillExtensionToLanguageMap(l, mf);
} }
void cmGlobalGenerator::SetLanguageEnabledMaps(const char* l, cmMakefile* mf) void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
cmMakefile* mf)
{ {
// use LanguageToLinkerPreference to detect whether this functions has // use LanguageToLinkerPreference to detect whether this functions has
// run before // run before
@ -969,7 +973,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const char* l, cmMakefile* mf)
} }
void cmGlobalGenerator::FillExtensionToLanguageMap(const char* l, void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l,
cmMakefile* mf) cmMakefile* mf)
{ {
std::string extensionsVar = std::string("CMAKE_") + std::string extensionsVar = std::string("CMAKE_") +
@ -986,14 +990,14 @@ void cmGlobalGenerator::FillExtensionToLanguageMap(const char* l,
bool cmGlobalGenerator::IgnoreFile(const char* l) const bool cmGlobalGenerator::IgnoreFile(const char* l) const
{ {
if(this->GetLanguageFromExtension(l)) if(!this->GetLanguageFromExtension(l).empty())
{ {
return false; return false;
} }
return (this->IgnoreExtensions.count(l) > 0); return (this->IgnoreExtensions.count(l) > 0);
} }
bool cmGlobalGenerator::GetLanguageEnabled(const char* l) const bool cmGlobalGenerator::GetLanguageEnabled(const std::string& l) const
{ {
return (this->LanguageEnabled.find(l)!= this->LanguageEnabled.end()); return (this->LanguageEnabled.find(l)!= this->LanguageEnabled.end());
} }
@ -1958,7 +1962,7 @@ cmGlobalGenerator::GetEnabledLanguages(std::vector<std::string>& lang) const
} }
} }
int cmGlobalGenerator::GetLinkerPreference(const char* lang) const int cmGlobalGenerator::GetLinkerPreference(const std::string& lang) const
{ {
std::map<cmStdString, int>::const_iterator it = std::map<cmStdString, int>::const_iterator it =
this->LanguageToLinkerPreference.find(lang); this->LanguageToLinkerPreference.find(lang);

View File

@ -77,8 +77,8 @@ public:
/** /**
* Set/Get and Clear the enabled languages. * Set/Get and Clear the enabled languages.
*/ */
void SetLanguageEnabled(const char*, cmMakefile* mf); void SetLanguageEnabled(const std::string&, cmMakefile* mf);
bool GetLanguageEnabled(const char*) const; bool GetLanguageEnabled(const std::string&) const;
void ClearEnabledLanguages(); void ClearEnabledLanguages();
void GetEnabledLanguages(std::vector<std::string>& lang) const; void GetEnabledLanguages(std::vector<std::string>& lang) const;
/** /**
@ -182,13 +182,13 @@ public:
bool GetToolSupportsColor() const { return this->ToolSupportsColor; } bool GetToolSupportsColor() const { return this->ToolSupportsColor; }
///! return the language for the given extension ///! return the language for the given extension
const char* GetLanguageFromExtension(const char* ext) const; std::string GetLanguageFromExtension(const char* ext) const;
///! is an extension to be ignored ///! is an extension to be ignored
bool IgnoreFile(const char* ext) const; bool IgnoreFile(const char* ext) const;
///! What is the preference for linkers and this language (None or Prefered) ///! What is the preference for linkers and this language (None or Prefered)
int GetLinkerPreference(const char* lang) const; int GetLinkerPreference(const std::string& lang) const;
///! What is the object file extension for a given source file? ///! What is the object file extension for a given source file?
const char* GetLanguageOutputExtension(cmSourceFile const&) const; std::string GetLanguageOutputExtension(cmSourceFile const&) const;
///! What is the configurations directory variable called? ///! What is the configurations directory variable called?
virtual const char* GetCMakeCFGIntDir() const { return "."; } virtual const char* GetCMakeCFGIntDir() const { return "."; }
@ -332,9 +332,9 @@ protected:
bool IsRootOnlyTarget(cmTarget* target) const; bool IsRootOnlyTarget(cmTarget* target) const;
void AddTargetDepends(cmTarget const* target, void AddTargetDepends(cmTarget const* target,
TargetDependSet& projectTargets); TargetDependSet& projectTargets);
void SetLanguageEnabledFlag(const char* l, cmMakefile* mf); void SetLanguageEnabledFlag(const std::string& l, cmMakefile* mf);
void SetLanguageEnabledMaps(const char* l, cmMakefile* mf); void SetLanguageEnabledMaps(const std::string& l, cmMakefile* mf);
void FillExtensionToLanguageMap(const char* l, cmMakefile* mf); void FillExtensionToLanguageMap(const std::string& l, cmMakefile* mf);
virtual bool ComputeTargetDepends(); virtual bool ComputeTargetDepends();
@ -420,9 +420,10 @@ private:
void WriteSummary(cmTarget* target); void WriteSummary(cmTarget* target);
void FinalizeTargetCompileInfo(); void FinalizeTargetCompileInfo();
virtual void PrintCompilerAdvice(std::ostream& os, std::string lang, virtual void PrintCompilerAdvice(std::ostream& os, std::string const& lang,
const char* envVar) const; const char* envVar) const;
void CheckCompilerIdCompatibility(cmMakefile* mf, std::string lang) const; void CheckCompilerIdCompatibility(cmMakefile* mf,
std::string const& lang) const;
cmExternalMakefileProjectGenerator* ExtraGenerator; cmExternalMakefileProjectGenerator* ExtraGenerator;

View File

@ -114,7 +114,8 @@ protected:
private: private:
virtual std::string GetVSMakeProgram() = 0; virtual std::string GetVSMakeProgram() = 0;
void PrintCompilerAdvice(std::ostream&, std::string, const char*) const {} void PrintCompilerAdvice(std::ostream&, std::string const&,
const char*) const {}
void ComputeTargetObjects(cmGeneratorTarget* gt) const; void ComputeTargetObjects(cmGeneratorTarget* gt) const;
void FollowLinkDepends(cmTarget const* target, void FollowLinkDepends(cmTarget const* target,

View File

@ -696,12 +696,8 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
flags += flagsBuild.GetString(); flags += flagsBuild.GetString();
} }
const char* lang = std::string lang =
this->CurrentLocalGenerator->GetSourceFileLanguage(*sf); this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
if (!lang)
{
lang = "";
}
cmXCodeObject* buildFile = cmXCodeObject* buildFile =
this->CreateXCodeSourceFileFromPath(sf->GetFullPath(), cmtarget, lang); this->CreateXCodeSourceFileFromPath(sf->GetFullPath(), cmtarget, lang);
@ -906,12 +902,8 @@ cmXCodeObject*
cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf, cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf,
cmTarget& cmtarget) cmTarget& cmtarget)
{ {
const char* lang = std::string lang =
this->CurrentLocalGenerator->GetSourceFileLanguage(*sf); this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
if (!lang)
{
lang = "";
}
return this->CreateXCodeFileReferenceFromPath( return this->CreateXCodeFileReferenceFromPath(
sf->GetFullPath(), cmtarget, lang); sf->GetFullPath(), cmtarget, lang);
@ -1036,7 +1028,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
// Include this file in the build if it has a known language // Include this file in the build if it has a known language
// and has not been listed as an ignored extension for this // and has not been listed as an ignored extension for this
// generator. // generator.
if(this->CurrentLocalGenerator->GetSourceFileLanguage(**i) && if(!this->CurrentLocalGenerator->GetSourceFileLanguage(**i).empty() &&
!this->IgnoreFile((*i)->GetExtension().c_str())) !this->IgnoreFile((*i)->GetExtension().c_str()))
{ {
sourceFiles.push_back(xsf); sourceFiles.push_back(xsf);
@ -1241,8 +1233,8 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget)
return; return;
} }
const char* llang = cmtarget.GetLinkerLanguage("NOCONFIG"); std::string llang = cmtarget.GetLinkerLanguage("NOCONFIG");
if(!llang) { return; } if(llang.empty()) { return; }
// If the language is compiled as a source trust Xcode to link with it. // If the language is compiled as a source trust Xcode to link with it.
cmTarget::LinkImplementation const* impl = cmTarget::LinkImplementation const* impl =
@ -1270,7 +1262,7 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget)
} }
if(cmSourceFile* sf = mf->GetOrCreateSource(fname.c_str())) if(cmSourceFile* sf = mf->GetOrCreateSource(fname.c_str()))
{ {
sf->SetProperty("LANGUAGE", llang); sf->SetProperty("LANGUAGE", llang.c_str());
cmtarget.AddSourceFile(sf); cmtarget.AddSourceFile(sf);
} }
} }
@ -1714,12 +1706,12 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
(target.GetType() == cmTarget::EXECUTABLE) || (target.GetType() == cmTarget::EXECUTABLE) ||
shared); shared);
const char* lang = target.GetLinkerLanguage(configName); std::string lang = target.GetLinkerLanguage(configName);
std::string cflags; std::string cflags;
if(lang) if(!lang.empty())
{ {
// for c++ projects get the c flags as well // for c++ projects get the c flags as well
if(strcmp(lang, "CXX") == 0) if(lang == "CXX")
{ {
this->CurrentLocalGenerator->AddLanguageFlags(cflags, "C", configName); this->CurrentLocalGenerator->AddLanguageFlags(cflags, "C", configName);
this->CurrentLocalGenerator->AddCMP0018Flags(cflags, &target, this->CurrentLocalGenerator->AddCMP0018Flags(cflags, &target,
@ -2178,7 +2170,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
const char* debugStr = "YES"; const char* debugStr = "YES";
// We can't set the Xcode flag differently depending on the language, // We can't set the Xcode flag differently depending on the language,
// so put them back in this case. // so put them back in this case.
if( (lang && strcmp(lang, "CXX") == 0) && gflag != gflagc ) if( (lang == "CXX") && gflag != gflagc )
{ {
cflags += " "; cflags += " ";
cflags += gflagc; cflags += gflagc;
@ -2201,7 +2193,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
this->CreateString("NO")); this->CreateString("NO"));
buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN", buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
this->CreateString("NO")); this->CreateString("NO"));
if(lang && strcmp(lang, "CXX") == 0) if(lang == "CXX")
{ {
flags += " "; flags += " ";
flags += defFlags; flags += defFlags;
@ -3800,12 +3792,13 @@ cmGlobalXCodeGenerator
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmGlobalXCodeGenerator::LookupFlags(const char* varNamePrefix, std::string cmGlobalXCodeGenerator::LookupFlags(
const char* varNameLang, const std::string& varNamePrefix,
const char* varNameSuffix, const std::string& varNameLang,
const char* default_flags) const std::string& varNameSuffix,
const std::string& default_flags)
{ {
if(varNameLang) if(!varNameLang.empty())
{ {
std::string varName = varNamePrefix; std::string varName = varNamePrefix;
varName += varNameLang; varName += varNameLang;

View File

@ -190,10 +190,10 @@ private:
void CreateReRunCMakeFile(cmLocalGenerator* root, void CreateReRunCMakeFile(cmLocalGenerator* root,
std::vector<cmLocalGenerator*> const& gens); std::vector<cmLocalGenerator*> const& gens);
std::string LookupFlags(const char* varNamePrefix, std::string LookupFlags(const std::string& varNamePrefix,
const char* varNameLang, const std::string& varNameLang,
const char* varNameSuffix, const std::string& varNameSuffix,
const char* default_flags); const std::string& default_flags);
class Factory; class Factory;
class BuildObjectListOrString; class BuildObjectListOrString;
@ -215,7 +215,8 @@ protected:
std::vector<cmXCodeObject*> XCodeObjects; std::vector<cmXCodeObject*> XCodeObjects;
cmXCodeObject* RootObject; cmXCodeObject* RootObject;
private: private:
void PrintCompilerAdvice(std::ostream&, std::string, const char*) const {} void PrintCompilerAdvice(std::ostream&, std::string const&,
const char*) const {}
void ComputeTargetObjects(cmGeneratorTarget* gt) const; void ComputeTargetObjects(cmGeneratorTarget* gt) const;
std::string GetObjectsNormalDirectory( std::string GetObjectsNormalDirectory(

View File

@ -572,7 +572,7 @@ void cmLocalGenerator::GenerateTargetManifest()
} }
void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname, void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
const char* lang, const std::string& lang,
cmSourceFile& source, cmSourceFile& source,
cmGeneratorTarget& target) cmGeneratorTarget& target)
{ {
@ -604,7 +604,7 @@ void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
std::vector<std::string> commands; std::vector<std::string> commands;
cmSystemTools::ExpandList(rules, commands); cmSystemTools::ExpandList(rules, commands);
cmLocalGenerator::RuleVariables vars; cmLocalGenerator::RuleVariables vars;
vars.Language = lang; vars.Language = lang.c_str();
vars.Source = sourceFile.c_str(); vars.Source = sourceFile.c_str();
vars.Object = objectFile.c_str(); vars.Object = objectFile.c_str();
vars.ObjectDir = objectDir.c_str(); vars.ObjectDir = objectDir.c_str();
@ -653,7 +653,7 @@ void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
); );
} }
void cmLocalGenerator::AddBuildTargetRule(const char* llang, void cmLocalGenerator::AddBuildTargetRule(const std::string& llang,
cmGeneratorTarget& target) cmGeneratorTarget& target)
{ {
cmStdString objs; cmStdString objs;
@ -703,7 +703,7 @@ void cmLocalGenerator::AddBuildTargetRule(const char* llang,
&target); &target);
linkLibs = frameworkPath + linkPath + linkLibs; linkLibs = frameworkPath + linkPath + linkLibs;
cmLocalGenerator::RuleVariables vars; cmLocalGenerator::RuleVariables vars;
vars.Language = llang; vars.Language = llang.c_str();
vars.Objects = objs.c_str(); vars.Objects = objs.c_str();
vars.ObjectDir = "."; vars.ObjectDir = ".";
vars.Target = targetName.c_str(); vars.Target = targetName.c_str();
@ -776,8 +776,8 @@ void cmLocalGenerator
case cmTarget::MODULE_LIBRARY: case cmTarget::MODULE_LIBRARY:
case cmTarget::EXECUTABLE: case cmTarget::EXECUTABLE:
{ {
const char* llang = target.Target->GetLinkerLanguage(); std::string llang = target.Target->GetLinkerLanguage();
if(!llang) if(llang.empty())
{ {
cmSystemTools::Error cmSystemTools::Error
("CMake can not determine linker language for target: ", ("CMake can not determine linker language for target: ",
@ -1290,10 +1290,11 @@ cmLocalGenerator::ConvertToIncludeReference(std::string const& path,
std::string cmLocalGenerator::GetIncludeFlags( std::string cmLocalGenerator::GetIncludeFlags(
const std::vector<std::string> &includes, const std::vector<std::string> &includes,
cmGeneratorTarget* target, cmGeneratorTarget* target,
const char* lang, bool forResponseFile, const std::string& lang,
bool forResponseFile,
const char *config) const char *config)
{ {
if(!lang) if(lang.empty())
{ {
return ""; return "";
} }
@ -1415,7 +1416,7 @@ void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalGenerator::AddCompileOptions( void cmLocalGenerator::AddCompileOptions(
std::string& flags, cmTarget* target, std::string& flags, cmTarget* target,
const char* lang, const char* config const std::string& lang, const char* config
) )
{ {
std::string langFlagRegexVar = std::string("CMAKE_")+lang+"_FLAG_REGEX"; std::string langFlagRegexVar = std::string("CMAKE_")+lang+"_FLAG_REGEX";
@ -1463,7 +1464,7 @@ void cmLocalGenerator::AddCompileOptions(
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs, void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
cmGeneratorTarget* target, cmGeneratorTarget* target,
const char* lang, const std::string& lang,
const char *config, const char *config,
bool stripImplicitInclDirs bool stripImplicitInclDirs
) )
@ -1689,8 +1690,8 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
linkFlags += this->Makefile->GetSafeDefinition(build.c_str()); linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
linkFlags += " "; linkFlags += " ";
} }
const char* linkLanguage = target->Target->GetLinkerLanguage(); std::string linkLanguage = target->Target->GetLinkerLanguage();
if(!linkLanguage) if(linkLanguage.empty())
{ {
cmSystemTools::Error cmSystemTools::Error
("CMake can not determine linker language for target: ", ("CMake can not determine linker language for target: ",
@ -1813,7 +1814,7 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
// Collect library linking flags command line options. // Collect library linking flags command line options.
std::string linkLibs; std::string linkLibs;
const char* linkLanguage = cli.GetLinkLanguage(); std::string linkLanguage = cli.GetLinkLanguage();
std::string libPathFlag = std::string libPathFlag =
this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG"); this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
@ -1943,7 +1944,7 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalGenerator::AddArchitectureFlags(std::string& flags, void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
cmGeneratorTarget* target, cmGeneratorTarget* target,
const char *lang, const std::string& lang,
const char* config) const char* config)
{ {
// Only add Mac OS X specific flags on Darwin platforms (OSX and iphone): // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone):
@ -1969,7 +1970,7 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG"; std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG";
const char* deploymentTargetFlag = const char* deploymentTargetFlag =
this->Makefile->GetDefinition(deploymentTargetFlagVar.c_str()); this->Makefile->GetDefinition(deploymentTargetFlagVar.c_str());
if(!archs.empty() && lang && (lang[0] =='C' || lang[0] == 'F')) if(!archs.empty() && !lang.empty() && (lang[0] =='C' || lang[0] == 'F'))
{ {
for(std::vector<std::string>::iterator i = archs.begin(); for(std::vector<std::string>::iterator i = archs.begin();
i != archs.end(); ++i) i != archs.end(); ++i)
@ -2000,7 +2001,7 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalGenerator::AddLanguageFlags(std::string& flags, void cmLocalGenerator::AddLanguageFlags(std::string& flags,
const char* lang, const std::string& lang,
const char* config) const char* config)
{ {
// Add language-specific flags. // Add language-specific flags.
@ -2112,7 +2113,7 @@ bool cmLocalGenerator::GetRealDependency(const char* inName,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalGenerator::AddSharedFlags(std::string& flags, void cmLocalGenerator::AddSharedFlags(std::string& flags,
const char* lang, const std::string& lang,
bool shared) bool shared)
{ {
std::string flagsVar; std::string flagsVar;
@ -2128,7 +2129,8 @@ void cmLocalGenerator::AddSharedFlags(std::string& flags,
} }
static void AddVisibilityCompileOption(std::string &flags, cmTarget* target, static void AddVisibilityCompileOption(std::string &flags, cmTarget* target,
cmLocalGenerator *lg, const char *lang) cmLocalGenerator *lg,
const std::string& lang)
{ {
std::string l(lang); std::string l(lang);
std::string compileOption = "CMAKE_" + l + "_COMPILE_OPTIONS_VISIBILITY"; std::string compileOption = "CMAKE_" + l + "_COMPILE_OPTIONS_VISIBILITY";
@ -2182,7 +2184,7 @@ static void AddInlineVisibilityCompileOption(std::string &flags,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalGenerator void cmLocalGenerator
::AddVisibilityPresetFlags(std::string &flags, cmTarget* target, ::AddVisibilityPresetFlags(std::string &flags, cmTarget* target,
const char *lang) const std::string& lang)
{ {
int targetType = target->GetType(); int targetType = target->GetType();
bool suitableTarget = ((targetType == cmTarget::SHARED_LIBRARY) bool suitableTarget = ((targetType == cmTarget::SHARED_LIBRARY)
@ -2194,13 +2196,13 @@ void cmLocalGenerator
return; return;
} }
if (!lang) if (lang.empty())
{ {
return; return;
} }
AddVisibilityCompileOption(flags, target, this, lang); AddVisibilityCompileOption(flags, target, this, lang);
if(strcmp(lang, "CXX") == 0) if(lang == "CXX")
{ {
AddInlineVisibilityCompileOption(flags, target, this); AddInlineVisibilityCompileOption(flags, target, this);
} }
@ -2396,11 +2398,11 @@ void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines, void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
std::string &definesString, std::string &definesString,
const char* lang) const std::string& lang)
{ {
// Lookup the define flag for the current language. // Lookup the define flag for the current language.
std::string dflag = "-D"; std::string dflag = "-D";
if(lang) if(!lang.empty())
{ {
std::string defineFlagVar = "CMAKE_"; std::string defineFlagVar = "CMAKE_";
defineFlagVar += lang; defineFlagVar += lang;
@ -2460,7 +2462,7 @@ void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalGenerator::AppendFeatureOptions( void cmLocalGenerator::AppendFeatureOptions(
std::string& flags, const char* lang, const char* feature) std::string& flags, const std::string& lang, const char* feature)
{ {
std::string optVar = "CMAKE_"; std::string optVar = "CMAKE_";
optVar += lang; optVar += lang;
@ -3140,7 +3142,8 @@ cmLocalGenerator
bool replaceExt = this->NeedBackwardsCompatibility_2_4(); bool replaceExt = this->NeedBackwardsCompatibility_2_4();
if(!replaceExt) if(!replaceExt)
{ {
if(const char* lang = source.GetLanguage()) std::string lang = source.GetLanguage();
if(!lang.empty())
{ {
std::string repVar = "CMAKE_"; std::string repVar = "CMAKE_";
repVar += lang; repVar += lang;
@ -3174,7 +3177,7 @@ cmLocalGenerator
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const char* std::string
cmLocalGenerator cmLocalGenerator
::GetSourceFileLanguage(const cmSourceFile& source) ::GetSourceFileLanguage(const cmSourceFile& source)
{ {

View File

@ -137,14 +137,14 @@ public:
void AddArchitectureFlags(std::string& flags, cmGeneratorTarget* target, void AddArchitectureFlags(std::string& flags, cmGeneratorTarget* target,
const char *lang, const char* config); const std::string&lang, const char* config);
void AddLanguageFlags(std::string& flags, const char* lang, void AddLanguageFlags(std::string& flags, const std::string& lang,
const char* config); const char* config);
void AddCMP0018Flags(std::string &flags, cmTarget* target, void AddCMP0018Flags(std::string &flags, cmTarget* target,
std::string const& lang, const char *config); std::string const& lang, const char *config);
void AddVisibilityPresetFlags(std::string &flags, cmTarget* target, void AddVisibilityPresetFlags(std::string &flags, cmTarget* target,
const char *lang); const std::string& lang);
void AddConfigVariableFlags(std::string& flags, const std::string& var, void AddConfigVariableFlags(std::string& flags, const std::string& var,
const char* config); const char* config);
///! Append flags to a string. ///! Append flags to a string.
@ -153,7 +153,8 @@ public:
///! Get the include flags for the current makefile and language ///! Get the include flags for the current makefile and language
std::string GetIncludeFlags(const std::vector<std::string> &includes, std::string GetIncludeFlags(const std::vector<std::string> &includes,
cmGeneratorTarget* target, cmGeneratorTarget* target,
const char* lang, bool forResponseFile = false, const std::string& lang,
bool forResponseFile = false,
const char *config = 0); const char *config = 0);
/** /**
@ -175,10 +176,10 @@ public:
*/ */
void JoinDefines(const std::set<std::string>& defines, void JoinDefines(const std::set<std::string>& defines,
std::string &definesString, std::string &definesString,
const char* lang); const std::string& lang);
/** Lookup and append options associated with a particular feature. */ /** Lookup and append options associated with a particular feature. */
void AppendFeatureOptions(std::string& flags, const char* lang, void AppendFeatureOptions(std::string& flags, const std::string& lang,
const char* feature); const char* feature);
/** \brief Get absolute path to dependency \a name /** \brief Get absolute path to dependency \a name
@ -223,16 +224,17 @@ public:
/** Get the include flags for the current makefile and language. */ /** Get the include flags for the current makefile and language. */
void GetIncludeDirectories(std::vector<std::string>& dirs, void GetIncludeDirectories(std::vector<std::string>& dirs,
cmGeneratorTarget* target, cmGeneratorTarget* target,
const char* lang = "C", const char *config = 0, const std::string& lang = "C",
const char *config = 0,
bool stripImplicitInclDirs = true); bool stripImplicitInclDirs = true);
void AddCompileOptions(std::string& flags, cmTarget* target, void AddCompileOptions(std::string& flags, cmTarget* target,
const char* lang, const char* config); const std::string& lang, const char* config);
void AddCompileDefinitions(std::set<std::string>& defines, void AddCompileDefinitions(std::set<std::string>& defines,
cmTarget const* target, cmTarget const* target,
const char* config); const char* config);
/** Compute the language used to compile the given source file. */ /** Compute the language used to compile the given source file. */
const char* GetSourceFileLanguage(const cmSourceFile& source); std::string GetSourceFileLanguage(const cmSourceFile& source);
// Fill the vector with the target names for the object files, // Fill the vector with the target names for the object files,
// preprocessed files and assembly files. // preprocessed files and assembly files.
@ -389,10 +391,11 @@ protected:
/** Convert a target to a utility target for unsupported /** Convert a target to a utility target for unsupported
* languages of a generator */ * languages of a generator */
void AddBuildTargetRule(const char* llang, cmGeneratorTarget& target); void AddBuildTargetRule(const std::string& llang,
cmGeneratorTarget& target);
///! add a custom command to build a .o file that is part of a target ///! add a custom command to build a .o file that is part of a target
void AddCustomCommandToCreateObject(const char* ofname, void AddCustomCommandToCreateObject(const char* ofname,
const char* lang, const std::string& lang,
cmSourceFile& source, cmSourceFile& source,
cmGeneratorTarget& target); cmGeneratorTarget& target);
// Create Custom Targets and commands for unsupported languages // Create Custom Targets and commands for unsupported languages
@ -473,7 +476,8 @@ private:
std::string const& result, std::string const& result,
OutputFormat format); OutputFormat format);
void AddSharedFlags(std::string& flags, const char* lang, bool shared); void AddSharedFlags(std::string& flags, const std::string& lang,
bool shared);
bool GetShouldUseOldFlags(bool shared, const std::string &lang) const; bool GetShouldUseOldFlags(bool shared, const std::string &lang) const;
void AddPositionIndependentFlags(std::string& flags, std::string const& l, void AddPositionIndependentFlags(std::string& flags, std::string const& l,
int targetType); int targetType);

View File

@ -2198,7 +2198,7 @@ cmLocalUnixMakefileGenerator3::GetImplicitDepends(cmTarget const& tgt)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void void
cmLocalUnixMakefileGenerator3::AddImplicitDepends(cmTarget const& tgt, cmLocalUnixMakefileGenerator3::AddImplicitDepends(cmTarget const& tgt,
const char* lang, const std::string& lang,
const char* obj, const char* obj,
const char* src) const char* src)
{ {

View File

@ -217,7 +217,7 @@ public:
public std::map<cmStdString, ImplicitDependLanguageMap> {}; public std::map<cmStdString, ImplicitDependLanguageMap> {};
ImplicitDependLanguageMap const& GetImplicitDepends(cmTarget const& tgt); ImplicitDependLanguageMap const& GetImplicitDepends(cmTarget const& tgt);
void AddImplicitDepends(cmTarget const& tgt, const char* lang, void AddImplicitDepends(cmTarget const& tgt, const std::string& lang,
const char* obj, const char* src); const char* obj, const char* src);
void AppendGlobalTargetDepends(std::vector<std::string>& depends, void AppendGlobalTargetDepends(std::vector<std::string>& depends,
@ -358,7 +358,7 @@ private:
cmTarget* Target; cmTarget* Target;
std::string Language; std::string Language;
LocalObjectEntry(): Target(0), Language() {} LocalObjectEntry(): Target(0), Language() {}
LocalObjectEntry(cmTarget* t, const char* lang): LocalObjectEntry(cmTarget* t, const std::string& lang):
Target(t), Language(lang) {} Target(t), Language(lang) {}
}; };
struct LocalObjectInfo: public std::vector<LocalObjectEntry> struct LocalObjectInfo: public std::vector<LocalObjectEntry>

View File

@ -413,19 +413,16 @@ void cmLocalVisualStudio6Generator
compileFlags += cflags; compileFlags += cflags;
} }
const char* lang = this->GetSourceFileLanguage(*(*sf)); const std::string& lang = this->GetSourceFileLanguage(*(*sf));
if(lang) if(lang == "CXX")
{ {
if(strcmp(lang, "CXX") == 0) // force a C++ file type
{ compileFlags += " /TP ";
// force a C++ file type }
compileFlags += " /TP "; else if(lang == "C")
} {
else if(strcmp(lang, "C") == 0) // force to c file type
{ compileFlags += " /TC ";
// force to c file type
compileFlags += " /TC ";
}
} }
// Add per-source and per-configuration preprocessor definitions. // Add per-source and per-configuration preprocessor definitions.
@ -469,7 +466,7 @@ void cmLocalVisualStudio6Generator
} }
bool excludedFromBuild = bool excludedFromBuild =
(lang && (*sf)->GetPropertyAsBool("HEADER_FILE_ONLY")); (!lang.empty() && (*sf)->GetPropertyAsBool("HEADER_FILE_ONLY"));
// Check for extra object-file dependencies. // Check for extra object-file dependencies.
const char* dependsValue = (*sf)->GetProperty("OBJECT_DEPENDS"); const char* dependsValue = (*sf)->GetProperty("OBJECT_DEPENDS");
@ -1255,8 +1252,8 @@ void cmLocalVisualStudio6Generator
if(targetBuilds) if(targetBuilds)
{ {
// Get the language to use for linking. // Get the language to use for linking.
const char* linkLanguage = target.GetLinkerLanguage(); const std::string& linkLanguage = target.GetLinkerLanguage();
if(!linkLanguage) if(linkLanguage.empty())
{ {
cmSystemTools::Error cmSystemTools::Error
("CMake can not determine linker language for target: ", ("CMake can not determine linker language for target: ",
@ -1677,8 +1674,8 @@ void cmLocalVisualStudio6Generator
if(target.GetType() >= cmTarget::EXECUTABLE && if(target.GetType() >= cmTarget::EXECUTABLE &&
target.GetType() <= cmTarget::OBJECT_LIBRARY) target.GetType() <= cmTarget::OBJECT_LIBRARY)
{ {
const char* linkLanguage = target.GetLinkerLanguage(); const std::string& linkLanguage = target.GetLinkerLanguage();
if(!linkLanguage) if(linkLanguage.empty())
{ {
cmSystemTools::Error cmSystemTools::Error
("CMake can not determine linker language for target: ", ("CMake can not determine linker language for target: ",
@ -1745,11 +1742,11 @@ void cmLocalVisualStudio6Generator
std::string minsizeDefines = " "; std::string minsizeDefines = " ";
std::string debugrelDefines = " "; std::string debugrelDefines = " ";
this->JoinDefines(definesSet, defines, 0); this->JoinDefines(definesSet, defines, "");
this->JoinDefines(debugDefinesSet, debugDefines, 0); this->JoinDefines(debugDefinesSet, debugDefines, "");
this->JoinDefines(releaseDefinesSet, releaseDefines, 0); this->JoinDefines(releaseDefinesSet, releaseDefines, "");
this->JoinDefines(minsizeDefinesSet, minsizeDefines, 0); this->JoinDefines(minsizeDefinesSet, minsizeDefines, "");
this->JoinDefines(debugrelDefinesSet, debugrelDefines, 0); this->JoinDefines(debugrelDefinesSet, debugrelDefines, "");
flags += defines; flags += defines;
flagsDebug += debugDefines; flagsDebug += debugDefines;

View File

@ -687,17 +687,18 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
std::string flags; std::string flags;
if(strcmp(configType, "10") != 0) if(strcmp(configType, "10") != 0)
{ {
const char* linkLanguage = (this->FortranProject? "Fortran": const std::string& linkLanguage = (this->FortranProject?
std::string("Fortran"):
target.GetLinkerLanguage(configName)); target.GetLinkerLanguage(configName));
if(!linkLanguage) if(linkLanguage.empty())
{ {
cmSystemTools::Error cmSystemTools::Error
("CMake can not determine linker language for target: ", ("CMake can not determine linker language for target: ",
target.GetName()); target.GetName());
return; return;
} }
if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0 if(linkLanguage == "C" || linkLanguage == "CXX"
|| strcmp(linkLanguage, "Fortran") == 0) || linkLanguage == "Fortran")
{ {
std::string baseFlagVar = "CMAKE_"; std::string baseFlagVar = "CMAKE_";
baseFlagVar += linkLanguage; baseFlagVar += linkLanguage;
@ -709,11 +710,11 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
flags += this->Makefile->GetRequiredDefinition(flagVar.c_str()); flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
} }
// set the correct language // set the correct language
if(strcmp(linkLanguage, "C") == 0) if(linkLanguage == "C")
{ {
flags += " /TC "; flags += " /TC ";
} }
if(strcmp(linkLanguage, "CXX") == 0) if(linkLanguage == "CXX")
{ {
flags += " /TP "; flags += " /TP ";
} }
@ -1081,7 +1082,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
return; return;
} }
cmComputeLinkInformation& cli = *pcli; cmComputeLinkInformation& cli = *pcli;
const char* linkLanguage = cli.GetLinkLanguage(); std::string linkLanguage = cli.GetLinkLanguage();
// Compute the variable name to lookup standard libraries for this // Compute the variable name to lookup standard libraries for this
// language. // language.
@ -1177,7 +1178,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
return; return;
} }
cmComputeLinkInformation& cli = *pcli; cmComputeLinkInformation& cli = *pcli;
const char* linkLanguage = cli.GetLinkLanguage(); std::string linkLanguage = cli.GetLinkLanguage();
bool isWin32Executable = target.GetPropertyAsBool("WIN32_EXECUTABLE"); bool isWin32Executable = target.GetPropertyAsBool("WIN32_EXECUTABLE");
@ -1546,14 +1547,14 @@ cmLocalVisualStudio7GeneratorFCInfo
} }
} }
const char* lang = std::string lang =
lg->GlobalGenerator->GetLanguageFromExtension lg->GlobalGenerator->GetLanguageFromExtension
(sf.GetExtension().c_str()); (sf.GetExtension().c_str());
const char* sourceLang = lg->GetSourceFileLanguage(sf); const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
const char* linkLanguage = target.GetLinkerLanguage(i->c_str()); const std::string& linkLanguage = target.GetLinkerLanguage(i->c_str());
bool needForceLang = false; bool needForceLang = false;
// source file does not match its extension language // source file does not match its extension language
if(lang && sourceLang && strcmp(lang, sourceLang) != 0) if(lang != sourceLang)
{ {
needForceLang = true; needForceLang = true;
lang = sourceLang; lang = sourceLang;
@ -1569,16 +1570,15 @@ cmLocalVisualStudio7GeneratorFCInfo
// if the source file does not match the linker language // if the source file does not match the linker language
// then force c or c++ // then force c or c++
if(needForceLang || (linkLanguage && lang if(needForceLang || (linkLanguage != lang))
&& strcmp(lang, linkLanguage) != 0))
{ {
if(strcmp(lang, "CXX") == 0) if(lang == "CXX")
{ {
// force a C++ file type // force a C++ file type
fc.CompileFlags += " /TP "; fc.CompileFlags += " /TP ";
needfc = true; needfc = true;
} }
else if(strcmp(lang, "C") == 0) else if(lang == "C")
{ {
// force to c // force to c
fc.CompileFlags += " /TC "; fc.CompileFlags += " /TC ";

View File

@ -2361,10 +2361,10 @@ bool cmMakefile::PlatformIs64Bit() const
return false; return false;
} }
const char* cmMakefile::GetSONameFlag(const char* language) const const char* cmMakefile::GetSONameFlag(const std::string& language) const
{ {
std::string name = "CMAKE_SHARED_LIBRARY_SONAME"; std::string name = "CMAKE_SHARED_LIBRARY_SONAME";
if(language) if(!language.empty())
{ {
name += "_"; name += "_";
name += language; name += language;

View File

@ -608,7 +608,7 @@ public:
bool PlatformIs64Bit() const; bool PlatformIs64Bit() const;
/** Retrieve soname flag for the specified language if supported */ /** Retrieve soname flag for the specified language if supported */
const char* GetSONameFlag(const char* language) const; const char* GetSONameFlag(const std::string& language) const;
/** /**
* Get a list of preprocessor define flags. * Get a list of preprocessor define flags.

View File

@ -160,11 +160,11 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
cmLocalGenerator::SHELL); cmLocalGenerator::SHELL);
// Get the language to use for linking this executable. // Get the language to use for linking this executable.
const char* linkLanguage = std::string linkLanguage =
this->Target->GetLinkerLanguage(this->ConfigName); this->Target->GetLinkerLanguage(this->ConfigName);
// Make sure we have a link language. // Make sure we have a link language.
if(!linkLanguage) if(linkLanguage.empty())
{ {
cmSystemTools::Error("Cannot determine link language for target \"", cmSystemTools::Error("Cannot determine link language for target \"",
this->Target->GetName(), "\"."); this->Target->GetName(), "\".");
@ -348,7 +348,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
cmLocalGenerator::RuleVariables vars; cmLocalGenerator::RuleVariables vars;
vars.RuleLauncher = "RULE_LAUNCH_LINK"; vars.RuleLauncher = "RULE_LAUNCH_LINK";
vars.CMTarget = this->Target; vars.CMTarget = this->Target;
vars.Language = linkLanguage; vars.Language = linkLanguage.c_str();
vars.Objects = buildObjs.c_str(); vars.Objects = buildObjs.c_str();
std::string objectDir = this->Target->GetSupportDirectory(); std::string objectDir = this->Target->GetSupportDirectory();
objectDir = this->Convert(objectDir.c_str(), objectDir = this->Convert(objectDir.c_str(),

View File

@ -131,13 +131,10 @@ void cmMakefileLibraryTargetGenerator::WriteObjectLibraryRules()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules() void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
{ {
const char* linkLanguage = std::string linkLanguage =
this->Target->GetLinkerLanguage(this->ConfigName); this->Target->GetLinkerLanguage(this->ConfigName);
std::string linkRuleVar = "CMAKE_"; std::string linkRuleVar = "CMAKE_";
if (linkLanguage) linkRuleVar += linkLanguage;
{
linkRuleVar += linkLanguage;
}
linkRuleVar += "_CREATE_STATIC_LIBRARY"; linkRuleVar += "_CREATE_STATIC_LIBRARY";
if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION") && if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION") &&
@ -160,13 +157,10 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
this->WriteFrameworkRules(relink); this->WriteFrameworkRules(relink);
return; return;
} }
const char* linkLanguage = std::string linkLanguage =
this->Target->GetLinkerLanguage(this->ConfigName); this->Target->GetLinkerLanguage(this->ConfigName);
std::string linkRuleVar = "CMAKE_"; std::string linkRuleVar = "CMAKE_";
if (linkLanguage) linkRuleVar += linkLanguage;
{
linkRuleVar += linkLanguage;
}
linkRuleVar += "_CREATE_SHARED_LIBRARY"; linkRuleVar += "_CREATE_SHARED_LIBRARY";
std::string extraFlags; std::string extraFlags;
@ -187,13 +181,10 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink) void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
{ {
const char* linkLanguage = std::string linkLanguage =
this->Target->GetLinkerLanguage(this->ConfigName); this->Target->GetLinkerLanguage(this->ConfigName);
std::string linkRuleVar = "CMAKE_"; std::string linkRuleVar = "CMAKE_";
if (linkLanguage) linkRuleVar += linkLanguage;
{
linkRuleVar += linkLanguage;
}
linkRuleVar += "_CREATE_SHARED_MODULE"; linkRuleVar += "_CREATE_SHARED_MODULE";
std::string extraFlags; std::string extraFlags;
@ -213,13 +204,10 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink) void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink)
{ {
const char* linkLanguage = std::string linkLanguage =
this->Target->GetLinkerLanguage(this->ConfigName); this->Target->GetLinkerLanguage(this->ConfigName);
std::string linkRuleVar = "CMAKE_"; std::string linkRuleVar = "CMAKE_";
if (linkLanguage) linkRuleVar += linkLanguage;
{
linkRuleVar += linkLanguage;
}
linkRuleVar += "_CREATE_MACOSX_FRAMEWORK"; linkRuleVar += "_CREATE_MACOSX_FRAMEWORK";
std::string extraFlags; std::string extraFlags;
@ -248,11 +236,11 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
this->AppendLinkDepends(depends); this->AppendLinkDepends(depends);
// Get the language to use for linking this library. // Get the language to use for linking this library.
const char* linkLanguage = std::string linkLanguage =
this->Target->GetLinkerLanguage(this->ConfigName); this->Target->GetLinkerLanguage(this->ConfigName);
// Make sure we have a link language. // Make sure we have a link language.
if(!linkLanguage) if(linkLanguage.empty())
{ {
cmSystemTools::Error("Cannot determine link language for target \"", cmSystemTools::Error("Cannot determine link language for target \"",
this->Target->GetName(), "\"."); this->Target->GetName(), "\".");
@ -589,7 +577,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
vars.RuleLauncher = "RULE_LAUNCH_LINK"; vars.RuleLauncher = "RULE_LAUNCH_LINK";
vars.CMTarget = this->Target; vars.CMTarget = this->Target;
vars.Language = linkLanguage; vars.Language = linkLanguage.c_str();
vars.Objects = buildObjs.c_str(); vars.Objects = buildObjs.c_str();
std::string objectDir = this->Target->GetSupportDirectory(); std::string objectDir = this->Target->GetSupportDirectory();
objectDir = this->Convert(objectDir.c_str(), objectDir = this->Convert(objectDir.c_str(),
@ -786,7 +774,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void void
cmMakefileLibraryTargetGenerator cmMakefileLibraryTargetGenerator
::AppendOSXVerFlag(std::string& flags, const char* lang, ::AppendOSXVerFlag(std::string& flags, const std::string& lang,
const char* name, bool so) const char* name, bool so)
{ {
// Lookup the flag to specify the version. // Lookup the flag to specify the version.

View File

@ -39,7 +39,7 @@ protected:
// Store the computd framework version for OS X Frameworks. // Store the computd framework version for OS X Frameworks.
std::string FrameworkVersion; std::string FrameworkVersion;
void AppendOSXVerFlag(std::string& flags, const char* lang, void AppendOSXVerFlag(std::string& flags, const std::string& lang,
const char* name, bool so); const char* name, bool so);
}; };

View File

@ -422,8 +422,9 @@ cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()
void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source) void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source)
{ {
// Identify the language of the source file. // Identify the language of the source file.
const char* lang = this->LocalGenerator->GetSourceFileLanguage(source); const std::string& lang =
if(!lang) this->LocalGenerator->GetSourceFileLanguage(source);
if(lang.empty())
{ {
// don't know anything about this file so skip it // don't know anything about this file so skip it
return; return;
@ -523,7 +524,7 @@ cmMakefileTargetGenerator
void void
cmMakefileTargetGenerator cmMakefileTargetGenerator
::WriteObjectBuildFile(std::string &obj, ::WriteObjectBuildFile(std::string &obj,
const char *lang, const std::string& lang,
cmSourceFile& source, cmSourceFile& source,
std::vector<std::string>& depends) std::vector<std::string>& depends)
{ {
@ -552,7 +553,7 @@ cmMakefileTargetGenerator
cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName); cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName);
// Add Fortran format flags. // Add Fortran format flags.
if(strcmp(lang, "Fortran") == 0) if(lang == "Fortran")
{ {
this->AppendFortranFormatFlags(flags, source); this->AppendFortranFormatFlags(flags, source);
} }
@ -664,7 +665,7 @@ cmMakefileTargetGenerator
cmLocalGenerator::RuleVariables vars; cmLocalGenerator::RuleVariables vars;
vars.RuleLauncher = "RULE_LAUNCH_COMPILE"; vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
vars.CMTarget = this->Target; vars.CMTarget = this->Target;
vars.Language = lang; vars.Language = lang.c_str();
vars.Target = targetOutPathReal.c_str(); vars.Target = targetOutPathReal.c_str();
vars.TargetPDB = targetOutPathPDB.c_str(); vars.TargetPDB = targetOutPathPDB.c_str();
vars.TargetCompilePDB = targetOutPathCompilePDB.c_str(); vars.TargetCompilePDB = targetOutPathCompilePDB.c_str();
@ -689,8 +690,7 @@ cmMakefileTargetGenerator
vars.Defines = definesString.c_str(); vars.Defines = definesString.c_str();
bool lang_is_c_or_cxx = ((strcmp(lang, "C") == 0) || bool lang_is_c_or_cxx = ((lang == "C") || (lang == "CXX"));
(strcmp(lang, "CXX") == 0));
// Construct the compile rules. // Construct the compile rules.
{ {
@ -1709,8 +1709,8 @@ void cmMakefileTargetGenerator
} }
void cmMakefileTargetGenerator::RemoveForbiddenFlags(const char* flagVar, void cmMakefileTargetGenerator::RemoveForbiddenFlags(const char* flagVar,
const char* linkLang, const std::string& linkLang,
std::string& linkFlags) std::string& linkFlags)
{ {
// check for language flags that are not allowed at link time, and // check for language flags that are not allowed at link time, and
// remove them, -w on darwin for gcc -w -dynamiclib sends -w to libtool // remove them, -w on darwin for gcc -w -dynamiclib sends -w to libtool
@ -1943,7 +1943,7 @@ cmMakefileTargetGenerator
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags, void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags,
const char* lang) const std::string& lang)
{ {
std::string responseVar = "CMAKE_"; std::string responseVar = "CMAKE_";
responseVar += lang; responseVar += lang;
@ -2113,7 +2113,7 @@ bool cmMakefileTargetGenerator::GetFeatureAsBool(const char* feature)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefileTargetGenerator::AddFeatureFlags( void cmMakefileTargetGenerator::AddFeatureFlags(
std::string& flags, const char* lang std::string& flags, const std::string& lang
) )
{ {
// Add language-specific flags. // Add language-specific flags.

View File

@ -93,7 +93,7 @@ protected:
// write the build rule for an object // write the build rule for an object
void WriteObjectBuildFile(std::string &obj, void WriteObjectBuildFile(std::string &obj,
const char *lang, const std::string& lang,
cmSourceFile& source, cmSourceFile& source,
std::vector<std::string>& depends); std::vector<std::string>& depends);
@ -173,10 +173,10 @@ protected:
bool useResponseFile, std::string& buildObjs, bool useResponseFile, std::string& buildObjs,
std::vector<std::string>& makefile_depends); std::vector<std::string>& makefile_depends);
void AddIncludeFlags(std::string& flags, const char* lang); void AddIncludeFlags(std::string& flags, const std::string& lang);
virtual void CloseFileStreams(); virtual void CloseFileStreams();
void RemoveForbiddenFlags(const char* flagVar, const char* linkLang, void RemoveForbiddenFlags(const char* flagVar, const std::string& linkLang,
std::string& linkFlags); std::string& linkFlags);
cmTarget *Target; cmTarget *Target;
cmGeneratorTarget* GeneratorTarget; cmGeneratorTarget* GeneratorTarget;
@ -260,7 +260,7 @@ protected:
void AddModuleDefinitionFlag(std::string& flags); void AddModuleDefinitionFlag(std::string& flags);
// Add language feature flags. // Add language feature flags.
void AddFeatureFlags(std::string& flags, const char* lang); void AddFeatureFlags(std::string& flags, const std::string& lang);
// Feature query methods. // Feature query methods.
const char* GetFeature(const char* feature); const char* GetFeature(const char* feature);

View File

@ -35,7 +35,7 @@ cmNinjaNormalTargetGenerator(cmGeneratorTarget* target)
, TargetNameReal() , TargetNameReal()
, TargetNameImport() , TargetNameImport()
, TargetNamePDB() , TargetNamePDB()
, TargetLinkLanguage(0) , TargetLinkLanguage("")
{ {
this->TargetLinkLanguage = target->Target this->TargetLinkLanguage = target->Target
->GetLinkerLanguage(this->GetConfigName()); ->GetLinkerLanguage(this->GetConfigName());
@ -72,7 +72,7 @@ cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator()
void cmNinjaNormalTargetGenerator::Generate() void cmNinjaNormalTargetGenerator::Generate()
{ {
if (!this->TargetLinkLanguage) { if (this->TargetLinkLanguage.empty()) {
cmSystemTools::Error("CMake can not determine linker language for " cmSystemTools::Error("CMake can not determine linker language for "
"target: ", "target: ",
this->GetTarget()->GetName()); this->GetTarget()->GetName());
@ -140,7 +140,7 @@ std::string
cmNinjaNormalTargetGenerator cmNinjaNormalTargetGenerator
::LanguageLinkerRule() const ::LanguageLinkerRule() const
{ {
return std::string(this->TargetLinkLanguage) return this->TargetLinkLanguage
+ "_" + "_"
+ cmTarget::GetTargetTypeName(this->GetTarget()->GetType()) + cmTarget::GetTargetTypeName(this->GetTarget()->GetType())
+ "_LINKER"; + "_LINKER";
@ -163,7 +163,7 @@ cmNinjaNormalTargetGenerator
cmLocalGenerator::RuleVariables vars; cmLocalGenerator::RuleVariables vars;
vars.RuleLauncher = "RULE_LAUNCH_LINK"; vars.RuleLauncher = "RULE_LAUNCH_LINK";
vars.CMTarget = this->GetTarget(); vars.CMTarget = this->GetTarget();
vars.Language = this->TargetLinkLanguage; vars.Language = this->TargetLinkLanguage.c_str();
std::string responseFlag; std::string responseFlag;
if (!useResponseFile) { if (!useResponseFile) {

View File

@ -47,7 +47,7 @@ private:
std::string TargetNameReal; std::string TargetNameReal;
std::string TargetNameImport; std::string TargetNameImport;
std::string TargetNamePDB; std::string TargetNamePDB;
const char *TargetLinkLanguage; std::string TargetLinkLanguage;
}; };
#endif // ! cmNinjaNormalTargetGenerator_h #endif // ! cmNinjaNormalTargetGenerator_h

View File

@ -110,7 +110,7 @@ bool cmNinjaTargetGenerator::GetFeatureAsBool(const char* feature)
// TODO: Picked up from cmMakefileTargetGenerator. Refactor it. // TODO: Picked up from cmMakefileTargetGenerator. Refactor it.
void cmNinjaTargetGenerator::AddFeatureFlags(std::string& flags, void cmNinjaTargetGenerator::AddFeatureFlags(std::string& flags,
const char* lang) const std::string& lang)
{ {
// Add language-specific flags. // Add language-specific flags.
this->LocalGenerator->AddLanguageFlags(flags, lang, this->GetConfigName()); this->LocalGenerator->AddLanguageFlags(flags, lang, this->GetConfigName());

View File

@ -72,7 +72,7 @@ protected:
const char* GetFeature(const char* feature); const char* GetFeature(const char* feature);
bool GetFeatureAsBool(const char* feature); bool GetFeatureAsBool(const char* feature);
void AddFeatureFlags(std::string& flags, const char* lang); void AddFeatureFlags(std::string& flags, const std::string& lang);
/** /**
* Compute the flags for compilation of object files for a given @a language. * Compute the flags for compilation of object files for a given @a language.

View File

@ -39,7 +39,7 @@ std::string const& cmSourceFile::GetExtension() const
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const char* cmSourceFile::GetLanguage() std::string cmSourceFile::GetLanguage()
{ {
// If the language was set explicitly by the user then use it. // If the language was set explicitly by the user then use it.
if(const char* lang = this->GetProperty("LANGUAGE")) if(const char* lang = this->GetProperty("LANGUAGE"))
@ -76,7 +76,7 @@ const char* cmSourceFile::GetLanguage()
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const char* cmSourceFile::GetLanguage() const std::string cmSourceFile::GetLanguage() const
{ {
// If the language was set explicitly by the user then use it. // If the language was set explicitly by the user then use it.
if(const char* lang = this->GetProperty("LANGUAGE")) if(const char* lang = this->GetProperty("LANGUAGE"))
@ -87,11 +87,11 @@ const char* cmSourceFile::GetLanguage() const
// If the language was determined from the source file extension use it. // If the language was determined from the source file extension use it.
if(!this->Language.empty()) if(!this->Language.empty())
{ {
return this->Language.c_str(); return this->Language;
} }
// The language is not known. // The language is not known.
return 0; return "";
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -267,7 +267,8 @@ void cmSourceFile::CheckLanguage(std::string const& ext)
// Try to identify the source file language from the extension. // Try to identify the source file language from the extension.
cmMakefile const* mf = this->Location.GetMakefile(); cmMakefile const* mf = this->Location.GetMakefile();
cmGlobalGenerator* gg = mf->GetLocalGenerator()->GetGlobalGenerator(); cmGlobalGenerator* gg = mf->GetLocalGenerator()->GetGlobalGenerator();
if(const char* l = gg->GetLanguageFromExtension(ext.c_str())) std::string l = gg->GetLanguageFromExtension(ext.c_str());
if(!l.empty())
{ {
this->Language = l; this->Language = l;
} }

View File

@ -79,8 +79,8 @@ public:
/** /**
* Get the language of the compiler to use for this source file. * Get the language of the compiler to use for this source file.
*/ */
const char* GetLanguage(); std::string GetLanguage();
const char* GetLanguage() const; std::string GetLanguage() const;
/** /**
* Return the vector that holds the list of dependencies * Return the vector that holds the list of dependencies

View File

@ -93,7 +93,7 @@ void cmSourceFileLocation::UpdateExtension(const std::string& name)
cmMakefile const* mf = this->Makefile; cmMakefile const* mf = this->Makefile;
const std::vector<std::string>& srcExts = mf->GetSourceExtensions(); const std::vector<std::string>& srcExts = mf->GetSourceExtensions();
const std::vector<std::string>& hdrExts = mf->GetHeaderExtensions(); const std::vector<std::string>& hdrExts = mf->GetHeaderExtensions();
if(gg->GetLanguageFromExtension(ext.c_str()) || if(!gg->GetLanguageFromExtension(ext.c_str()).empty() ||
std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end() || std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end() ||
std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end()) std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end())
{ {

View File

@ -2884,13 +2884,11 @@ private:
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const char* cmTarget::GetLinkerLanguage(const char* config, std::string cmTarget::GetLinkerLanguage(const char* config,
cmTarget const* head) const cmTarget const* head) const
{ {
cmTarget const* headTarget = head ? head : this; cmTarget const* headTarget = head ? head : this;
const char* lang = this->GetLinkClosure(config, headTarget) return this->GetLinkClosure(config, headTarget)->LinkerLanguage;
->LinkerLanguage.c_str();
return *lang? lang : 0;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -2924,7 +2922,7 @@ public:
this->Makefile = this->Target->GetMakefile(); this->Makefile = this->Target->GetMakefile();
this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator(); this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
} }
void Consider(const char* lang) void Consider(const std::string& lang)
{ {
int preference = this->GG->GetLinkerPreference(lang); int preference = this->GG->GetLinkerPreference(lang);
if(preference > this->Preference) if(preference > this->Preference)
@ -3530,7 +3528,8 @@ void cmTarget::GetFullNameInternal(const char* config,
const char* suffixVar = this->GetSuffixVariableInternal(implib); const char* suffixVar = this->GetSuffixVariableInternal(implib);
// Check for language-specific default prefix and suffix. // Check for language-specific default prefix and suffix.
if(const char* ll = this->GetLinkerLanguage(config, this)) std::string ll = this->GetLinkerLanguage(config, this);
if(!ll.empty())
{ {
if(!targetSuffix && suffixVar && *suffixVar) if(!targetSuffix && suffixVar && *suffixVar)
{ {
@ -3867,7 +3866,8 @@ bool cmTarget::NeedRelinkBeforeInstall(const char* config) const
} }
// Check for rpath support on this platform. // Check for rpath support on this platform.
if(const char* ll = this->GetLinkerLanguage(config, this)) std::string ll = this->GetLinkerLanguage(config, this);
if(!ll.empty())
{ {
std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_"; std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
flagVar += ll; flagVar += ll;
@ -4825,7 +4825,8 @@ void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
for(std::vector<cmSourceFile*>::const_iterator for(std::vector<cmSourceFile*>::const_iterator
i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i) i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
{ {
if(const char* lang = (*i)->GetLanguage()) const std::string& lang = (*i)->GetLanguage();
if(!lang.empty())
{ {
languages.insert(lang); languages.insert(lang);
} }
@ -4876,7 +4877,8 @@ bool cmTarget::IsChrpathUsed(const char* config) const
#if defined(CMAKE_USE_ELF_PARSER) #if defined(CMAKE_USE_ELF_PARSER)
// Enable if the rpath flag uses a separator and the target uses ELF // Enable if the rpath flag uses a separator and the target uses ELF
// binaries. // binaries.
if(const char* ll = this->GetLinkerLanguage(config, this)) std::string ll = this->GetLinkerLanguage(config, this);
if(!ll.empty())
{ {
std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_"; std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
sepVar += ll; sepVar += ll;

View File

@ -347,7 +347,7 @@ public:
GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const; GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const;
///! Return the preferred linker language for this target ///! Return the preferred linker language for this target
const char* GetLinkerLanguage(const char* config = 0, std::string GetLinkerLanguage(const char* config = 0,
cmTarget const* head = 0) const; cmTarget const* head = 0) const;
/** Get the full name of the target according to the settings in its /** Get the full name of the target according to the settings in its

View File

@ -1012,18 +1012,18 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
si = objectSources.begin(); si = objectSources.begin();
si != objectSources.end(); ++si) si != objectSources.end(); ++si)
{ {
const char* lang = (*si)->GetLanguage(); const std::string& lang = (*si)->GetLanguage();
const char* tool = NULL; const char* tool = NULL;
if (strcmp(lang, "C") == 0 || strcmp(lang, "CXX") == 0) if (lang == "C"|| lang == "CXX")
{ {
tool = "ClCompile"; tool = "ClCompile";
} }
else if (strcmp(lang, "ASM_MASM") == 0 && else if (lang == "ASM_NASM" &&
this->GlobalGenerator->IsMasmEnabled()) this->GlobalGenerator->IsMasmEnabled())
{ {
tool = "MASM"; tool = "MASM";
} }
else if (strcmp(lang, "RC") == 0) else if (lang == "RC")
{ {
tool = "ResourceCompile"; tool = "ResourceCompile";
} }
@ -1108,29 +1108,28 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
{ {
defines += cdefs; defines += cdefs;
} }
const char* lang = std::string lang =
this->GlobalGenerator->GetLanguageFromExtension this->GlobalGenerator->GetLanguageFromExtension
(sf.GetExtension().c_str()); (sf.GetExtension().c_str());
const char* sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf); std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
const char* linkLanguage = this->Target->GetLinkerLanguage(); const std::string& linkLanguage = this->Target->GetLinkerLanguage();
bool needForceLang = false; bool needForceLang = false;
// source file does not match its extension language // source file does not match its extension language
if(lang && sourceLang && strcmp(lang, sourceLang) != 0) if(lang != sourceLang)
{ {
needForceLang = true; needForceLang = true;
lang = sourceLang; lang = sourceLang;
} }
// if the source file does not match the linker language // if the source file does not match the linker language
// then force c or c++ // then force c or c++
if(needForceLang || (linkLanguage && lang if(needForceLang || (linkLanguage != lang))
&& strcmp(lang, linkLanguage) != 0))
{ {
if(strcmp(lang, "CXX") == 0) if(lang == "CXX")
{ {
// force a C++ file type // force a C++ file type
flags += " /TP "; flags += " /TP ";
} }
else if(strcmp(lang, "C") == 0) else if(lang == "C")
{ {
// force to c // force to c
flags += " /TC "; flags += " /TC ";
@ -1341,17 +1340,17 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
// collect up flags for // collect up flags for
if(this->Target->GetType() < cmTarget::UTILITY) if(this->Target->GetType() < cmTarget::UTILITY)
{ {
const char* linkLanguage = const std::string& linkLanguage =
this->Target->GetLinkerLanguage(configName.c_str()); this->Target->GetLinkerLanguage(configName.c_str());
if(!linkLanguage) if(linkLanguage.empty())
{ {
cmSystemTools::Error cmSystemTools::Error
("CMake can not determine linker language for target: ", ("CMake can not determine linker language for target: ",
this->Name.c_str()); this->Name.c_str());
return false; return false;
} }
if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0 if(linkLanguage == "C" || linkLanguage == "CXX"
|| strcmp(linkLanguage, "Fortran") == 0) || linkLanguage == "Fortran")
{ {
std::string baseFlagVar = "CMAKE_"; std::string baseFlagVar = "CMAKE_";
baseFlagVar += linkLanguage; baseFlagVar += linkLanguage;
@ -1365,11 +1364,11 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str()); Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
} }
// set the correct language // set the correct language
if(strcmp(linkLanguage, "C") == 0) if(linkLanguage == "C")
{ {
flags += " /TC "; flags += " /TC ";
} }
if(strcmp(linkLanguage, "CXX") == 0) if(linkLanguage == "CXX")
{ {
flags += " /TP "; flags += " /TP ";
} }
@ -1525,9 +1524,9 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
cmVSGetLinkFlagTable(this->LocalGenerator), 0, this)); cmVSGetLinkFlagTable(this->LocalGenerator), 0, this));
Options& linkOptions = *pOptions; Options& linkOptions = *pOptions;
const char* linkLanguage = const std::string& linkLanguage =
this->Target->GetLinkerLanguage(config.c_str()); this->Target->GetLinkerLanguage(config.c_str());
if(!linkLanguage) if(linkLanguage.empty())
{ {
cmSystemTools::Error cmSystemTools::Error
("CMake can not determine linker language for target: ", ("CMake can not determine linker language for target: ",

View File

@ -222,7 +222,7 @@ cmVisualStudioGeneratorOptions
::OutputPreprocessorDefinitions(std::ostream& fout, ::OutputPreprocessorDefinitions(std::ostream& fout,
const char* prefix, const char* prefix,
const char* suffix, const char* suffix,
const char* lang) const std::string& lang)
{ {
if(this->Defines.empty()) if(this->Defines.empty())
{ {
@ -270,7 +270,7 @@ cmVisualStudioGeneratorOptions
{ {
define = cmVisualStudio10GeneratorOptionsEscapeForXML(define.c_str()); define = cmVisualStudio10GeneratorOptionsEscapeForXML(define.c_str());
if(0 == strcmp(lang, "RC")) if(lang == "RC")
{ {
cmSystemTools::ReplaceString(define, "\"", "\\\""); cmSystemTools::ReplaceString(define, "\"", "\\\"");
} }

View File

@ -55,7 +55,7 @@ public:
void OutputPreprocessorDefinitions(std::ostream& fout, void OutputPreprocessorDefinitions(std::ostream& fout,
const char* prefix, const char* prefix,
const char* suffix, const char* suffix,
const char* lang); const std::string& lang);
void OutputFlagMap(std::ostream& fout, const char* indent); void OutputFlagMap(std::ostream& fout, const char* indent);
void OutputAdditionalOptions(std::ostream& fout, void OutputAdditionalOptions(std::ostream& fout,
const char* prefix, const char* prefix,

View File

@ -123,7 +123,7 @@ public:
void CopyAttributes(cmXCodeObject* ); void CopyAttributes(cmXCodeObject* );
void AddDependLibrary(const char* configName, void AddDependLibrary(const char* configName,
const char* l) const std::string& l)
{ {
if(!configName) if(!configName)
{ {