summaryrefslogtreecommitdiffstats
path: root/Source/cmTarget.cxx
diff options
context:
space:
mode:
authorModestas Vainius <modax@debian.org>2012-04-22 13:42:55 (GMT)
committerBrad King <brad.king@kitware.com>2012-04-30 15:50:27 (GMT)
commite1409ac59bce76258c054a8ddcaed75425e072b8 (patch)
treec10250abc86e47faa822b3ab05c823b5f39f9f73 /Source/cmTarget.cxx
parent3a503926018fd10ef2120e2c1b98e93afb4fd0c1 (diff)
downloadCMake-e1409ac59bce76258c054a8ddcaed75425e072b8.zip
CMake-e1409ac59bce76258c054a8ddcaed75425e072b8.tar.gz
CMake-e1409ac59bce76258c054a8ddcaed75425e072b8.tar.bz2
Support building shared libraries or modules without soname (#13155)
Add a boolean target property NO_SONAME which may be used to disable soname for the specified shared library or module even if the platform supports it. This property should be useful for private shared libraries or various plugins which live in private directories and have not been designed to be found or loaded globally. Replace references to <CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG> and hard-coded -install_name flags with a conditional <SONAME_FLAG> which is expanded to the value of the CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG definition as long as soname supports is enabled for the target in question. Keep expanding CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG in rules in case third party projects still use it. Such projects would not yet use NO_SONAME so the adjacent <TARGET_SONAME> will always be expanded. Make <TARGET_INSTALLNAME_DIR> NO_SONAME aware as well. Since -install_name is soname on OS X, this should not be a problem if this variable is expanded only if soname is enabled. The Ninja generator performs rule variable substitution only once globally per rule to put its own placeholders. Final substitution is performed by ninja at build time. Therefore we cannot conditionally replace the soname placeholders on a per-target basis. Rather than omitting $SONAME from rules.ninja, simply do not write its contents for targets which have NO_SONAME. Since 3 variables are affected by NO_SONAME ($SONAME, $SONAME_FLAG, $INSTALLNAME_DIR), set them only if soname is enabled.
Diffstat (limited to 'Source/cmTarget.cxx')
-rw-r--r--Source/cmTarget.cxx39
1 files changed, 26 insertions, 13 deletions
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index cfa9976..4789197 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -823,6 +823,19 @@ void cmTarget::DefineProperties(cmake *cm)
"CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
cm->DefineProperty
+ ("NO_SONAME", cmProperty::TARGET,
+ "Whether to set \"soname\" when linking a shared library or module.",
+ "Enable this boolean property if a generated shared library or module "
+ "should not have \"soname\" set. Default is to set \"soname\" on all "
+ "shared libraries and modules as long as the platform supports it. "
+ "Generally, use this property only for leaf private libraries or "
+ "plugins. If you use it on normal shared libraries which other targets "
+ "link against, on some platforms a linker will insert a full path to "
+ "the library (as specified at link time) into the dynamic section of "
+ "the dependant binary. Therefore, once installed, dynamic linker may "
+ "eventually fail to locate the library for the binary.");
+
+ cm->DefineProperty
("SOVERSION", cmProperty::TARGET,
"What version number is this target.",
"For shared libraries VERSION and SOVERSION can be used to specify "
@@ -831,6 +844,7 @@ void cmTarget::DefineProperties(cmake *cm)
"supports symlinks and the linker supports so-names. "
"If only one of both is specified the missing is assumed to have "
"the same version number. "
+ "SOVERSION is ignored if NO_SONAME property is set. "
"For shared libraries and executables on Windows the VERSION "
"attribute is parsed to extract a \"major.minor\" version number. "
"These numbers are used as the image version of the binary. ");
@@ -2995,6 +3009,17 @@ std::string cmTarget::GetPDBName(const char* config)
}
//----------------------------------------------------------------------------
+bool cmTarget::HasSOName(const char* config)
+{
+ // soname is supported only for shared libraries and modules,
+ // and then only when the platform supports an soname flag.
+ return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
+ this->GetType() == cmTarget::MODULE_LIBRARY) &&
+ !this->GetPropertyAsBool("NO_SONAME") &&
+ this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
+}
+
+//----------------------------------------------------------------------------
std::string cmTarget::GetSOName(const char* config)
{
if(this->IsImported())
@@ -3327,22 +3352,10 @@ void cmTarget::GetLibraryNames(std::string& name,
return;
}
- // Construct the name of the soname flag variable for this language.
- const char* ll = this->GetLinkerLanguage(config);
- std::string sonameFlag = "CMAKE_SHARED_LIBRARY_SONAME";
- if(ll)
- {
- sonameFlag += "_";
- sonameFlag += ll;
- }
- sonameFlag += "_FLAG";
-
// Check for library version properties.
const char* version = this->GetProperty("VERSION");
const char* soversion = this->GetProperty("SOVERSION");
- if((this->GetType() != cmTarget::SHARED_LIBRARY &&
- this->GetType() != cmTarget::MODULE_LIBRARY) ||
- !this->Makefile->GetDefinition(sonameFlag.c_str()) ||
+ if(!this->HasSOName(config) ||
this->IsFrameworkOnApple())
{
// Versioning is supported only for shared libraries and modules,