cmGeneratorTarget: Move HasMacOSXRpathInstallNameDir from cmTarget.

This commit is contained in:
Stephen Kelly 2015-08-05 19:07:03 +02:00
parent c5718217ad
commit e73916992c
6 changed files with 128 additions and 124 deletions

View File

@ -1783,12 +1783,13 @@ void
cmComputeLinkInformation::AddLibraryRuntimeInfo(std::string const& fullPath, cmComputeLinkInformation::AddLibraryRuntimeInfo(std::string const& fullPath,
cmTarget const* target) cmTarget const* target)
{ {
cmGeneratorTarget *gtgt = this->GlobalGenerator->GetGeneratorTarget(target);
// Ignore targets on Apple where install_name is not @rpath. // Ignore targets on Apple where install_name is not @rpath.
// The dependenty library can be found with other means such as // The dependenty library can be found with other means such as
// @loader_path or full paths. // @loader_path or full paths.
if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
{ {
if(!target->HasMacOSXRpathInstallNameDir(this->Config)) if(!gtgt->HasMacOSXRpathInstallNameDir(this->Config))
{ {
return; return;
} }
@ -1810,7 +1811,6 @@ cmComputeLinkInformation::AddLibraryRuntimeInfo(std::string const& fullPath,
// Try to get the soname of the library. Only files with this name // Try to get the soname of the library. Only files with this name
// could possibly conflict. // could possibly conflict.
cmGeneratorTarget *gtgt = this->GlobalGenerator->GetGeneratorTarget(target);
std::string soName = gtgt->GetSOName(this->Config); std::string soName = gtgt->GetSOName(this->Config);
const char* soname = soName.empty()? 0 : soName.c_str(); const char* soname = soName.empty()? 0 : soName.c_str();

View File

@ -1283,6 +1283,120 @@ bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
} }
//----------------------------------------------------------------------------
bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir(
const std::string& config) const
{
bool install_name_is_rpath = false;
bool macosx_rpath = false;
if(!this->IsImported())
{
if(this->GetType() != cmTarget::SHARED_LIBRARY)
{
return false;
}
const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
bool use_install_name =
this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
if(install_name && use_install_name &&
std::string(install_name) == "@rpath")
{
install_name_is_rpath = true;
}
else if(install_name && use_install_name)
{
return false;
}
if(!install_name_is_rpath)
{
macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
}
}
else
{
// Lookup the imported soname.
if(cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config))
{
if(!info->NoSOName && !info->SOName.empty())
{
if(info->SOName.find("@rpath/") == 0)
{
install_name_is_rpath = true;
}
}
else
{
std::string install_name;
cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
if(install_name.find("@rpath") != std::string::npos)
{
install_name_is_rpath = true;
}
}
}
}
if(!install_name_is_rpath && !macosx_rpath)
{
return false;
}
if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
{
std::ostringstream w;
w << "Attempting to use";
if(macosx_rpath)
{
w << " MACOSX_RPATH";
}
else
{
w << " @rpath";
}
w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
w << " This could be because you are using a Mac OS X version";
w << " less than 10.5 or because CMake's platform configuration is";
w << " corrupt.";
cmake* cm = this->Makefile->GetCMakeInstance();
cm->IssueMessage(cmake::FATAL_ERROR, w.str(),
this->Target->GetBacktrace());
}
return true;
}
//----------------------------------------------------------------------------
bool cmGeneratorTarget::MacOSXRpathInstallNameDirDefault() const
{
// we can't do rpaths when unsupported
if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
{
return false;
}
const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
if(macosx_rpath_str)
{
return this->GetPropertyAsBool("MACOSX_RPATH");
}
cmPolicies::PolicyStatus cmp0042 = this->Target->GetPolicyStatusCMP0042();
if(cmp0042 == cmPolicies::WARN)
{
this->Makefile->GetGlobalGenerator()->
AddCMP0042WarnTarget(this->GetName());
}
if(cmp0042 == cmPolicies::NEW)
{
return true;
}
return false;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmGeneratorTarget::GetSOName(const std::string& config) const std::string cmGeneratorTarget::GetSOName(const std::string& config) const
{ {
@ -1428,7 +1542,7 @@ cmGeneratorTarget::GetInstallNameDirForBuildTree(
!this->GetPropertyAsBool("SKIP_BUILD_RPATH")) !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
{ {
std::string dir; std::string dir;
if(this->Target->MacOSXRpathInstallNameDirDefault()) if(this->MacOSXRpathInstallNameDirDefault())
{ {
dir = "@rpath"; dir = "@rpath";
} }
@ -1464,7 +1578,7 @@ std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
} }
if(!install_name_dir) if(!install_name_dir)
{ {
if(this->Target->MacOSXRpathInstallNameDirDefault()) if(this->MacOSXRpathInstallNameDirDefault())
{ {
dir = "@rpath/"; dir = "@rpath/";
} }

View File

@ -409,6 +409,12 @@ public:
bool HaveInstallTreeRPATH() const; bool HaveInstallTreeRPATH() const;
/** Whether this library has \@rpath and platform supports it. */
bool HasMacOSXRpathInstallNameDir(const std::string& config) const;
/** Whether this library defaults to \@rpath. */
bool MacOSXRpathInstallNameDirDefault() const;
private: private:
friend class cmTargetTraceDependencies; friend class cmTargetTraceDependencies;
struct SourceEntry { std::vector<cmSourceFile*> Depends; }; struct SourceEntry { std::vector<cmSourceFile*> Depends; };

View File

@ -56,7 +56,8 @@ void cmLocalXCodeGenerator::Generate()
iter != targets.end(); ++iter) iter != targets.end(); ++iter)
{ {
cmTarget* t = &iter->second; cmTarget* t = &iter->second;
t->HasMacOSXRpathInstallNameDir(""); cmGeneratorTarget* gt = this->GlobalGenerator->GetGeneratorTarget(t);
gt->HasMacOSXRpathInstallNameDir("");
} }
} }
@ -70,7 +71,8 @@ void cmLocalXCodeGenerator::GenerateInstallRules()
iter != targets.end(); ++iter) iter != targets.end(); ++iter)
{ {
cmTarget* t = &iter->second; cmTarget* t = &iter->second;
t->HasMacOSXRpathInstallNameDir(""); cmGeneratorTarget* gt = this->GlobalGenerator->GetGeneratorTarget(t);
gt->HasMacOSXRpathInstallNameDir("");
} }
} }

