From 12e4790a0b40d8176940f855f7f6c9cfe6c39f9f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 16 Oct 2015 19:19:51 +0200 Subject: [PATCH] cmGeneratorTarget: Move GetTargetVersion from cmTarget. --- Source/cmGeneratorTarget.cxx | 38 +++++++++++++++++++ Source/cmGeneratorTarget.h | 11 ++++++ Source/cmGlobalXCodeGenerator.cxx | 4 +- Source/cmLocalVisualStudio6Generator.cxx | 2 +- Source/cmLocalVisualStudio7Generator.cxx | 8 ++-- Source/cmLocalVisualStudio7Generator.h | 3 +- .../cmMakefileExecutableTargetGenerator.cxx | 2 +- Source/cmMakefileLibraryTargetGenerator.cxx | 4 +- Source/cmNinjaNormalTargetGenerator.cxx | 2 +- Source/cmTarget.cxx | 38 ------------------- Source/cmTarget.h | 11 ------ 11 files changed, 62 insertions(+), 61 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index b6c29672d..7e4c917a1 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -4398,6 +4398,44 @@ cmGeneratorTarget::GetLinkInformation(const std::string& config) const return i->second; } +//---------------------------------------------------------------------------- +void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const +{ + int patch; + this->GetTargetVersion(false, major, minor, patch); +} + +//---------------------------------------------------------------------------- +void cmGeneratorTarget::GetTargetVersion(bool soversion, + int& major, int& minor, int& patch) const +{ + // Set the default values. + major = 0; + minor = 0; + patch = 0; + + assert(this->GetType() != cmState::INTERFACE_LIBRARY); + + // Look for a VERSION or SOVERSION property. + const char* prop = soversion? "SOVERSION" : "VERSION"; + if(const char* version = this->GetProperty(prop)) + { + // Try to parse the version number and store the results that were + // successfully parsed. + int parsed_major; + int parsed_minor; + int parsed_patch; + switch(sscanf(version, "%d.%d.%d", + &parsed_major, &parsed_minor, &parsed_patch)) + { + case 3: patch = parsed_patch; // no break! + case 2: minor = parsed_minor; // no break! + case 1: major = parsed_major; // no break! + default: break; + } + } +} + //---------------------------------------------------------------------------- void cmGeneratorTarget::ReportPropertyOrigin(const std::string &p, diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 0c198bbd7..f3b8d1fdc 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -445,6 +445,17 @@ public: const char* ImportedGetLocation(const std::string& config) const; + /** Get the target major and minor version numbers interpreted from + the VERSION property. Version 0 is returned if the property is + not set or cannot be parsed. */ + void GetTargetVersion(int& major, int& minor) const; + + /** Get the target major, minor, and patch version numbers + interpreted from the VERSION or SOVERSION property. Version 0 + is returned if the property is not set or cannot be parsed. */ + void + GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const; + private: friend class cmTargetTraceDependencies; struct SourceEntry { std::vector Depends; }; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index bc05aeadc..8454bc10c 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2422,7 +2422,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, int patch; // VERSION -> current_version - target.GetTargetVersion(false, major, minor, patch); + gtgt->GetTargetVersion(false, major, minor, patch); std::ostringstream v; // Xcode always wants at least 1.0.0 or nothing @@ -2434,7 +2434,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, this->CreateString(v.str().c_str())); // SOVERSION -> compatibility_version - target.GetTargetVersion(true, major, minor, patch); + gtgt->GetTargetVersion(true, major, minor, patch); std::ostringstream vso; // Xcode always wants at least 1.0.0 or nothing diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index b6f5aedac..3e901bac5 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -1319,7 +1319,7 @@ void cmLocalVisualStudio6Generator { int major; int minor; - target.GetTargetVersion(major, minor); + gt->GetTargetVersion(major, minor); std::ostringstream targetVersionStream; targetVersionStream << "/version:" << major << "." << minor; targetVersionFlag = targetVersionStream.str(); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 11229196b..6d02bfa2e 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1215,7 +1215,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, temp += targetNameFull; fout << "\t\t\t\tOutputFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n"; - this->WriteTargetVersionAttribute(fout, target); + this->WriteTargetVersionAttribute(fout, gt); linkOptions.OutputFlagMap(fout, "\t\t\t\t"); fout << "\t\t\t\tAdditionalLibraryDirectories=\""; this->OutputLibraryDirectories(fout, cli.GetDirectories()); @@ -1314,7 +1314,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, temp += targetNameFull; fout << "\t\t\t\tOutputFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n"; - this->WriteTargetVersionAttribute(fout, target); + this->WriteTargetVersionAttribute(fout, gt); linkOptions.OutputFlagMap(fout, "\t\t\t\t"); fout << "\t\t\t\tAdditionalLibraryDirectories=\""; this->OutputLibraryDirectories(fout, cli.GetDirectories()); @@ -1384,11 +1384,11 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, //---------------------------------------------------------------------------- void cmLocalVisualStudio7Generator -::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target) +::WriteTargetVersionAttribute(std::ostream& fout, cmGeneratorTarget* gt) { int major; int minor; - target.GetTargetVersion(major, minor); + gt->GetTargetVersion(major, minor); fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n"; } diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index ba6a72be9..16cf00431 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -106,7 +106,8 @@ private: const char* source, const cmCustomCommand& command, FCInfo& fcinfo); - void WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target); + void WriteTargetVersionAttribute(std::ostream& fout, + cmGeneratorTarget* gt); bool WriteGroup(const cmSourceGroup *sg, cmTarget& target, std::ostream &fout, diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 2d2de5f47..ea910953d 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -382,7 +382,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) std::ostringstream minorStream; int major; int minor; - this->Target->GetTargetVersion(major, minor); + this->GeneratorTarget->GetTargetVersion(major, minor); majorStream << major; minorStream << minor; targetVersionMajor = majorStream.str(); diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index a0aa10bfa..669514300 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -630,7 +630,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules std::ostringstream minorStream; int major; int minor; - this->Target->GetTargetVersion(major, minor); + this->GeneratorTarget->GetTargetVersion(major, minor); majorStream << major; minorStream << minor; targetVersionMajor = majorStream.str(); @@ -862,7 +862,7 @@ cmMakefileLibraryTargetGenerator int major; int minor; int patch; - this->Target->GetTargetVersion(so, major, minor, 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. diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 066c64e05..a8f182bce 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -227,7 +227,7 @@ cmNinjaNormalTargetGenerator std::ostringstream minorStream; int major; int minor; - this->GetTarget()->GetTargetVersion(major, minor); + this->GetGeneratorTarget()->GetTargetVersion(major, minor); majorStream << major; minorStream << minor; targetVersionMajor = majorStream.str(); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 7f21efeb6..850fc6a53 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1615,44 +1615,6 @@ bool cmTarget::HaveWellDefinedOutputFiles() const this->GetType() == cmState::EXECUTABLE; } -//---------------------------------------------------------------------------- -void cmTarget::GetTargetVersion(int& major, int& minor) const -{ - int patch; - this->GetTargetVersion(false, major, minor, patch); -} - -//---------------------------------------------------------------------------- -void cmTarget::GetTargetVersion(bool soversion, - int& major, int& minor, int& patch) const -{ - // Set the default values. - major = 0; - minor = 0; - patch = 0; - - assert(this->GetType() != cmState::INTERFACE_LIBRARY); - - // Look for a VERSION or SOVERSION property. - const char* prop = soversion? "SOVERSION" : "VERSION"; - if(const char* version = this->GetProperty(prop)) - { - // Try to parse the version number and store the results that were - // successfully parsed. - int parsed_major; - int parsed_minor; - int parsed_patch; - switch(sscanf(version, "%d.%d.%d", - &parsed_major, &parsed_minor, &parsed_patch)) - { - case 3: patch = parsed_patch; // no break! - case 2: minor = parsed_minor; // no break! - case 1: major = parsed_major; // no break! - default: break; - } - } -} - //---------------------------------------------------------------------------- bool cmTarget::HandleLocationPropertyPolicy(cmMakefile* context) const { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 6cd876eb0..a9d2454ce 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -213,17 +213,6 @@ public: bool IsImported() const {return this->IsImportedTarget;} - /** Get the target major and minor version numbers interpreted from - the VERSION property. Version 0 is returned if the property is - not set or cannot be parsed. */ - void GetTargetVersion(int& major, int& minor) const; - - /** Get the target major, minor, and patch version numbers - interpreted from the VERSION or SOVERSION property. Version 0 - is returned if the property is not set or cannot be parsed. */ - void - GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const; - // Get the properties cmPropertyMap &GetProperties() const { return this->Properties; }