Make cmLocalGenerator::AddArchitectureFlags take a cmGeneratorTarget.

This commit is contained in:
Stephen Kelly 2012-09-16 01:16:43 +02:00
parent 4f5384e75c
commit 78bfee35d5
13 changed files with 56 additions and 49 deletions

View File

@ -315,3 +315,24 @@ cmGeneratorTarget::GetLinkInformation(const char* config)
} }
return i->second; return i->second;
} }
//----------------------------------------------------------------------------
void cmGeneratorTarget::GetAppleArchs(const char* config,
std::vector<std::string>& archVec)
{
const char* archs = 0;
if(config && *config)
{
std::string defVarName = "OSX_ARCHITECTURES_";
defVarName += cmSystemTools::UpperCase(config);
archs = this->Target->GetProperty(defVarName.c_str());
}
if(!archs)
{
archs = this->Target->GetProperty("OSX_ARCHITECTURES");
}
if(archs)
{
cmSystemTools::ExpandListArgument(std::string(archs), archVec);
}
}

View File

@ -67,6 +67,8 @@ public:
cmComputeLinkInformation* GetLinkInformation(const char* config); cmComputeLinkInformation* GetLinkInformation(const char* config);
void GetAppleArchs(const char* config,
std::vector<std::string>& archVec);
private: private:
void ClassifySources(); void ClassifySources();
void LookupObjectLibraries(); void LookupObjectLibraries();

View File

