diff --git a/Source/cmGetTargetPropertyCommand.cxx b/Source/cmGetTargetPropertyCommand.cxx index 6ff0fccb0..9c8ed4f44 100644 --- a/Source/cmGetTargetPropertyCommand.cxx +++ b/Source/cmGetTargetPropertyCommand.cxx @@ -64,8 +64,7 @@ bool cmGetTargetPropertyCommand::InitialPass( target_location += "/"; } - cmLocalGenerator* lg = m_Makefile->GetLocalGenerator(); - target_location += lg->GetFullTargetName(targetName, target); + target_location += target.GetFullName(m_Makefile); m_Makefile->AddDefinition(var, target_location.c_str()); return true; } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 0db955951..259a1f591 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -212,7 +212,7 @@ void cmLocalGenerator::GenerateInstallRules() case cmTarget::STATIC_LIBRARY: case cmTarget::MODULE_LIBRARY: fname = libOutPath; - fname += this->GetFullTargetName(l->first.c_str(), l->second); + fname += l->second.GetFullName(m_Makefile); files = fname.c_str(); this->AddInstallRule(fout, dest, type, files); break; @@ -220,7 +220,7 @@ void cmLocalGenerator::GenerateInstallRules() { // Special code to handle DLL fname = libOutPath; - fname += this->GetFullTargetName(l->first.c_str(), l->second); + fname += l->second.GetFullName(m_Makefile); std::string ext = cmSystemTools::GetFilenameExtension(fname); ext = cmSystemTools::LowerCase(ext); if ( ext == ".dll" ) @@ -263,7 +263,7 @@ void cmLocalGenerator::GenerateInstallRules() break; case cmTarget::EXECUTABLE: fname = exeOutPath; - fname += this->GetFullTargetName(l->first.c_str(), l->second); + fname += l->second.GetFullName(m_Makefile); files = fname.c_str(); this->AddInstallRule(fout, dest, type, files); break; @@ -380,49 +380,6 @@ void cmLocalGenerator::AddInstallRule(std::ostream& fout, const char* dest, << " FILES \"" << sfiles.c_str() << "\")\n"; } -std::string cmLocalGenerator::GetFullTargetName(const char* n, - const cmTarget& t) -{ - const char* targetPrefix = t.GetProperty("PREFIX"); - const char* targetSuffix = t.GetProperty("SUFFIX"); - if(!targetSuffix && t.GetType() == cmTarget::EXECUTABLE) - { - targetSuffix = cmSystemTools::GetExecutableExtension(); - } - const char* prefixVar = t.GetPrefixVariable(); - const char* suffixVar = t.GetSuffixVariable(); - const char* ll = t.GetLinkerLanguage(this->GetGlobalGenerator()); - // first try language specific suffix - if(ll) - { - if(!targetSuffix) - { - std::string langSuff = suffixVar + std::string("_") + ll; - targetSuffix = m_Makefile->GetDefinition(langSuff.c_str()); - } - if(!targetPrefix) - { - std::string langPrefix = prefixVar + std::string("_") + ll; - targetPrefix = m_Makefile->GetDefinition(langPrefix.c_str()); - } - } - - // if there is no prefix on the target use the cmake definition - if(!targetPrefix && prefixVar) - { - targetPrefix = m_Makefile->GetSafeDefinition(prefixVar); - } - // if there is no suffix on the target use the cmake definition - if(!targetSuffix && suffixVar) - { - targetSuffix = m_Makefile->GetSafeDefinition(suffixVar); - } - std::string name = targetPrefix?targetPrefix:""; - name += n; - name += targetSuffix?targetSuffix:""; - return name; -} - void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname, const char* lang, cmSourceFile& source, @@ -519,7 +476,7 @@ void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target) std::string createRule = "CMAKE_"; createRule += llang; createRule += target.GetCreateRuleVariable(); - std::string targetName = this->GetFullTargetName(target.GetName(), target); + std::string targetName = target.GetFullName(m_Makefile); // Executable : // Shared Library: // Static Library: diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index bea6c67fe..4012cdfa6 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -69,9 +69,6 @@ public: ///! Set the Global Generator, done on creation by the GlobalGenerator void SetGlobalGenerator(cmGlobalGenerator *gg); - - /** Get the full name of the target's file, without path. */ - std::string GetFullTargetName(const char* n, const cmTarget& t); /** * Convert the given remote path to a relative path with respect to diff --git a/Source/cmLocalUnixMakefileGenerator2.cxx b/Source/cmLocalUnixMakefileGenerator2.cxx index bd1c08025..92b6be9cb 100644 --- a/Source/cmLocalUnixMakefileGenerator2.cxx +++ b/Source/cmLocalUnixMakefileGenerator2.cxx @@ -1478,7 +1478,7 @@ cmLocalUnixMakefileGenerator2 const char* targetOutPath) { // Add a rule to build the target by name. - std::string localName = this->GetFullTargetName(target.GetName(), target); + std::string localName = target.GetFullName(m_Makefile); localName = this->ConvertToRelativeOutputPath(localName.c_str()); this->WriteConvenienceRule(ruleFileStream, targetOutPath, localName.c_str()); @@ -2775,42 +2775,6 @@ cmLocalUnixMakefileGenerator2::SamePath(const char* path1, const char* path2) #endif } -//---------------------------------------------------------------------------- -std::string -cmLocalUnixMakefileGenerator2::GetBaseTargetName(const cmTarget& t) -{ - std::string pathPrefix = ""; -#ifdef __APPLE__ - if ( t.GetPropertyAsBool("MACOSX_BUNDLE") ) - { - pathPrefix = t.GetName(); - pathPrefix += ".app/Contents/MacOS/"; - } -#endif - - const char* targetPrefix = t.GetProperty("PREFIX"); - const char* prefixVar = t.GetPrefixVariable(); - // if there is no prefix on the target use the cmake definition - if(!targetPrefix && prefixVar) - { - // first check for a language specific suffix var - const char* ll = t.GetLinkerLanguage(this->GetGlobalGenerator()); - if(ll) - { - std::string langPrefix = prefixVar + std::string("_") + ll; - targetPrefix = m_Makefile->GetDefinition(langPrefix.c_str()); - } - // if there not a language specific suffix then use the general one - if(!targetPrefix) - { - targetPrefix = m_Makefile->GetSafeDefinition(prefixVar); - } - } - std::string name = pathPrefix + (targetPrefix?targetPrefix:""); - name += t.GetName(); - return name; -} - //---------------------------------------------------------------------------- void cmLocalUnixMakefileGenerator2::GetLibraryNames(const cmTarget& t, std::string& name, @@ -2838,7 +2802,7 @@ void cmLocalUnixMakefileGenerator2::GetLibraryNames(const cmTarget& t, } // The library name. - name = this->GetFullTargetName(t.GetName(), t); + name = t.GetFullName(m_Makefile); // The library's soname. soName = name; @@ -2862,7 +2826,7 @@ void cmLocalUnixMakefileGenerator2::GetLibraryNames(const cmTarget& t, } // The library name without extension. - baseName = this->GetBaseTargetName(t); + baseName = t.GetBaseName(m_Makefile); } //---------------------------------------------------------------------------- diff --git a/Source/cmLocalUnixMakefileGenerator2.h b/Source/cmLocalUnixMakefileGenerator2.h index 76bc75a56..8f77b5efd 100644 --- a/Source/cmLocalUnixMakefileGenerator2.h +++ b/Source/cmLocalUnixMakefileGenerator2.h @@ -221,7 +221,6 @@ protected: //========================================================================== bool SamePath(const char* path1, const char* path2); - std::string GetBaseTargetName(const cmTarget& t); void GetLibraryNames(const cmTarget& t, std::string& name, std::string& soName, std::string& realName, std::string& baseName); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index c2af5e435..479947f3f 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -17,6 +17,7 @@ #include "cmTarget.h" #include "cmMakefile.h" #include "cmSourceFile.h" +#include "cmLocalGenerator.h" #include "cmGlobalGenerator.h" #include #include @@ -831,10 +832,14 @@ const char* cmTarget::GetCreateRuleVariable() return ""; } - const char* cmTarget::GetSuffixVariable() const { - switch(this->GetType()) + return this->GetSuffixVariableInternal(this->GetType()); +} + +const char* cmTarget::GetSuffixVariableInternal(TargetType type) const +{ + switch(type) { case cmTarget::STATIC_LIBRARY: return "CMAKE_STATIC_LIBRARY_SUFFIX"; @@ -855,7 +860,12 @@ const char* cmTarget::GetSuffixVariable() const const char* cmTarget::GetPrefixVariable() const { - switch(this->GetType()) + return this->GetPrefixVariableInternal(this->GetType()); +} + +const char* cmTarget::GetPrefixVariableInternal(TargetType type) const +{ + switch(type) { case cmTarget::STATIC_LIBRARY: return "CMAKE_STATIC_LIBRARY_PREFIX"; @@ -872,3 +882,95 @@ const char* cmTarget::GetPrefixVariable() const } return ""; } + +std::string cmTarget::GetFullName(cmMakefile* mf) const +{ + return this->GetFullNameInternal(mf, this->GetType()); +} + +std::string cmTarget::GetFullNameInternal(cmMakefile* mf, + TargetType type) const +{ + const char* targetPrefix = this->GetProperty("PREFIX"); + const char* targetSuffix = this->GetProperty("SUFFIX"); + if(!targetSuffix && this->GetType() == cmTarget::EXECUTABLE) + { + targetSuffix = cmSystemTools::GetExecutableExtension(); + } + const char* prefixVar = this->GetPrefixVariableInternal(type); + const char* suffixVar = this->GetSuffixVariableInternal(type); + const char* ll = + this->GetLinkerLanguage( + mf->GetLocalGenerator()->GetGlobalGenerator()); + // first try language specific suffix + if(ll) + { + if(!targetSuffix) + { + std::string langSuff = suffixVar + std::string("_") + ll; + targetSuffix = mf->GetDefinition(langSuff.c_str()); + } + if(!targetPrefix) + { + std::string langPrefix = prefixVar + std::string("_") + ll; + targetPrefix = mf->GetDefinition(langPrefix.c_str()); + } + } + + // if there is no prefix on the target use the cmake definition + if(!targetPrefix && prefixVar) + { + targetPrefix = mf->GetSafeDefinition(prefixVar); + } + // if there is no suffix on the target use the cmake definition + if(!targetSuffix && suffixVar) + { + targetSuffix = mf->GetSafeDefinition(suffixVar); + } + std::string name = targetPrefix?targetPrefix:""; + name += this->GetName(); + name += targetSuffix?targetSuffix:""; + return name; +} + +std::string cmTarget::GetBaseName(cmMakefile* mf) const +{ + return this->GetBaseNameInternal(mf, this->GetType()); +} + +std::string +cmTarget::GetBaseNameInternal(cmMakefile* mf, TargetType type) const +{ + std::string pathPrefix = ""; +#ifdef __APPLE__ + if(this->GetPropertyAsBool("MACOSX_BUNDLE")) + { + pathPrefix = this->GetName(); + pathPrefix += ".app/Contents/MacOS/"; + } +#endif + const char* targetPrefix = this->GetProperty("PREFIX"); + const char* prefixVar = this->GetPrefixVariableInternal(type); + // if there is no prefix on the target use the cmake definition + if(!targetPrefix && prefixVar) + { + // first check for a language specific suffix var + const char* ll = + this->GetLinkerLanguage( + mf->GetLocalGenerator()->GetGlobalGenerator()); + if(ll) + { + std::string langPrefix = prefixVar + std::string("_") + ll; + targetPrefix = mf->GetDefinition(langPrefix.c_str()); + } + // if there not a language specific suffix then use the general one + if(!targetPrefix) + { + targetPrefix = mf->GetSafeDefinition(prefixVar); + } + } + std::string name = pathPrefix; + name += targetPrefix?targetPrefix:""; + name += this->GetName(); + return name; +} diff --git a/Source/cmTarget.h b/Source/cmTarget.h index cc848499a..e1ea2ee07 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -167,6 +167,14 @@ public: const char* GetSuffixVariable() const; ///! Return the name of the variable to look up the target suffix const char* GetPrefixVariable() const; + + // Get the full name of the target according to the settings in the + // given makefile. + std::string GetFullName(cmMakefile* mf) const; + + // Get the baes name (no suffix) of the target according to the + // settings in the given makefile. + std::string GetBaseName(cmMakefile* mf) const; private: /** * A list of direct dependencies. Use in conjunction with DependencyMap. @@ -221,6 +229,10 @@ private: void GatherDependencies( const cmMakefile& mf, const std::string& lib, DependencyMap& dep_map ); + const char* GetSuffixVariableInternal(TargetType type) const; + const char* GetPrefixVariableInternal(TargetType type) const; + std::string GetFullNameInternal(cmMakefile* mf, TargetType type) const; + std::string GetBaseNameInternal(cmMakefile* mf, TargetType type) const; private: std::string m_Name;