From 1f2b39c6ce390570ab3918b5e1169619394bb669 Mon Sep 17 00:00:00 2001 From: Bruce Stephens Date: Sat, 20 Feb 2016 19:35:18 +0000 Subject: [PATCH 1/2] cmCommonTargetGenerator: Adopt AppendOSXVerFlag method Move this method from cmMakefileLibraryTargetGenerator so it can be re-used for the Ninja generator too. Signed-off-by: Bruce Stephens --- Source/cmCommonTargetGenerator.cxx | 32 +++++++++++++++++++ Source/cmCommonTargetGenerator.h | 3 ++ Source/cmMakefileLibraryTargetGenerator.cxx | 34 --------------------- Source/cmMakefileLibraryTargetGenerator.h | 3 -- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index 76ed0387c..b5688a803 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -426,3 +426,35 @@ std::string cmCommonTargetGenerator::GetManifests() return cmJoin(manifests, " "); } + +void cmCommonTargetGenerator +::AppendOSXVerFlag(std::string& flags, const std::string& lang, + const char* name, bool so) +{ + // Lookup the flag to specify the version. + std::string fvar = "CMAKE_"; + fvar += lang; + fvar += "_OSX_"; + fvar += name; + fvar += "_VERSION_FLAG"; + const char* flag = this->Makefile->GetDefinition(fvar); + + // Skip if no such flag. + if(!flag) + { + return; + } + + // Lookup the target version information. + int major; + int minor; + int patch; + this->GeneratorTarget->GetTargetVersion(so, major, minor, patch); + if(major > 0 || minor > 0 || patch > 0) + { + // Append the flag since a non-zero version is specified. + std::ostringstream vflag; + vflag << flag << major << "." << minor << "." << patch; + this->LocalGenerator->AppendFlags(flags, vflag.str()); + } +} diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h index 0c1750012..bfb6b7926 100644 --- a/Source/cmCommonTargetGenerator.h +++ b/Source/cmCommonTargetGenerator.h @@ -79,6 +79,9 @@ protected: virtual void AddIncludeFlags(std::string& flags, std::string const& lang) = 0; + void AppendOSXVerFlag(std::string& flags, const std::string& lang, + const char* name, bool so); + typedef std::map ByLanguageMap; std::string GetFlags(const std::string &l); ByLanguageMap FlagsByLanguage; diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 1923ea4fb..435844e31 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -841,37 +841,3 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules this->CleanFiles.insert(this->CleanFiles.end(), libCleanFiles.begin(),libCleanFiles.end()); } - -//---------------------------------------------------------------------------- -void -cmMakefileLibraryTargetGenerator -::AppendOSXVerFlag(std::string& flags, const std::string& lang, - const char* name, bool so) -{ - // Lookup the flag to specify the version. - std::string fvar = "CMAKE_"; - fvar += lang; - fvar += "_OSX_"; - fvar += name; - fvar += "_VERSION_FLAG"; - const char* flag = this->Makefile->GetDefinition(fvar); - - // Skip if no such flag. - if(!flag) - { - return; - } - - // Lookup the target version information. - int major; - int minor; - int patch; - this->GeneratorTarget->GetTargetVersion(so, major, minor, patch); - if(major > 0 || minor > 0 || patch > 0) - { - // Append the flag since a non-zero version is specified. - std::ostringstream vflag; - vflag << flag << major << "." << minor << "." << patch; - this->LocalGenerator->AppendFlags(flags, vflag.str()); - } -} diff --git a/Source/cmMakefileLibraryTargetGenerator.h b/Source/cmMakefileLibraryTargetGenerator.h index 68980c3ff..009f15d61 100644 --- a/Source/cmMakefileLibraryTargetGenerator.h +++ b/Source/cmMakefileLibraryTargetGenerator.h @@ -38,9 +38,6 @@ protected: // Store the computd framework version for OS X Frameworks. std::string FrameworkVersion; - - void AppendOSXVerFlag(std::string& flags, const std::string& lang, - const char* name, bool so); }; #endif From 9e165a64addbf997d5af58caccd2c93ec2c77a95 Mon Sep 17 00:00:00 2001 From: Bruce Stephens Date: Sat, 20 Feb 2016 19:35:18 +0000 Subject: [PATCH 2/2] Ninja: Add OS X dylib versioning (#14140) Teach the Ninja generator to add the `-current_version` and the `-compatibility_version` flags based on the VERSION and SOVERSION target properties just as the Makefile generators do. Signed-off-by: Bruce Stephens --- Source/cmNinjaNormalTargetGenerator.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 17561b5ab..c34df3cb1 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -504,6 +504,16 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() } } + // Add OS X version flags, if any. + if(this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY || + this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY) + { + this->AppendOSXVerFlag(vars["LINK_FLAGS"], this->TargetLinkLanguage, + "COMPATIBILITY", true); + this->AppendOSXVerFlag(vars["LINK_FLAGS"], this->TargetLinkLanguage, + "CURRENT", false); + } + this->addPoolNinjaVariable("JOB_POOL_LINK", >, vars); this->AddModuleDefinitionFlag(vars["LINK_FLAGS"]);