View File

@ -2177,118 +2177,6 @@ const char* cmTarget::GetPrefixVariableInternal(bool implib) const
return ""; return "";
} }
//----------------------------------------------------------------------------
bool cmTarget::HasMacOSXRpathInstallNameDir(const std::string& config) const
{
bool install_name_is_rpath = false;
bool macosx_rpath = false;
if(!this->IsImportedTarget)
{
if(this->GetType() != cmTarget::SHARED_LIBRARY)
{
return false;
}
const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
bool use_install_name =
this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
if(install_name && use_install_name &&
std::string(install_name) == "@rpath")
{
install_name_is_rpath = true;
}
else if(install_name && use_install_name)
{
return false;
}
if(!install_name_is_rpath)
{
macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
}
}
else
{
// Lookup the imported soname.
if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
{
if(!info->NoSOName && !info->SOName.empty())
{
if(info->SOName.find("@rpath/") == 0)
{
install_name_is_rpath = true;
}
}
else
{
std::string install_name;
cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
if(install_name.find("@rpath") != std::string::npos)
{
install_name_is_rpath = true;
}
}
}
}
if(!install_name_is_rpath && !macosx_rpath)
{
return false;
}
if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
{
std::ostringstream w;
w << "Attempting to use";
if(macosx_rpath)
{
w << " MACOSX_RPATH";
}
else
{
w << " @rpath";
}
w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
w << " This could be because you are using a Mac OS X version";
w << " less than 10.5 or because CMake's platform configuration is";
w << " corrupt.";
cmake* cm = this->Makefile->GetCMakeInstance();
cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
}
return true;
}
//----------------------------------------------------------------------------
bool cmTarget::MacOSXRpathInstallNameDirDefault() const
{
// we can't do rpaths when unsupported
if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
{
return false;
}
const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
if(macosx_rpath_str)
{
return this->GetPropertyAsBool("MACOSX_RPATH");
}
cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
if(cmp0042 == cmPolicies::WARN)
{
this->Makefile->GetGlobalGenerator()->
AddCMP0042WarnTarget(this->GetName());
}
if(cmp0042 == cmPolicies::NEW)
{
return true;
}
return false;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmTarget::IsImportedSharedLibWithoutSOName( bool cmTarget::IsImportedSharedLibWithoutSOName(
const std::string& config) const const std::string& config) const

View File

@ -244,12 +244,6 @@ public:
void void
GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const; GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const;
/** Whether this library has \@rpath and platform supports it. */
bool HasMacOSXRpathInstallNameDir(const std::string& config) const;
/** Whether this library defaults to \@rpath. */
bool MacOSXRpathInstallNameDirDefault() const;
/** Test for special case of a third-party shared library that has /** Test for special case of a third-party shared library that has
no soname at all. */ no soname at all. */
bool IsImportedSharedLibWithoutSOName(const std::string& config) const; bool IsImportedSharedLibWithoutSOName(const std::string& config) const;