summaryrefslogtreecommitdiffstats
path: root/Source/cmTarget.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2006-02-16 20:19:00 (GMT)
committerBrad King <brad.king@kitware.com>2006-02-16 20:19:00 (GMT)
commit537e2b4ed57d5a84f140f9b9bde427e7b604b330 (patch)
tree8f7869ce7e441cdb2b45d46a235d74ca97cde6f9 /Source/cmTarget.cxx
parent13661cdd23790dd6d8c118ba7b95b278966e7dae (diff)
downloadCMake-537e2b4ed57d5a84f140f9b9bde427e7b604b330.zip
CMake-537e2b4ed57d5a84f140f9b9bde427e7b604b330.tar.gz
CMake-537e2b4ed57d5a84f140f9b9bde427e7b604b330.tar.bz2
ENH: Implemented RPATH specification support. It is documented by the command SET_TARGET_PROPERTIES.
Diffstat (limited to 'Source/cmTarget.cxx')
-rw-r--r--Source/cmTarget.cxx101
1 files changed, 101 insertions, 0 deletions
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 58a40b3..c006bf2 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -44,6 +44,17 @@ void cmTarget::SetType(TargetType type, const char* name)
}
}
+//----------------------------------------------------------------------------
+void cmTarget::SetMakefile(cmMakefile* mf)
+{
+ // Set our makefile.
+ m_Makefile = mf;
+
+ // Setup default property values.
+ this->SetPropertyDefault("INSTALL_RPATH", "");
+ this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
+ this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
+}
void cmTarget::TraceVSDependencies(std::string projFile,
cmMakefile *makefile)
@@ -1309,3 +1320,93 @@ void cmTarget::GetExecutableNamesInternal(std::string& name,
realName += version;
}
}
+
+//----------------------------------------------------------------------------
+void cmTarget::SetPropertyDefault(const char* property,
+ const char* default_value)
+{
+ // Compute the name of the variable holding the default value.
+ std::string var = "CMAKE_";
+ var += property;
+
+ if(const char* value = m_Makefile->GetDefinition(var.c_str()))
+ {
+ this->SetProperty(property, value);
+ }
+ else if(default_value)
+ {
+ this->SetProperty(property, default_value);
+ }
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::HaveBuildTreeRPATH()
+{
+ return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
+ !m_LinkLibraries.empty());
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::HaveInstallTreeRPATH()
+{
+ const char* install_rpath = this->GetProperty("INSTALL_RPATH");
+ return install_rpath && *install_rpath;
+}
+
+//----------------------------------------------------------------------------
+bool cmTarget::NeedRelinkBeforeInstall()
+{
+ // Only executables and shared libraries can have an rpath and may
+ // need relinking.
+ if(m_TargetType != cmTarget::EXECUTABLE &&
+ m_TargetType != cmTarget::SHARED_LIBRARY &&
+ m_TargetType != 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->GetInstallPath().empty())
+ {
+ return false;
+ }
+
+ // If skipping all rpaths completely then no relinking is needed.
+ if(m_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;
+ }
+
+ // Check for rpath support on this platform.
+ if(const char* ll = this->GetLinkerLanguage(
+ m_Makefile->GetLocalGenerator()->GetGlobalGenerator()))
+ {
+ std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
+ flagVar += ll;
+ flagVar += "_FLAG";
+ if(!m_Makefile->IsSet(flagVar.c_str()))
+ {
+ // 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() || this->HaveInstallTreeRPATH();
+}