@ -1713,7 +1713,10 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
// Set target-specific architectures. // Set target-specific architectures.
std::vector<std::string> archs; std::vector<std::string> archs;
target.GetAppleArchs(configName, archs); {
cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target);
gtgt->GetAppleArchs(configName, archs);
}
if(!archs.empty()) if(!archs.empty())
{ {
// Enable ARCHS attribute. // Enable ARCHS attribute.

View File

@ -557,7 +557,7 @@ void cmLocalGenerator::GenerateTargetManifest()
void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname, void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
const char* lang, const char* lang,
cmSourceFile& source, cmSourceFile& source,
cmTarget& target) cmGeneratorTarget& target)
{ {
std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname)); std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname));
objectDir = this->Convert(objectDir.c_str(),START_OUTPUT,SHELL); objectDir = this->Convert(objectDir.c_str(),START_OUTPUT,SHELL);
@ -577,7 +577,7 @@ void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
flags += " "; flags += " ";
{ {
std::vector<std::string> includes; std::vector<std::string> includes;
this->GetIncludeDirectories(includes, &target, lang); this->GetIncludeDirectories(includes, target.Target, lang);
flags += this->GetIncludeFlags(includes, lang); flags += this->GetIncludeFlags(includes, lang);
} }
flags += this->Makefile->GetDefineFlags(); flags += this->Makefile->GetDefineFlags();
@ -636,7 +636,8 @@ void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
); );
} }
void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target) void cmLocalGenerator::AddBuildTargetRule(const char* llang,
cmGeneratorTarget& target)
{ {
cmStdString objs; cmStdString objs;
std::vector<std::string> objVector; std::vector<std::string> objVector;
@ -669,8 +670,8 @@ void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
} }
std::string createRule = "CMAKE_"; std::string createRule = "CMAKE_";
createRule += llang; createRule += llang;
createRule += target.GetCreateRuleVariable(); createRule += target.Target->GetCreateRuleVariable();
std::string targetName = target.GetFullName(); std::string targetName = target.Target->GetFullName();
// Executable : // Executable :
// Shared Library: // Shared Library:
// Static Library: // Static Library:
@ -678,7 +679,7 @@ void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
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); this->GetTargetFlags(linkLibs, flags, linkFlags, *target.Target);
cmLocalGenerator::RuleVariables vars; cmLocalGenerator::RuleVariables vars;
vars.Language = llang; vars.Language = llang;
vars.Objects = objs.c_str(); vars.Objects = objs.c_str();
@ -715,7 +716,7 @@ void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
// Store this command line. // Store this command line.
commandLines.push_back(commandLine); commandLines.push_back(commandLine);
} }
std::string targetFullPath = target.GetFullPath(); std::string targetFullPath = target.Target->GetFullPath();
// Generate a meaningful comment for the command. // Generate a meaningful comment for the command.
std::string comment = "Linking "; std::string comment = "Linking ";
comment += llang; comment += llang;
@ -729,7 +730,7 @@ void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
comment.c_str(), comment.c_str(),
this->Makefile->GetStartOutputDirectory() this->Makefile->GetStartOutputDirectory()
); );
target.AddSourceFile target.Target->AddSourceFile
(this->Makefile->GetSource(targetFullPath.c_str())); (this->Makefile->GetSource(targetFullPath.c_str()));
} }
@ -737,11 +738,11 @@ void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
void cmLocalGenerator void cmLocalGenerator
::CreateCustomTargetsAndCommands(std::set<cmStdString> const& lang) ::CreateCustomTargetsAndCommands(std::set<cmStdString> const& lang)
{ {
cmTargets &tgts = this->Makefile->GetTargets(); cmGeneratorTargetsType tgts = this->Makefile->GetGeneratorTargets();
for(cmTargets::iterator l = tgts.begin(); for(cmGeneratorTargetsType::iterator l = tgts.begin();
l != tgts.end(); l++) l != tgts.end(); l++)
{ {
cmTarget& target = l->second; cmGeneratorTarget& target = *l->second;
switch(target.GetType()) switch(target.GetType())
{ {
case cmTarget::STATIC_LIBRARY: case cmTarget::STATIC_LIBRARY:
@ -749,12 +750,12 @@ void cmLocalGenerator
case cmTarget::MODULE_LIBRARY: case cmTarget::MODULE_LIBRARY:
case cmTarget::EXECUTABLE: case cmTarget::EXECUTABLE:
{ {
const char* llang = target.GetLinkerLanguage(); const char* llang = target.Target->GetLinkerLanguage();
if(!llang) if(!llang)
{ {
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;
} }
// if the language is not in the set lang then create custom // if the language is not in the set lang then create custom
@ -1780,7 +1781,7 @@ void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmLocalGenerator::AddArchitectureFlags(std::string& flags, void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
cmTarget* target, cmGeneratorTarget* target,
const char *lang, const char *lang,
const char* config) const char* config)
{ {

View File

@ -16,6 +16,7 @@
class cmMakefile; class cmMakefile;
class cmGlobalGenerator; class cmGlobalGenerator;
class cmGeneratorTarget;
class cmTarget; class cmTarget;
class cmTargetManifest; class cmTargetManifest;
class cmSourceFile; class cmSourceFile;
@ -135,7 +136,7 @@ public:
std::vector<cmLocalGenerator*>& GetChildren() { return this->Children; }; std::vector<cmLocalGenerator*>& GetChildren() { return this->Children; };
void AddArchitectureFlags(std::string& flags, cmTarget* target, void AddArchitectureFlags(std::string& flags, cmGeneratorTarget* target,
const char *lang, const char* config); const char *lang, const char* config);
void AddLanguageFlags(std::string& flags, const char* lang, void AddLanguageFlags(std::string& flags, const char* lang,
@ -354,12 +355,12 @@ 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, cmTarget& target); void AddBuildTargetRule(const char* 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 char* lang,
cmSourceFile& source, cmSourceFile& source,
cmTarget& target); cmGeneratorTarget& target);
// Create Custom Targets and commands for unsupported languages // Create Custom Targets and commands for unsupported languages
// The set passed in should contain the languages supported by the // The set passed in should contain the languages supported by the
// generator directly. Any targets containing files that are not // generator directly. Any targets containing files that are not

View File

@ -210,7 +210,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// Add language feature flags. // Add language feature flags.
this->AddFeatureFlags(flags, linkLanguage); this->AddFeatureFlags(flags, linkLanguage);
this->LocalGenerator->AddArchitectureFlags(flags, this->Target, this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget,
linkLanguage, this->ConfigName); linkLanguage, this->ConfigName);
// Add target-specific linker flags. // Add target-specific linker flags.

View File

@ -625,7 +625,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
std::string langFlags; std::string langFlags;
this->AddFeatureFlags(langFlags, linkLanguage); this->AddFeatureFlags(langFlags, linkLanguage);
this->LocalGenerator->AddArchitectureFlags(langFlags, this->Target, this->LocalGenerator->AddArchitectureFlags(langFlags, this->GeneratorTarget,
linkLanguage, this->ConfigName); linkLanguage, this->ConfigName);
// remove any language flags that might not work with the // remove any language flags that might not work with the

View File

@ -259,7 +259,7 @@ std::string cmMakefileTargetGenerator::GetFlags(const std::string &l)
// Add language feature flags. // Add language feature flags.
this->AddFeatureFlags(flags, lang); this->AddFeatureFlags(flags, lang);
this->LocalGenerator->AddArchitectureFlags(flags, this->Target, this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget,
lang, this->ConfigName); lang, this->ConfigName);
// Fortran-specific flags computed for this target. // Fortran-specific flags computed for this target.

View File

@ -434,7 +434,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
? vars["FLAGS"] ? vars["FLAGS"]
: vars["ARCH_FLAGS"]); : vars["ARCH_FLAGS"]);
this->GetLocalGenerator()->AddArchitectureFlags(flags, this->GetLocalGenerator()->AddArchitectureFlags(flags,
this->GetTarget(), this->GetGeneratorTarget(),
this->TargetLinkLanguage, this->TargetLinkLanguage,
this->GetConfigName()); this->GetConfigName());
if (targetType == cmTarget::EXECUTABLE) { if (targetType == cmTarget::EXECUTABLE) {

View File

@ -134,7 +134,7 @@ cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile *source,
this->AddFeatureFlags(flags, language.c_str()); this->AddFeatureFlags(flags, language.c_str());
this->GetLocalGenerator()->AddArchitectureFlags(flags, this->GetLocalGenerator()->AddArchitectureFlags(flags,
this->GetTarget(), this->GeneratorTarget,
language.c_str(), language.c_str(),
this->GetConfigName()); this->GetConfigName());

View File

@ -52,6 +52,9 @@ protected:
cmTarget* GetTarget() const cmTarget* GetTarget() const
{ return this->Target; } { return this->Target; }
cmGeneratorTarget* GetGeneratorTarget() const
{ return this->GeneratorTarget; }
cmLocalNinjaGenerator* GetLocalGenerator() const cmLocalNinjaGenerator* GetLocalGenerator() const
{ return this->LocalGenerator; } { return this->LocalGenerator; }

View File

@ -3908,27 +3908,6 @@ void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
} }
} }
//----------------------------------------------------------------------------
void cmTarget::GetAppleArchs(const char* config,
std::vector<std::string>& archVec)
{
const char* archs = 0;
if(config && *config)
{
std::string defVarName = "OSX_ARCHITECTURES_";
defVarName += cmSystemTools::UpperCase(config);
archs = this->GetProperty(defVarName.c_str());
}
if(!archs)
{
archs = this->GetProperty("OSX_ARCHITECTURES");
}
if(archs)
{
cmSystemTools::ExpandListArgument(std::string(archs), archVec);
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmTarget::IsChrpathUsed(const char* config) bool cmTarget::IsChrpathUsed(const char* config)
{ {

View File

@ -404,9 +404,6 @@ public:
// until we have per-target object file properties. // until we have per-target object file properties.
void GetLanguages(std::set<cmStdString>& languages) const; void GetLanguages(std::set<cmStdString>& languages) const;
/** Get the list of OS X target architectures to be built. */
void GetAppleArchs(const char* config, std::vector<std::string>& archVec);
/** Return whether this target is an executable with symbol exports /** Return whether this target is an executable with symbol exports
enabled. */ enabled. */
bool IsExecutableWithExports(); bool IsExecutableWithExports();