diff options
author | David Cole <david.cole@kitware.com> | 2012-05-01 18:09:59 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2012-05-01 18:09:59 (GMT) |
commit | 8df7aa54f0f78d48e4ed91001ac9ac9d39dbf535 (patch) | |
tree | cfde4039510819e096c2bf197cfdc6e7827b6b0d /Source | |
parent | d05e12bc166d4285ccd5e961bd48cc6eb95bc77f (diff) | |
parent | fdb3f878fec158ab284130a55849ada9edbd6fd1 (diff) | |
download | CMake-8df7aa54f0f78d48e4ed91001ac9ac9d39dbf535.zip CMake-8df7aa54f0f78d48e4ed91001ac9ac9d39dbf535.tar.gz CMake-8df7aa54f0f78d48e4ed91001ac9ac9d39dbf535.tar.bz2 |
Merge topic 'module-no-soname'
fdb3f87 Test NO_SONAME property (#13155)
e1409ac Support building shared libraries or modules without soname (#13155)
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmExportFileGenerator.cxx | 16 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 34 | ||||
-rw-r--r-- | Source/cmLocalGenerator.h | 1 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 8 | ||||
-rw-r--r-- | Source/cmMakefile.h | 3 | ||||
-rw-r--r-- | Source/cmMakefileLibraryTargetGenerator.cxx | 6 | ||||
-rw-r--r-- | Source/cmNinjaNormalTargetGenerator.cxx | 26 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 39 | ||||
-rw-r--r-- | Source/cmTarget.h | 3 |
9 files changed, 90 insertions, 46 deletions
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index c4f5dfb..eb19df5e 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -137,10 +137,20 @@ cmExportFileGenerator (mf->IsOn("WIN32") || mf->IsOn("CYGWIN") || mf->IsOn("MINGW")); if(!dll_platform) { - std::string soname = target->GetSOName(config); - std::string prop = "IMPORTED_SONAME"; + std::string prop; + std::string value; + if(target->HasSOName(config)) + { + prop = "IMPORTED_SONAME"; + value = target->GetSOName(config); + } + else + { + prop = "IMPORTED_NO_SONAME"; + value = "TRUE"; + } prop += suffix; - properties[prop] = soname; + properties[prop] = value; } } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 13ede5d..6362d80 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -954,29 +954,27 @@ cmLocalGenerator::ExpandRuleVariable(std::string const& variable, } } } - if(replaceValues.TargetSOName) + if(variable == "TARGET_SONAME" || variable == "SONAME_FLAG" || + variable == "TARGET_INSTALLNAME_DIR") { - if(variable == "TARGET_SONAME") + // All these variables depend on TargetSOName + if(replaceValues.TargetSOName) { - if(replaceValues.Language) + if(variable == "TARGET_SONAME") { - std::string name = "CMAKE_SHARED_LIBRARY_SONAME_"; - name += replaceValues.Language; - name += "_FLAG"; - if(this->Makefile->GetDefinition(name.c_str())) - { - return replaceValues.TargetSOName; - } + return replaceValues.TargetSOName; + } + if(variable == "SONAME_FLAG" && replaceValues.SONameFlag) + { + return replaceValues.SONameFlag; + } + if(replaceValues.TargetInstallNameDir && + variable == "TARGET_INSTALLNAME_DIR") + { + return replaceValues.TargetInstallNameDir; } - return ""; - } - } - if(replaceValues.TargetInstallNameDir) - { - if(variable == "TARGET_INSTALLNAME_DIR") - { - return replaceValues.TargetInstallNameDir; } + return ""; } if(replaceValues.LinkLibraries) { diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 3e93819..cb84a30 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -228,6 +228,7 @@ public: const char* ObjectDir; const char* Flags; const char* ObjectsQuoted; + const char* SONameFlag; const char* TargetSOName; const char* TargetInstallNameDir; const char* LinkFlags; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 17bb5ed..0a709ae 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2195,6 +2195,14 @@ bool cmMakefile::PlatformIs64Bit() const return false; } +const char* cmMakefile::GetSONameFlag(const char* language) const +{ + std::string name = "CMAKE_SHARED_LIBRARY_SONAME_"; + name += language; + name += "_FLAG"; + return GetDefinition(name.c_str()); +} + bool cmMakefile::CanIWriteThisFile(const char* fileName) { if ( !this->IsOn("CMAKE_DISABLE_SOURCE_CHANGES") ) diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 8b3bef7..9fc64d6 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -595,6 +595,9 @@ public: /** Return whether the target platform is 64-bit. */ bool PlatformIs64Bit() const; + /** Retrieve soname flag for the specified language if supported */ + const char* GetSONameFlag(const char* language) const; + /** * Get a list of preprocessor define flags. */ diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 38aa59d..db59ffd 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -714,7 +714,11 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules std::string linkString = linklibs.str(); vars.LinkLibraries = linkString.c_str(); vars.ObjectsQuoted = buildObjs.c_str(); - vars.TargetSOName= targetNameSO.c_str(); + if (this->Target->HasSOName(this->ConfigName)) + { + vars.SONameFlag = this->Makefile->GetSONameFlag(linkLanguage); + vars.TargetSOName= targetNameSO.c_str(); + } vars.LinkFlags = linkFlags.c_str(); // Compute the directory portion of the install_name setting. diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index cf2b427..63ba58d 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -166,6 +166,7 @@ cmNinjaNormalTargetGenerator cmLocalGenerator::SHELL); vars.ObjectDir = objdir.c_str(); vars.Target = "$out"; + vars.SONameFlag = "$SONAME_FLAG"; vars.TargetSOName = "$SONAME"; vars.TargetInstallNameDir = "$INSTALLNAME_DIR"; vars.TargetPDB = "$TARGET_PDB"; @@ -380,17 +381,20 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() this->GetTarget(), this->TargetLinkLanguage, this->GetConfigName()); - vars["SONAME"] = this->TargetNameSO; - - if (targetType == cmTarget::SHARED_LIBRARY) { - std::string install_name_dir = - this->GetTarget()->GetInstallNameDirForBuildTree(this->GetConfigName()); - - if (!install_name_dir.empty()) { - vars["INSTALLNAME_DIR"] = - this->GetLocalGenerator()->Convert(install_name_dir.c_str(), - cmLocalGenerator::NONE, - cmLocalGenerator::SHELL, false); + if (this->GetTarget()->HasSOName(this->GetConfigName())) { + vars["SONAME_FLAG"] = + this->GetMakefile()->GetSONameFlag(this->TargetLinkLanguage); + vars["SONAME"] = this->TargetNameSO; + if (targetType == cmTarget::SHARED_LIBRARY) { + std::string install_name_dir = this->GetTarget() + ->GetInstallNameDirForBuildTree(this->GetConfigName()); + + if (!install_name_dir.empty()) { + vars["INSTALLNAME_DIR"] = + this->GetLocalGenerator()->Convert(install_name_dir.c_str(), + cmLocalGenerator::NONE, + cmLocalGenerator::SHELL, false); + } } } 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, diff --git a/Source/cmTarget.h b/Source/cmTarget.h index d41c827..d70cacd 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -347,6 +347,9 @@ public: /** Get the name of the pdb file for the target. */ std::string GetPDBName(const char* config=0); + /** Whether this library has soname enabled and platform supports it. */ + bool HasSOName(const char* config); + /** Get the soname of the target. Allowed only for a shared library. */ std::string GetSOName(const char* config); |