From f6da044080d854b9ad87cef5c2a6f5195722a6da Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 11 Mar 2014 17:37:26 +0100 Subject: cmLocalGenerator: Add ComputeObjectFilenames interface. Implement it in the local generators and use it in the global generators. --- Source/cmGlobalNinjaGenerator.cxx | 23 +++++++++------ Source/cmGlobalUnixMakefileGenerator3.cxx | 21 ++++++++------ Source/cmGlobalVisualStudioGenerator.cxx | 48 +++++++++---------------------- Source/cmGlobalXCodeGenerator.cxx | 30 +++++++------------ Source/cmLocalGenerator.cxx | 8 ++++++ Source/cmLocalGenerator.h | 4 +++ Source/cmLocalNinjaGenerator.cxx | 14 +++++++++ Source/cmLocalNinjaGenerator.h | 4 +++ Source/cmLocalUnixMakefileGenerator3.cxx | 14 +++++++++ Source/cmLocalUnixMakefileGenerator3.h | 4 +++ Source/cmLocalVisualStudioGenerator.cxx | 40 ++++++++++++++++++++++++++ Source/cmLocalVisualStudioGenerator.h | 4 +++ Source/cmLocalXCodeGenerator.cxx | 28 ++++++++++++++++++ Source/cmLocalXCodeGenerator.h | 3 ++ 14 files changed, 176 insertions(+), 69 deletions(-) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index e9c31e9..08507eb 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -19,6 +19,7 @@ #include "cmVersion.h" #include +#include const char* cmGlobalNinjaGenerator::NINJA_BUILD_FILE = "build.ninja"; const char* cmGlobalNinjaGenerator::NINJA_RULES_FILE = "rules.ninja"; @@ -636,15 +637,21 @@ void cmGlobalNinjaGenerator::ComputeTargetObjects(cmGeneratorTarget* gt) const { std::vector objectSources; gt->GetObjectSources(objectSources); - // Compute the name of each object file. - for(std::vector::iterator - si = objectSources.begin(); - si != objectSources.end(); ++si) + + std::map mapping; + for(std::vector::const_iterator it + = objectSources.begin(); it != objectSources.end(); ++it) + { + mapping[*it]; + } + + gt->LocalGenerator->ComputeObjectFilenames(mapping, gt); + + for(std::map::const_iterator it + = mapping.begin(); it != mapping.end(); ++it) { - cmSourceFile const* sf = *si; - std::string objectName = gt->LocalGenerator - ->GetObjectFileNameWithoutTarget(*sf, gt->ObjectDirectory); - gt->AddObject(sf, objectName); + assert(!it->second.empty()); + gt->AddObject(it->first, it->second); } } diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 6ce8678..91258ed 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -110,15 +110,20 @@ cmGlobalUnixMakefileGenerator3 { std::vector objectSources; gt->GetObjectSources(objectSources); - // Compute the name of each object file. - for(std::vector::iterator - si = objectSources.begin(); - si != objectSources.end(); ++si) + + std::map mapping; + for(std::vector::const_iterator it + = objectSources.begin(); it != objectSources.end(); ++it) + { + mapping[*it]; + } + + gt->LocalGenerator->ComputeObjectFilenames(mapping, gt); + + for(std::map::const_iterator it + = mapping.begin(); it != mapping.end(); ++it) { - cmSourceFile const* sf = *si; - std::string objectName = gt->LocalGenerator - ->GetObjectFileNameWithoutTarget(*sf, gt->ObjectDirectory); - gt->AddObject(sf, objectName); + gt->AddObject(it->first, it->second); } } diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index bd57d0c..9740fbfb 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -122,42 +122,22 @@ void cmGlobalVisualStudioGenerator ::ComputeTargetObjects(cmGeneratorTarget* gt) const { - cmLocalVisualStudioGenerator* lg = - static_cast(gt->LocalGenerator); - std::string dir_max = lg->ComputeLongestObjectDirectory(*gt->Target); - - // Count the number of object files with each name. Note that - // windows file names are not case sensitive. - std::map counts; std::vector objectSources; gt->GetObjectSources(objectSources); - for(std::vector::const_iterator - si = objectSources.begin(); - si != objectSources.end(); ++si) - { - cmSourceFile const* sf = *si; - std::string objectNameLower = cmSystemTools::LowerCase( - cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())); - objectNameLower += ".obj"; - counts[objectNameLower] += 1; - } - - // For all source files producing duplicate names we need unique - // object name computation. - for(std::vector::const_iterator - si = objectSources.begin(); - si != objectSources.end(); ++si) - { - cmSourceFile const* sf = *si; - std::string objectName = - cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()); - objectName += ".obj"; - if(counts[cmSystemTools::LowerCase(objectName)] > 1) - { - gt->AddExplicitObjectName(sf); - objectName = lg->GetObjectFileNameWithoutTarget(*sf, dir_max); - } - gt->AddObject(sf, objectName); + + std::map mapping; + for(std::vector::const_iterator it + = objectSources.begin(); it != objectSources.end(); ++it) + { + mapping[*it]; + } + + gt->LocalGenerator->ComputeObjectFilenames(mapping, gt); + + for(std::map::const_iterator it + = mapping.begin(); it != mapping.end(); ++it) + { + gt->AddObject(it->first, it->second); } } diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 4904d51..0a4b51c 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3939,30 +3939,22 @@ void cmGlobalXCodeGenerator ::ComputeTargetObjects(cmGeneratorTarget* gt) const { - // Count the number of object files with each name. Warn about duplicate - // names since Xcode names them uniquely automatically with a numeric suffix - // to avoid exact duplicate file names. Note that Mac file names are not - // typically case sensitive, hence the LowerCase. - std::map counts; std::vector objectSources; gt->GetObjectSources(objectSources); - for(std::vector::const_iterator - si = objectSources.begin(); - si != objectSources.end(); ++si) + + std::map mapping; + for(std::vector::const_iterator it + = objectSources.begin(); it != objectSources.end(); ++it) { - cmSourceFile const* sf = *si; - std::string objectName = - cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()); - objectName += ".o"; + mapping[*it]; + } - std::string objectNameLower = cmSystemTools::LowerCase(objectName); - counts[objectNameLower] += 1; - if (2 == counts[objectNameLower]) - { - // TODO: emit warning about duplicate name? - } + gt->LocalGenerator->ComputeObjectFilenames(mapping, gt); - gt->AddObject(sf, objectName); + for(std::map::const_iterator it + = mapping.begin(); it != mapping.end(); ++it) + { + gt->AddObject(it->first, it->second); } } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index ebcfa08..c63de79 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -3081,6 +3081,14 @@ cmLocalGenerator } //---------------------------------------------------------------------------- +void cmLocalGenerator::ComputeObjectFilenames( + std::map&, + cmGeneratorTarget const*) +{ + +} + +//---------------------------------------------------------------------------- std::string cmLocalGenerator ::GetObjectFileNameWithoutTarget(const cmSourceFile& source, diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index afcaee9..61488fe 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -372,6 +372,10 @@ public: std::string& linkPath, cmGeneratorTarget* target); + virtual void ComputeObjectFilenames( + std::map& mapping, + cmGeneratorTarget const* gt = 0); + protected: ///! put all the libraries for a target on into the given stream virtual void OutputLinkLibraries(std::string& linkLibraries, diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 7c4aab8..2f763ce 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -267,6 +267,20 @@ void cmLocalNinjaGenerator::SetConfigName() } } +//---------------------------------------------------------------------------- +void cmLocalNinjaGenerator::ComputeObjectFilenames( + std::map& mapping, + cmGeneratorTarget const* gt) +{ + for(std::map::iterator + si = mapping.begin(); si != mapping.end(); ++si) + { + cmSourceFile const* sf = si->first; + si->second = this->GetObjectFileNameWithoutTarget(*sf, + gt->ObjectDirectory); + } +} + void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os) { cmGlobalNinjaGenerator::WriteDivider(os); diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h index 9d0b7b5..e91e60b 100644 --- a/Source/cmLocalNinjaGenerator.h +++ b/Source/cmLocalNinjaGenerator.h @@ -101,6 +101,10 @@ public: virtual std::string ConvertToLinkReference(std::string const& lib, OutputFormat format = SHELL); + virtual void ComputeObjectFilenames( + std::map& mapping, + cmGeneratorTarget const* gt = 0); + protected: virtual std::string ConvertToIncludeReference(std::string const& path, diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 79240e1..2d36089 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -172,6 +172,20 @@ void cmLocalUnixMakefileGenerator3::Generate() } //---------------------------------------------------------------------------- +void cmLocalUnixMakefileGenerator3::ComputeObjectFilenames( + std::map& mapping, + cmGeneratorTarget const* gt) +{ + for(std::map::iterator + si = mapping.begin(); si != mapping.end(); ++si) + { + cmSourceFile const* sf = si->first; + si->second = this->GetObjectFileNameWithoutTarget(*sf, + gt->ObjectDirectory); + } +} + +//---------------------------------------------------------------------------- void cmLocalUnixMakefileGenerator3:: GetLocalObjectFiles(std::map &localObjectFiles) { diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index 27070e2..14543fb 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -313,6 +313,10 @@ private: std::string MakeLauncher(cmCustomCommandGenerator const& ccg, cmTarget* target, RelativeRoot relative); + virtual void ComputeObjectFilenames( + std::map& mapping, + cmGeneratorTarget const* gt = 0); + friend class cmMakefileTargetGenerator; friend class cmMakefileExecutableTargetGenerator; friend class cmMakefileLibraryTargetGenerator; diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index 613ee97..9680d43 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -31,6 +31,46 @@ cmLocalVisualStudioGenerator::~cmLocalVisualStudioGenerator() } //---------------------------------------------------------------------------- +void cmLocalVisualStudioGenerator::ComputeObjectFilenames( + std::map& mapping, + cmGeneratorTarget const* gt) +{ + std::string dir_max = this->ComputeLongestObjectDirectory(*gt->Target); + + // Count the number of object files with each name. Note that + // windows file names are not case sensitive. + std::map counts; + + for(std::map::iterator + si = mapping.begin(); si != mapping.end(); ++si) + { + cmSourceFile const* sf = si->first; + std::string objectNameLower = cmSystemTools::LowerCase( + cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())); + objectNameLower += ".obj"; + counts[objectNameLower] += 1; + } + + // For all source files producing duplicate names we need unique + // object name computation. + + for(std::map::iterator + si = mapping.begin(); si != mapping.end(); ++si) + { + cmSourceFile const* sf = si->first; + std::string objectName = + cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()); + objectName += ".obj"; + if(counts[cmSystemTools::LowerCase(objectName)] > 1) + { + const_cast(gt)->AddExplicitObjectName(sf); + objectName = this->GetObjectFileNameWithoutTarget(*sf, dir_max); + } + si->second = objectName; + } +} + +//---------------------------------------------------------------------------- cmsys::auto_ptr cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmTarget& target, const std::string& config, diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h index a89e219..3bf4f43 100644 --- a/Source/cmLocalVisualStudioGenerator.h +++ b/Source/cmLocalVisualStudioGenerator.h @@ -61,6 +61,10 @@ public: virtual void AddCMakeListsRules() = 0; + virtual void ComputeObjectFilenames( + std::map& mapping, + cmGeneratorTarget const* = 0); + protected: virtual const char* ReportErrorLabel() const; virtual bool CustomCommandUseLocal() const { return false; } diff --git a/Source/cmLocalXCodeGenerator.cxx b/Source/cmLocalXCodeGenerator.cxx index 5857aef..8ff6c87 100644 --- a/Source/cmLocalXCodeGenerator.cxx +++ b/Source/cmLocalXCodeGenerator.cxx @@ -71,3 +71,31 @@ void cmLocalXCodeGenerator::GenerateInstallRules() t->HasMacOSXRpathInstallNameDir(""); } } + +//---------------------------------------------------------------------------- +void cmLocalXCodeGenerator::ComputeObjectFilenames( + std::map& mapping, + cmGeneratorTarget const*) +{ + // Count the number of object files with each name. Warn about duplicate + // names since Xcode names them uniquely automatically with a numeric suffix + // to avoid exact duplicate file names. Note that Mac file names are not + // typically case sensitive, hence the LowerCase. + std::map counts; + for(std::map::iterator + si = mapping.begin(); si != mapping.end(); ++si) + { + cmSourceFile const* sf = si->first; + std::string objectName = + cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()); + objectName += ".o"; + + std::string objectNameLower = cmSystemTools::LowerCase(objectName); + counts[objectNameLower] += 1; + if (2 == counts[objectNameLower]) + { + // TODO: emit warning about duplicate name? + } + si->second = objectName; + } +} diff --git a/Source/cmLocalXCodeGenerator.h b/Source/cmLocalXCodeGenerator.h index 3bfe3a3..f553a17 100644 --- a/Source/cmLocalXCodeGenerator.h +++ b/Source/cmLocalXCodeGenerator.h @@ -32,6 +32,9 @@ public: const std::string& rawFlag); virtual void Generate(); virtual void GenerateInstallRules(); + virtual void ComputeObjectFilenames( + std::map& mapping, + cmGeneratorTarget const* gt = 0); private: }; -- cgit v0.12