Port cmLocalGenerator::GetTargetFlags to cmGeneratorTarget.

This commit is contained in:
Stephen Kelly 2012-09-16 01:35:08 +02:00
parent 9facfd1336
commit f9146f6b90
6 changed files with 28 additions and 26 deletions

View File

@ -679,7 +679,7 @@ void cmLocalGenerator::AddBuildTargetRule(const char* llang,
std::string linkLibs; // should be set std::string linkLibs; // should be set
std::string flags; // should be set std::string flags; // should be set
std::string linkFlags; // should be set std::string linkFlags; // should be set
this->GetTargetFlags(linkLibs, flags, linkFlags, *target.Target); this->GetTargetFlags(linkLibs, flags, linkFlags, &target);
cmLocalGenerator::RuleVariables vars; cmLocalGenerator::RuleVariables vars;
vars.Language = llang; vars.Language = llang;
vars.Objects = objs.c_str(); vars.Objects = objs.c_str();
@ -1451,7 +1451,7 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
void cmLocalGenerator::GetTargetFlags(std::string& linkLibs, void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
std::string& flags, std::string& flags,
std::string& linkFlags, std::string& linkFlags,
cmTarget& target) cmGeneratorTarget* target)
{ {
std::string buildType = std::string buildType =
this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
@ -1459,12 +1459,12 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
const char* libraryLinkVariable = const char* libraryLinkVariable =
"CMAKE_SHARED_LINKER_FLAGS"; // default to shared library "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
switch(target.GetType()) switch(target->GetType())
{ {
case cmTarget::STATIC_LIBRARY: case cmTarget::STATIC_LIBRARY:
{ {
const char* targetLinkFlags = const char* targetLinkFlags =
target.GetProperty("STATIC_LIBRARY_FLAGS"); target->GetProperty("STATIC_LIBRARY_FLAGS");
if(targetLinkFlags) if(targetLinkFlags)
{ {
linkFlags += targetLinkFlags; linkFlags += targetLinkFlags;
@ -1474,7 +1474,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
{ {
std::string build = "STATIC_LIBRARY_FLAGS_"; std::string build = "STATIC_LIBRARY_FLAGS_";
build += buildType; build += buildType;
targetLinkFlags = target.GetProperty(build.c_str()); targetLinkFlags = target->GetProperty(build.c_str());
if(targetLinkFlags) if(targetLinkFlags)
{ {
linkFlags += targetLinkFlags; linkFlags += targetLinkFlags;
@ -1500,7 +1500,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
if(this->Makefile->IsOn("WIN32") && if(this->Makefile->IsOn("WIN32") &&
!(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW"))) !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
{ {
const std::vector<cmSourceFile*>& sources = target.GetSourceFiles(); const std::vector<cmSourceFile*>& sources = target->GetSourceFiles();
for(std::vector<cmSourceFile*>::const_iterator i = sources.begin(); for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
i != sources.end(); ++i) i != sources.end(); ++i)
{ {
@ -1515,7 +1515,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
} }
} }
} }
const char* targetLinkFlags = target.GetProperty("LINK_FLAGS"); const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
if(targetLinkFlags) if(targetLinkFlags)
{ {
linkFlags += targetLinkFlags; linkFlags += targetLinkFlags;
@ -1525,7 +1525,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
{ {
std::string configLinkFlags = "LINK_FLAGS_"; std::string configLinkFlags = "LINK_FLAGS_";
configLinkFlags += buildType; configLinkFlags += buildType;
targetLinkFlags = target.GetProperty(configLinkFlags.c_str()); targetLinkFlags = target->GetProperty(configLinkFlags.c_str());
if(targetLinkFlags) if(targetLinkFlags)
{ {
linkFlags += targetLinkFlags; linkFlags += targetLinkFlags;
@ -1533,7 +1533,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
} }
} }
cmOStringStream linklibsStr; cmOStringStream linklibsStr;
this->OutputLinkLibraries(linklibsStr, target, false); this->OutputLinkLibraries(linklibsStr, *target, false);
linkLibs = linklibsStr.str(); linkLibs = linklibsStr.str();
} }
break; break;
@ -1549,17 +1549,17 @@ 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.GetLinkerLanguage(); const char* linkLanguage = target->Target->GetLinkerLanguage();
if(!linkLanguage) if(!linkLanguage)
{ {
cmSystemTools::Error cmSystemTools::Error
("CMake can not determine linker language for target:", ("CMake can not determine linker language for target:",
target.GetName()); target->Target->GetName());
return; return;
} }
this->AddLanguageFlags(flags, linkLanguage, buildType.c_str()); this->AddLanguageFlags(flags, linkLanguage, buildType.c_str());
cmOStringStream linklibs; cmOStringStream linklibs;
this->OutputLinkLibraries(linklibs, target, false); this->OutputLinkLibraries(linklibs, *target, false);
linkLibs = linklibs.str(); linkLibs = linklibs.str();
if(cmSystemTools::IsOn if(cmSystemTools::IsOn
(this->Makefile->GetDefinition("BUILD_SHARED_LIBS"))) (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
@ -1569,7 +1569,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
linkFlags += this->Makefile->GetSafeDefinition(sFlagVar.c_str()); linkFlags += this->Makefile->GetSafeDefinition(sFlagVar.c_str());
linkFlags += " "; linkFlags += " ";
} }
if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") ) if ( target->GetPropertyAsBool("WIN32_EXECUTABLE") )
{ {
linkFlags += linkFlags +=
this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE"); this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
@ -1581,7 +1581,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE"); this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
linkFlags += " "; linkFlags += " ";
} }
if (target.IsExecutableWithExports()) if (target->Target->IsExecutableWithExports())
{ {
std::string exportFlagVar = "CMAKE_EXE_EXPORTS_"; std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
exportFlagVar += linkLanguage; exportFlagVar += linkLanguage;
@ -1591,7 +1591,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
this->Makefile->GetSafeDefinition(exportFlagVar.c_str()); this->Makefile->GetSafeDefinition(exportFlagVar.c_str());
linkFlags += " "; linkFlags += " ";
} }
const char* targetLinkFlags = target.GetProperty("LINK_FLAGS"); const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
if(targetLinkFlags) if(targetLinkFlags)
{ {
linkFlags += targetLinkFlags; linkFlags += targetLinkFlags;
@ -1601,7 +1601,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
{ {
std::string configLinkFlags = "LINK_FLAGS_"; std::string configLinkFlags = "LINK_FLAGS_";
configLinkFlags += buildType; configLinkFlags += buildType;
targetLinkFlags = target.GetProperty(configLinkFlags.c_str()); targetLinkFlags = target->GetProperty(configLinkFlags.c_str());
if(targetLinkFlags) if(targetLinkFlags)
{ {
linkFlags += targetLinkFlags; linkFlags += targetLinkFlags;
@ -1653,12 +1653,11 @@ std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib)
* to the name of the library. This will not link a library against itself. * to the name of the library. This will not link a library against itself.
*/ */
void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout,
cmTarget& tgt, cmGeneratorTarget& tgt,
bool relink) bool relink)
{ {
const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"); const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
cmGeneratorTarget* gtgt = this->GlobalGenerator->GetGeneratorTarget(&tgt); cmComputeLinkInformation* pcli = tgt.GetLinkInformation(config);
cmComputeLinkInformation* pcli = gtgt->GetLinkInformation(config);
if(!pcli) if(!pcli)
{ {
return; return;
@ -1679,7 +1678,7 @@ void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout,
std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_"; std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
linkFlagsVar += linkLanguage; linkFlagsVar += linkLanguage;
linkFlagsVar += "_FLAGS"; linkFlagsVar += "_FLAGS";
if( gtgt->GetType() == cmTarget::EXECUTABLE ) if( tgt.GetType() == cmTarget::EXECUTABLE )
{ {
linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar.c_str()); linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar.c_str());
linkLibs += " "; linkLibs += " ";

View File

@ -335,11 +335,12 @@ public:
void GetTargetFlags(std::string& linkLibs, void GetTargetFlags(std::string& linkLibs,
std::string& flags, std::string& flags,
std::string& linkFlags, std::string& linkFlags,
cmTarget&target); cmGeneratorTarget* target);
protected: protected:
///! put all the libraries for a target on into the given stream ///! put all the libraries for a target on into the given stream
virtual void OutputLinkLibraries(std::ostream&, cmTarget&, bool relink); virtual void OutputLinkLibraries(std::ostream&, cmGeneratorTarget&,
bool relink);
// Expand rule variables in CMake of the type found in language rules // Expand rule variables in CMake of the type found in language rules
void ExpandRuleVariables(std::string& string, void ExpandRuleVariables(std::string& string,

View File

@ -319,7 +319,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// Collect up flags to link in needed libraries. // Collect up flags to link in needed libraries.
cmOStringStream linklibs; cmOStringStream linklibs;
this->LocalGenerator->OutputLinkLibraries(linklibs, *this->Target, relink); this->LocalGenerator->OutputLinkLibraries(linklibs, *this->GeneratorTarget,
relink);
// Construct object file lists that may be needed to expand the // Construct object file lists that may be needed to expand the
// rule. // rule.

View File

@ -546,7 +546,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
if(this->Target->GetType() != cmTarget::STATIC_LIBRARY) if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
{ {
this->LocalGenerator this->LocalGenerator
->OutputLinkLibraries(linklibs, *this->Target, relink); ->OutputLinkLibraries(linklibs, *this->GeneratorTarget, relink);
} }
// Construct object file lists that may be needed to expand the // Construct object file lists that may be needed to expand the

View File

@ -423,7 +423,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
this->GetLocalGenerator()->GetTargetFlags(vars["LINK_LIBRARIES"], this->GetLocalGenerator()->GetTargetFlags(vars["LINK_LIBRARIES"],
vars["FLAGS"], vars["FLAGS"],
vars["LINK_FLAGS"], vars["LINK_FLAGS"],
*this->GetTarget()); this->GetGeneratorTarget());
this->AddModuleDefinitionFlag(vars["LINK_FLAGS"]); this->AddModuleDefinitionFlag(vars["LINK_FLAGS"]);

View File

@ -630,7 +630,8 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
std::string linkLibs; std::string linkLibs;
std::string flags; std::string flags;
std::string linkFlags; std::string linkFlags;
lg->GetTargetFlags(linkLibs, flags, linkFlags, *tgt); cmGeneratorTarget gtgt(tgt);
lg->GetTargetFlags(linkLibs, flags, linkFlags, &gtgt);
printf("%s\n", linkLibs.c_str() ); printf("%s\n", linkLibs.c_str() );