cmGeneratorTarget: Move GetTargetVersion from cmTarget.

This commit is contained in:
Stephen Kelly 2015-10-16 19:19:51 +02:00
parent 1427227720
commit 12e4790a0b
11 changed files with 62 additions and 61 deletions

View File

@ -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,

View File

@ -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<cmSourceFile*> Depends; };

View File

@ -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

View File

@ -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();

View File

@ -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";
}

View File

@ -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,

View File

@ -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();

View File

@ -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.

View File

@ -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();

View File

@ -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
{

View File

@ -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; }