cmGeneratorTarget: Move NeedRelinkBeforeInstall from cmTarget.

This commit is contained in:
Stephen Kelly 2015-08-04 19:19:46 +02:00
parent 3df705681b
commit 8d2de00244
9 changed files with 80 additions and 78 deletions

View File

@ -713,6 +713,73 @@ bool cmGeneratorTarget::HasSOName(const std::string& config) const
this->Target->GetLinkerLanguage(config)));
}
//----------------------------------------------------------------------------
bool
cmGeneratorTarget::NeedRelinkBeforeInstall(const std::string& config) const
{
// Only executables and shared libraries can have an rpath and may
// need relinking.
if(this->GetType() != cmTarget::EXECUTABLE &&
this->GetType() != cmTarget::SHARED_LIBRARY &&
this->GetType() != cmTarget::MODULE_LIBRARY)
{
return false;
}
// If there is no install location this target will not be installed
// and therefore does not need relinking.
if(!this->Target->GetHaveInstallRule())
{
return false;
}
// If skipping all rpaths completely then no relinking is needed.
if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
{
return false;
}
// If building with the install-tree rpath no relinking is needed.
if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
{
return false;
}
// If chrpath is going to be used no relinking is needed.
if(this->Target->IsChrpathUsed(config))
{
return false;
}
// Check for rpath support on this platform.
std::string ll = this->Target->GetLinkerLanguage(config);
if(!ll.empty())
{
std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
flagVar += ll;
flagVar += "_FLAG";
if(!this->Makefile->IsSet(flagVar))
{
// There is no rpath support on this platform so nothing needs
// relinking.
return false;
}
}
else
{
// No linker language is known. This error will be reported by
// other code.
return false;
}
// If either a build or install tree rpath is set then the rpath
// will likely change between the build tree and install tree and
// this target must be relinked.
return this->Target->HaveBuildTreeRPATH(config)
|| this->Target->HaveInstallTreeRPATH();
}
//----------------------------------------------------------------------------
std::string cmGeneratorTarget::GetSOName(const std::string& config) const
{

View File

@ -210,6 +210,11 @@ public:
std::string& realName, std::string& impName,
std::string& pdbName, const std::string& config) const;
/**
* Compute whether this target must be relinked before installing.
*/
bool NeedRelinkBeforeInstall(const std::string& config) const;
struct SourceFileFlags
GetTargetSourceFileFlags(const cmSourceFile* sf) const;

View File

@ -482,7 +482,7 @@ cmGlobalUnixMakefileGenerator3
// Add this to the list of depends rules in this directory.
if((!check_all || !gtarget->GetPropertyAsBool("EXCLUDE_FROM_ALL")) &&
(!check_relink ||
gtarget->Target
gtarget
->NeedRelinkBeforeInstall(lg->GetConfigName())))
{
std::string tname = lg->GetRelativeTargetDirectory(*gtarget->Target);
@ -691,7 +691,7 @@ cmGlobalUnixMakefileGenerator3
// Add a local name for the rule to relink the target before
// installation.
if(gtarget->Target
if(gtarget
->NeedRelinkBeforeInstall(lg->GetConfigName()))
{
makeTargetName = lg->GetRelativeTargetDirectory(*gtarget->Target);
@ -876,7 +876,7 @@ cmGlobalUnixMakefileGenerator3
name, depends, commands, true);
// Add rules to prepare the target for installation.
if(gtarget->Target
if(gtarget
->NeedRelinkBeforeInstall(lg->GetConfigName()))
{
localName = lg->GetRelativeTargetDirectory(*gtarget->Target);

View File

@ -73,7 +73,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os,
{
// Compute the build tree directory from which to copy the target.
std::string fromDirConfig;
if(this->Target->Target->NeedRelinkBeforeInstall(config))
if(this->Target->NeedRelinkBeforeInstall(config))
{
fromDirConfig =
this->Target->Target->GetMakefile()->GetCurrentBinaryDirectory();

View File

@ -486,8 +486,7 @@ void cmLocalUnixMakefileGenerator3
// Add a local name for the rule to relink the target before
// installation.
if(t->second->Target
->NeedRelinkBeforeInstall(this->ConfigName))
if(t->second->NeedRelinkBeforeInstall(this->ConfigName))
{
makeTargetName = this->GetRelativeTargetDirectory(*t->second->Target);
makeTargetName += "/preinstall";

View File

@ -58,7 +58,7 @@ void cmMakefileExecutableTargetGenerator::WriteRuleFiles()
// write the link rules
this->WriteExecutableRule(false);
if(this->Target->NeedRelinkBeforeInstall(this->ConfigName))
if(this->GeneratorTarget->NeedRelinkBeforeInstall(this->ConfigName))
{
// Write rules to link an installable version of the target.
this->WriteExecutableRule(true);

View File

@ -69,7 +69,7 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
break;
case cmTarget::SHARED_LIBRARY:
this->WriteSharedLibraryRules(false);
if(this->Target->NeedRelinkBeforeInstall(this->ConfigName))
if(this->GeneratorTarget->NeedRelinkBeforeInstall(this->ConfigName))
{
// Write rules to link an installable version of the target.
this->WriteSharedLibraryRules(true);
@ -77,7 +77,7 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
break;
case cmTarget::MODULE_LIBRARY:
this->WriteModuleLibraryRules(false);
if(this->Target->NeedRelinkBeforeInstall(this->ConfigName))
if(this->GeneratorTarget->NeedRelinkBeforeInstall(this->ConfigName))
{
// Write rules to link an installable version of the target.
this->WriteModuleLibraryRules(true);

View File

@ -3854,70 +3854,6 @@ bool cmTarget::HaveInstallTreeRPATH() const
!this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
}
//----------------------------------------------------------------------------
bool cmTarget::NeedRelinkBeforeInstall(const std::string& config) const
{
// Only executables and shared libraries can have an rpath and may
// need relinking.
if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
{
return false;
}
// If there is no install location this target will not be installed
// and therefore does not need relinking.
if(!this->GetHaveInstallRule())
{
return false;
}
// If skipping all rpaths completely then no relinking is needed.
if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
{
return false;
}
// If building with the install-tree rpath no relinking is needed.
if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
{
return false;
}
// If chrpath is going to be used no relinking is needed.
if(this->IsChrpathUsed(config))
{
return false;
}
// Check for rpath support on this platform.
std::string ll = this->GetLinkerLanguage(config);
if(!ll.empty())
{
std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
flagVar += ll;
flagVar += "_FLAG";
if(!this->Makefile->IsSet(flagVar))
{
// There is no rpath support on this platform so nothing needs
// relinking.
return false;
}
}
else
{
// No linker language is known. This error will be reported by
// other code.
return false;
}
// If either a build or install tree rpath is set then the rpath
// will likely change between the build tree and install tree and
// this target must be relinked.
return this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
}
//----------------------------------------------------------------------------
std::string cmTarget::GetInstallNameDirForBuildTree(
const std::string& config) const

View File

@ -395,11 +395,6 @@ public:
bool GetImplibGNUtoMS(std::string const& gnuName, std::string& out,
const char* newExt = 0) const;
/**
* Compute whether this target must be relinked before installing.
*/
bool NeedRelinkBeforeInstall(const std::string& config) const;
bool HaveBuildTreeRPATH(const std::string& config) const;
bool HaveInstallTreeRPATH() const;