From 47803e6f8e98984e740acf2f7c0a217de58717cd Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 4 Aug 2015 19:19:44 +0200 Subject: [PATCH] cmGeneratorTarget: Move GetExecutableNames from cmTarget. --- Source/cmGeneratorTarget.cxx | 68 ++++++++++++++++++- Source/cmGeneratorTarget.h | 6 ++ Source/cmInstallTargetGenerator.cxx | 7 +- Source/cmLocalVisualStudio7Generator.cxx | 2 +- .../cmMakefileExecutableTargetGenerator.cxx | 4 +- Source/cmNinjaNormalTargetGenerator.cxx | 2 +- Source/cmTarget.cxx | 62 ----------------- Source/cmTarget.h | 8 --- Source/cmVisualStudio10TargetGenerator.cxx | 2 +- 9 files changed, 81 insertions(+), 80 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index f9f23a6da..6a693f1d8 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1248,8 +1248,7 @@ void cmGeneratorTarget::GenerateTargetManifest( std::string pdbName; if(this->GetType() == cmTarget::EXECUTABLE) { - this->Target->GetExecutableNames(name, realName, impName, pdbName, - config); + this->GetExecutableNames(name, realName, impName, pdbName, config); } else if(this->GetType() == cmTarget::STATIC_LIBRARY || this->GetType() == cmTarget::SHARED_LIBRARY || @@ -1368,7 +1367,7 @@ cmGeneratorTarget::NormalGetRealName(const std::string& config) const std::string realName; std::string impName; std::string pdbName; - this->Target->GetExecutableNames(name, realName, impName, pdbName, config); + this->GetExecutableNames(name, realName, impName, pdbName, config); return realName; } else @@ -1385,6 +1384,69 @@ cmGeneratorTarget::NormalGetRealName(const std::string& config) const } } +//---------------------------------------------------------------------------- +void cmGeneratorTarget::GetExecutableNames(std::string& name, + std::string& realName, + std::string& impName, + std::string& pdbName, + const std::string& config) const +{ + // This should not be called for imported targets. + // TODO: Split cmTarget into a class hierarchy to get compile-time + // enforcement of the limited imported target API. + if(this->Target->IsImported()) + { + std::string msg = + "GetExecutableNames called on imported target: "; + msg += this->GetName(); + this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg); + } + + // This versioning is supported only for executables and then only + // when the platform supports symbolic links. +#if defined(_WIN32) && !defined(__CYGWIN__) + const char* version = 0; +#else + // Check for executable version properties. + const char* version = this->GetProperty("VERSION"); + if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE")) + { + version = 0; + } +#endif + + // Get the components of the executable name. + std::string prefix; + std::string base; + std::string suffix; + this->Target->GetFullNameInternal(config, false, prefix, base, suffix); + + // The executable name. + name = prefix+base+suffix; + + // The executable's real name on disk. +#if defined(__CYGWIN__) + realName = prefix+base; +#else + realName = name; +#endif + if(version) + { + realName += "-"; + realName += version; + } +#if defined(__CYGWIN__) + realName += suffix; +#endif + + // The import library name. + impName = this->Target->GetFullNameInternal(config, true); + + // The program database file name. + pdbName = this->Target->GetPDBName(config); +} + + bool cmStrictTargetComparison::operator()(cmTarget const* t1, cmTarget const* t2) const { diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 1303ee410..49aa65b6b 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -184,6 +184,12 @@ public: void GetAutoUicOptions(std::vector &result, const std::string& config) const; + /** Get the names of the executable needed to generate a build rule + that takes into account executable version numbers. This should + be called only on an executable target. */ + void GetExecutableNames(std::string& name, std::string& realName, + std::string& impName, std::string& pdbName, + const std::string& config) const; struct SourceFileFlags GetTargetSourceFileFlags(const cmSourceFile* sf) const; diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index c64f9a34b..c87285922 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -125,7 +125,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os, std::string targetNameReal; std::string targetNameImport; std::string targetNamePDB; - this->Target->Target->GetExecutableNames(targetName, targetNameReal, + this->Target->GetExecutableNames(targetName, targetNameReal, targetNameImport, targetNamePDB, config); if(this->ImportLibrary) @@ -372,13 +372,16 @@ cmInstallTargetGenerator::GetInstallFilename(cmTarget const* target, { std::string fname; // Compute the name of the library. + cmGeneratorTarget *gtgt = target->GetMakefile() + ->GetGlobalGenerator() + ->GetGeneratorTarget(target); if(target->GetType() == cmTarget::EXECUTABLE) { std::string targetName; std::string targetNameReal; std::string targetNameImport; std::string targetNamePDB; - target->GetExecutableNames(targetName, targetNameReal, + gtgt->GetExecutableNames(targetName, targetNameReal, targetNameImport, targetNamePDB, config); if(nameType == NameImplib) diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 37e08dd2d..daac33130 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1244,7 +1244,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, std::string targetNameFull; std::string targetNameImport; std::string targetNamePDB; - target.GetExecutableNames(targetName, targetNameFull, + gt->GetExecutableNames(targetName, targetNameFull, targetNameImport, targetNamePDB, configName); // Compute the link library and directory information. diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 416063f10..31a78ad93 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -25,7 +25,7 @@ cmMakefileExecutableTargetGenerator cmMakefileTargetGenerator(target) { this->CustomCommandDriver = OnDepends; - this->Target->GetExecutableNames( + this->GeneratorTarget->GetExecutableNames( this->TargetNameOut, this->TargetNameReal, this->TargetNameImport, this->TargetNamePDB, this->ConfigName); @@ -94,7 +94,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) std::string targetNameReal; std::string targetNameImport; std::string targetNamePDB; - this->Target->GetExecutableNames + this->GeneratorTarget->GetExecutableNames (targetName, targetNameReal, targetNameImport, targetNamePDB, this->ConfigName); diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index c9fa7c063..737510f45 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -43,7 +43,7 @@ cmNinjaNormalTargetGenerator(cmGeneratorTarget* target) this->TargetLinkLanguage = target->Target ->GetLinkerLanguage(this->GetConfigName()); if (target->GetType() == cmTarget::EXECUTABLE) - target->Target->GetExecutableNames(this->TargetNameOut, + this->GetGeneratorTarget()->GetExecutableNames(this->TargetNameOut, this->TargetNameReal, this->TargetNameImport, this->TargetNamePDB, diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index ded5363c1..22b76e998 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -3967,68 +3967,6 @@ void cmTarget::ComputeVersionedName(std::string& vName, vName += this->IsApple? suffix : std::string(); } -//---------------------------------------------------------------------------- -void cmTarget::GetExecutableNames(std::string& name, - std::string& realName, - std::string& impName, - std::string& pdbName, - const std::string& config) const -{ - // This should not be called for imported targets. - // TODO: Split cmTarget into a class hierarchy to get compile-time - // enforcement of the limited imported target API. - if(this->IsImported()) - { - std::string msg = - "GetExecutableNames called on imported target: "; - msg += this->GetName(); - this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg); - } - - // This versioning is supported only for executables and then only - // when the platform supports symbolic links. -#if defined(_WIN32) && !defined(__CYGWIN__) - const char* version = 0; -#else - // Check for executable version properties. - const char* version = this->GetProperty("VERSION"); - if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE")) - { - version = 0; - } -#endif - - // Get the components of the executable name. - std::string prefix; - std::string base; - std::string suffix; - this->GetFullNameInternal(config, false, prefix, base, suffix); - - // The executable name. - name = prefix+base+suffix; - - // The executable's real name on disk. -#if defined(__CYGWIN__) - realName = prefix+base; -#else - realName = name; -#endif - if(version) - { - realName += "-"; - realName += version; - } -#if defined(__CYGWIN__) - realName += suffix; -#endif - - // The import library name. - impName = this->GetFullNameInternal(config, true); - - // The program database file name. - pdbName = this->GetPDBName(config); -} - //---------------------------------------------------------------------------- bool cmTarget::HasImplibGNUtoMS() const { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 925e7c6c8..714647cae 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -406,14 +406,6 @@ public: std::string& realName, std::string& impName, std::string& pdbName, const std::string& config) const; - /** Get the names of the executable needed to generate a build rule - that takes into account executable version numbers. This should - be called only on an executable target. */ - void GetExecutableNames(std::string& name, std::string& realName, - std::string& impName, - std::string& pdbName, - const std::string& config) const; - /** Does this target have a GNU implib to convert to MS format? */ bool HasImplibGNUtoMS() const; diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index f3f291ad0..1bb21ffe6 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2471,7 +2471,7 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config) std::string targetNamePDB; if(this->Target->GetType() == cmTarget::EXECUTABLE) { - this->Target->GetExecutableNames(targetName, targetNameFull, + this->GeneratorTarget->GetExecutableNames(targetName, targetNameFull, targetNameImport, targetNamePDB, config.c_str()); }