From d5b2e33be2119ad12744ed62920a8f8d9b6d705d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 11 Mar 2014 16:35:58 +0100 Subject: Makefiles: Compute local object files on demand. Don't compute them up front. --- Source/cmGlobalUnixMakefileGenerator3.cxx | 8 +---- Source/cmLocalUnixMakefileGenerator3.cxx | 58 ++++++++++++++++++++++++------- Source/cmLocalUnixMakefileGenerator3.h | 8 ++--- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index f5c56a9..0e03e89 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -109,9 +109,6 @@ cmGlobalUnixMakefileGenerator3 ::ComputeTargetObjects(cmGeneratorTarget* gt) const { cmTarget* target = gt->Target; - cmLocalUnixMakefileGenerator3* lg = - static_cast(gt->LocalGenerator); - // Compute full path to object file directory for this target. std::string dir_max; dir_max += gt->Makefile->GetCurrentOutputDirectory(); @@ -128,12 +125,9 @@ cmGlobalUnixMakefileGenerator3 si != objectSources.end(); ++si) { cmSourceFile* sf = *si; - bool hasSourceExtension = true; std::string objectName = gt->LocalGenerator - ->GetObjectFileNameWithoutTarget(*sf, dir_max, - &hasSourceExtension); + ->GetObjectFileNameWithoutTarget(*sf, dir_max); gt->AddObject(sf, objectName); - lg->AddLocalObjectFile(target, sf, objectName, hasSourceExtension); } } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 9f12ffe..a838ce3 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -172,26 +172,57 @@ void cmLocalUnixMakefileGenerator3::Generate() } //---------------------------------------------------------------------------- -void cmLocalUnixMakefileGenerator3::AddLocalObjectFile( - cmTarget* target, cmSourceFile* sf, std::string objNoTargetDir, - bool hasSourceExtension) +void cmLocalUnixMakefileGenerator3:: +GetLocalObjectFiles(std::map &localObjectFiles) { - if(cmSystemTools::FileIsFullPath(objNoTargetDir.c_str())) + std::set emitted; + cmGeneratorTargetsType targets = this->Makefile->GetGeneratorTargets(); + for(cmGeneratorTargetsType::iterator ti = targets.begin(); + ti != targets.end(); ++ti) { - objNoTargetDir = cmSystemTools::GetFilenameName(objNoTargetDir); + cmGeneratorTarget* gt = ti->second; + if (gt->GetType() == cmTarget::INTERFACE_LIBRARY) + { + continue; + } + std::vector objectSources; + gt->GetObjectSources(objectSources); + // Compute full path to object file directory for this target. + std::string dir_max; + dir_max += gt->Makefile->GetCurrentOutputDirectory(); + dir_max += "/"; + dir_max += this->GetTargetDirectory(*gt->Target); + dir_max += "/"; + // Compute the name of each object file. + for(std::vector::iterator + si = objectSources.begin(); + si != objectSources.end(); ++si) + { + cmSourceFile* sf = *si; + bool hasSourceExtension = true; + std::string objectName = this->GetObjectFileNameWithoutTarget(*sf, + dir_max, + &hasSourceExtension); + if(cmSystemTools::FileIsFullPath(objectName.c_str())) + { + objectName = cmSystemTools::GetFilenameName(objectName); + } + LocalObjectInfo& info = localObjectFiles[objectName]; + info.HasSourceExtension = hasSourceExtension; + info.push_back(LocalObjectEntry(gt->Target, sf->GetLanguage())); + } } - LocalObjectInfo& info = this->LocalObjectFiles[objNoTargetDir]; - info.HasSourceExtension = hasSourceExtension; - info.push_back(LocalObjectEntry(target, sf->GetLanguage())); } //---------------------------------------------------------------------------- void cmLocalUnixMakefileGenerator3::GetIndividualFileTargets (std::vector& targets) { + std::map localObjectFiles; + this->GetLocalObjectFiles(localObjectFiles); for (std::map::iterator lo = - this->LocalObjectFiles.begin(); - lo != this->LocalObjectFiles.end(); ++lo) + localObjectFiles.begin(); + lo != localObjectFiles.end(); ++lo) { targets.push_back(lo->first); @@ -253,11 +284,14 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefile() bool do_assembly_rules = this->GetCreateAssemblySourceRules(); + std::map localObjectFiles; + this->GetLocalObjectFiles(localObjectFiles); + // now write out the object rules // for each object file name for (std::map::iterator lo = - this->LocalObjectFiles.begin(); - lo != this->LocalObjectFiles.end(); ++lo) + localObjectFiles.begin(); + lo != localObjectFiles.end(); ++lo) { // Add a convenience rule for building the object file. this->WriteObjectConvenienceRule(ruleFileStream, diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index d504247..27070e2 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -224,10 +224,6 @@ public: // write the target rules for the local Makefile into the stream void WriteLocalAllRules(std::ostream& ruleFileStream); - void AddLocalObjectFile(cmTarget* target, cmSourceFile* sf, - std::string objNoTargetDir, - bool hasSourceExtension); - std::vector const& GetLocalHelp() { return this->LocalHelp; } /** Get whether to create rules to generate preprocessed and @@ -366,7 +362,9 @@ private: LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false), HasAssembleRule(false) {} }; - std::map LocalObjectFiles; + void GetLocalObjectFiles( + std::map &localObjectFiles); + void WriteObjectConvenienceRule(std::ostream& ruleFileStream, const char* comment, const char* output, LocalObjectInfo const& info); -- cgit v0.12 From cd43433de56ab31269a076fb2b2ace8babaa107d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 12 Mar 2014 21:09:20 +0100 Subject: cmGlobalGenerator: Extract a ComputeTargetObjectDirectory interface. Make it public for future external calls. --- Source/cmGlobalGenerator.cxx | 6 ++++++ Source/cmGlobalGenerator.h | 2 ++ Source/cmGlobalNinjaGenerator.cxx | 27 ++++++++++++++++----------- Source/cmGlobalNinjaGenerator.h | 2 +- Source/cmGlobalUnixMakefileGenerator3.cxx | 27 +++++++++++++++++---------- Source/cmGlobalUnixMakefileGenerator3.h | 1 + Source/cmGlobalVisualStudioGenerator.cxx | 7 ++++++- Source/cmGlobalVisualStudioGenerator.h | 1 + Source/cmGlobalXCodeGenerator.cxx | 5 +++++ Source/cmGlobalXCodeGenerator.h | 1 + 10 files changed, 56 insertions(+), 23 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index b95ff81..c9ae799 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1449,6 +1449,7 @@ void cmGlobalGenerator::ComputeGeneratorTargetObjects() continue; } cmGeneratorTarget* gt = ti->second; + this->ComputeTargetObjectDirectory(gt); gt->LookupObjectLibraries(); this->ComputeTargetObjects(gt); } @@ -1520,6 +1521,11 @@ void cmGlobalGenerator::ComputeTargetObjects(cmGeneratorTarget*) const // Implemented in generator subclasses that need this. } +//---------------------------------------------------------------------------- +void cmGlobalGenerator::ComputeTargetObjectDirectory(cmGeneratorTarget*) const +{ +} + void cmGlobalGenerator::CheckLocalGenerators() { std::map notFoundMap; diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 91e71a8..ed07b10 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -323,6 +323,8 @@ public: GetExportedTargetsFile(const std::string &filename) const; void AddCMP0042WarnTarget(const std::string& target); + virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const; + protected: typedef std::vector GeneratorVector; // for a project collect all its targets by following depend diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 0a05f5a..686414d 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -634,16 +634,6 @@ std::string cmGlobalNinjaGenerator::GetEditCacheCommand() const // TODO: Refactor to combine with cmGlobalUnixMakefileGenerator3 impl. void cmGlobalNinjaGenerator::ComputeTargetObjects(cmGeneratorTarget* gt) const { - cmTarget* target = gt->Target; - - // Compute full path to object file directory for this target. - std::string dir_max; - dir_max += gt->Makefile->GetCurrentOutputDirectory(); - dir_max += "/"; - dir_max += gt->LocalGenerator->GetTargetDirectory(*target); - dir_max += "/"; - gt->ObjectDirectory = dir_max; - std::vector objectSources; gt->GetObjectSources(objectSources); // Compute the name of each object file. @@ -653,12 +643,27 @@ void cmGlobalNinjaGenerator::ComputeTargetObjects(cmGeneratorTarget* gt) const { cmSourceFile* sf = *si; std::string objectName = gt->LocalGenerator - ->GetObjectFileNameWithoutTarget(*sf, dir_max); + ->GetObjectFileNameWithoutTarget(*sf, gt->ObjectDirectory); gt->AddObject(sf, objectName); } } //---------------------------------------------------------------------------- +void cmGlobalNinjaGenerator +::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const +{ + cmTarget* target = gt->Target; + + // Compute full path to object file directory for this target. + std::string dir_max; + dir_max += gt->Makefile->GetCurrentOutputDirectory(); + dir_max += "/"; + dir_max += gt->LocalGenerator->GetTargetDirectory(*target); + dir_max += "/"; + gt->ObjectDirectory = dir_max; +} + +//---------------------------------------------------------------------------- // Private methods void cmGlobalNinjaGenerator::OpenBuildFileStream() diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 7725cf3..e3a22e5 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -299,7 +299,7 @@ public: void AddTargetAlias(const std::string& alias, cmTarget* target); - + virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const; protected: /// Overloaded methods. diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 0e03e89..f9ec0a9 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -108,15 +108,6 @@ void cmGlobalUnixMakefileGenerator3 ::ComputeTargetObjects(cmGeneratorTarget* gt) const { - cmTarget* target = gt->Target; - // Compute full path to object file directory for this target. - std::string dir_max; - dir_max += gt->Makefile->GetCurrentOutputDirectory(); - dir_max += "/"; - dir_max += gt->LocalGenerator->GetTargetDirectory(*target); - dir_max += "/"; - gt->ObjectDirectory = dir_max; - std::vector objectSources; gt->GetObjectSources(objectSources); // Compute the name of each object file. @@ -126,11 +117,27 @@ cmGlobalUnixMakefileGenerator3 { cmSourceFile* sf = *si; std::string objectName = gt->LocalGenerator - ->GetObjectFileNameWithoutTarget(*sf, dir_max); + ->GetObjectFileNameWithoutTarget(*sf, gt->ObjectDirectory); gt->AddObject(sf, objectName); } } +//---------------------------------------------------------------------------- +void +cmGlobalUnixMakefileGenerator3 +::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const +{ + cmTarget* target = gt->Target; + + // Compute full path to object file directory for this target. + std::string dir_max; + dir_max += gt->Makefile->GetCurrentOutputDirectory(); + dir_max += "/"; + dir_max += gt->LocalGenerator->GetTargetDirectory(*target); + dir_max += "/"; + gt->ObjectDirectory = dir_max; +} + void cmGlobalUnixMakefileGenerator3::Configure() { // Initialize CMAKE_EDIT_COMMAND cache entry. diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index 8115176..42453f2 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -128,6 +128,7 @@ public: /** Does the make tool tolerate .NOTPARALLEL? */ virtual bool AllowNotParallel() const { return true; } + virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const; protected: void WriteMainMakefile2(); void WriteMainCMakefile(); diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 69c893c..f3cba5a 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -159,10 +159,15 @@ cmGlobalVisualStudioGenerator } gt->AddObject(sf, objectName); } +} +//---------------------------------------------------------------------------- +void cmGlobalVisualStudioGenerator +::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const +{ std::string dir = gt->Makefile->GetCurrentOutputDirectory(); dir += "/"; - std::string tgtDir = lg->GetTargetDirectory(*gt->Target); + std::string tgtDir = gt->LocalGenerator->GetTargetDirectory(*gt->Target); if(!tgtDir.empty()) { dir += tgtDir; diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h index 7e8dcf8..f957056 100644 --- a/Source/cmGlobalVisualStudioGenerator.h +++ b/Source/cmGlobalVisualStudioGenerator.h @@ -88,6 +88,7 @@ public: virtual std::string ExpandCFGIntDir(const std::string& str, const std::string& config) const; + void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const; protected: // Does this VS version link targets to each other if there are // dependencies in the SLN file? This was done for VS versions diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 36196a2..6c12040 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3964,7 +3964,12 @@ cmGlobalXCodeGenerator gt->AddObject(sf, objectName); } +} +//---------------------------------------------------------------------------- +void cmGlobalXCodeGenerator +::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const +{ const char* configName = this->GetCMakeCFGIntDir(); std::string dir = this->GetObjectsNormalDirectory( "$(PROJECT_NAME)", configName, gt->Target); diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index be81cdc..f9dd58f 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -204,6 +204,7 @@ private: std::vector const& defines, bool dflag = false); + void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const; protected: virtual const char* GetInstallTargetName() const { return "install"; } virtual const char* GetPackageTargetName() const { return "package"; } -- cgit v0.12 From bc51221164330a24e90cf896300ded637b86d740 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 12 Mar 2014 23:43:43 +0100 Subject: cmGeneratorTarget: Constify the AddObject API. The storage is already const. --- Source/cmGeneratorTarget.cxx | 3 ++- Source/cmGeneratorTarget.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index db88749..1d8d2dd 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -321,7 +321,8 @@ const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file) return this->Objects[file]; } -void cmGeneratorTarget::AddObject(cmSourceFile *sf, std::string const&name) +void cmGeneratorTarget::AddObject(cmSourceFile const* sf, + std::string const&name) { this->Objects[sf] = name; } diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 81a447f..e5ed271 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -35,7 +35,7 @@ public: void GetObjectSources(std::vector &) const; const std::string& GetObjectName(cmSourceFile const* file); - void AddObject(cmSourceFile *sf, std::string const&name); + void AddObject(cmSourceFile const* sf, std::string const&name); bool HasExplicitObjectName(cmSourceFile const* file) const; void AddExplicitObjectName(cmSourceFile* sf); -- cgit v0.12 From 6132d979d9d7877f5b116a2a110245adbb89e1b7 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 13 Mar 2014 12:28:32 +0100 Subject: cmGeneratorTarget: Constify the AddExplicitObjectName API. The storage is already const. --- Source/cmGeneratorTarget.cxx | 2 +- Source/cmGeneratorTarget.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 1d8d2dd..4d335cd 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -328,7 +328,7 @@ void cmGeneratorTarget::AddObject(cmSourceFile const* sf, } //---------------------------------------------------------------------------- -void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile* sf) +void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf) { this->ExplicitObjectName.insert(sf); } diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index e5ed271..d1a0e06 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -37,7 +37,7 @@ public: void AddObject(cmSourceFile const* sf, std::string const&name); bool HasExplicitObjectName(cmSourceFile const* file) const; - void AddExplicitObjectName(cmSourceFile* sf); + void AddExplicitObjectName(cmSourceFile const* sf); void GetResxSources(std::vector&) const; void GetIDLSources(std::vector&) const; -- cgit v0.12 From 04cf50ff62a022296832cef6b48fb532508eb853 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 12 Mar 2014 23:45:43 +0100 Subject: cmOSXBundleGenerator: Make MacOSXContentGeneratorType arg const. --- Source/cmMakefileTargetGenerator.cxx | 2 +- Source/cmMakefileTargetGenerator.h | 2 +- Source/cmNinjaTargetGenerator.cxx | 2 +- Source/cmNinjaTargetGenerator.h | 2 +- Source/cmOSXBundleGenerator.h | 3 ++- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 3161aba..fdca7f7 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -373,7 +373,7 @@ void cmMakefileTargetGenerator::WriteTargetLanguageFlags() //---------------------------------------------------------------------------- void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator() - (cmSourceFile& source, const char* pkgloc) + (cmSourceFile const& source, const char* pkgloc) { // Skip OS X content when not building a Framework or Bundle. if(!this->Generator->GetTarget()->IsBundleOnApple()) diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index 97c58b9..f59bd9b 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -81,7 +81,7 @@ protected: MacOSXContentGeneratorType(cmMakefileTargetGenerator* gen) : Generator(gen) {} - void operator()(cmSourceFile& source, const char* pkgloc); + void operator()(cmSourceFile const& source, const char* pkgloc); private: cmMakefileTargetGenerator* Generator; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index ed3782c..149b129 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -733,7 +733,7 @@ cmNinjaTargetGenerator //---------------------------------------------------------------------------- void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()( - cmSourceFile& source, const char* pkgloc) + cmSourceFile const& source, const char* pkgloc) { // Skip OS X content when not building a Framework or Bundle. if(!this->Generator->GetTarget()->IsBundleOnApple()) diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index e66e55f..900e2bd 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -129,7 +129,7 @@ protected: MacOSXContentGeneratorType(cmNinjaTargetGenerator* g) : Generator(g) {} - void operator()(cmSourceFile& source, const char* pkgloc); + void operator()(cmSourceFile const& source, const char* pkgloc); private: cmNinjaTargetGenerator* Generator; diff --git a/Source/cmOSXBundleGenerator.h b/Source/cmOSXBundleGenerator.h index 95b4aef..5acdd9f 100644 --- a/Source/cmOSXBundleGenerator.h +++ b/Source/cmOSXBundleGenerator.h @@ -44,7 +44,8 @@ public: struct MacOSXContentGeneratorType { virtual ~MacOSXContentGeneratorType() {} - virtual void operator()(cmSourceFile& source, const char* pkgloc) = 0; + virtual void operator()(cmSourceFile const& source, + const char* pkgloc) = 0; }; void GenerateMacOSXContentStatements( -- cgit v0.12 From dcfcd23ed53d3bfe8ef299b8a3a38c47c27fa6b6 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 13 Mar 2014 00:19:50 +0100 Subject: cmGeneratorTarget: Make GetSourceDepends const. --- Source/cmGeneratorTarget.cxx | 2 +- Source/cmGeneratorTarget.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 4d335cd..bde60b8 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -241,7 +241,7 @@ const char *cmGeneratorTarget::GetProperty(const std::string& prop) const //---------------------------------------------------------------------------- std::vector const* -cmGeneratorTarget::GetSourceDepends(cmSourceFile* sf) const +cmGeneratorTarget::GetSourceDepends(cmSourceFile const* sf) const { SourceEntriesType::const_iterator i = this->SourceEntries.find(sf); if(i != this->SourceEntries.end()) diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index d1a0e06..1c4276c 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -87,7 +87,8 @@ public: void LookupObjectLibraries(); /** Get sources that must be built before the given source. */ - std::vector const* GetSourceDepends(cmSourceFile* sf) const; + std::vector const* + GetSourceDepends(cmSourceFile const* sf) const; /** * Flags for a given source file as used in this target. Typically assigned @@ -121,7 +122,7 @@ public: private: friend class cmTargetTraceDependencies; struct SourceEntry { std::vector Depends; }; - typedef std::map SourceEntriesType; + typedef std::map SourceEntriesType; SourceEntriesType SourceEntries; std::map Objects; -- cgit v0.12 From c725bb3cbd51edd4043f81d01b7a01bbd42adb2f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 12 Mar 2014 23:50:42 +0100 Subject: Constify some APIs in generators. --- Source/cmGlobalVisualStudio10Generator.cxx | 2 +- Source/cmGlobalVisualStudio10Generator.h | 4 ++-- Source/cmMakefileTargetGenerator.cxx | 9 +++++---- Source/cmMakefileTargetGenerator.h | 9 +++++---- Source/cmNinjaTargetGenerator.cxx | 10 +++++----- Source/cmNinjaTargetGenerator.h | 10 +++++----- Source/cmVisualStudio10TargetGenerator.cxx | 11 ++++++----- Source/cmVisualStudio10TargetGenerator.h | 13 +++++++------ 8 files changed, 36 insertions(+), 32 deletions(-) diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 840e888..37a416b 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -470,7 +470,7 @@ cmGlobalVisualStudio10Generator //---------------------------------------------------------------------------- void cmGlobalVisualStudio10Generator::PathTooLong( - cmTarget* target, cmSourceFile* sf, std::string const& sfRel) + cmTarget* target, cmSourceFile const* sf, std::string const& sfRel) { size_t len = (strlen(target->GetMakefile()->GetCurrentOutputDirectory()) + 1 + sfRel.length()); diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 999a9d5..ede6b1b 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -87,7 +87,7 @@ public: /** Generate an .rule file path for a given command output. */ virtual std::string GenerateRuleFile(std::string const& output) const; - void PathTooLong(cmTarget* target, cmSourceFile* sf, + void PathTooLong(cmTarget* target, cmSourceFile const* sf, std::string const& sfRel); virtual const char* GetToolsVersion() { return "4.0"; } @@ -112,7 +112,7 @@ private: LongestSourcePath(): Length(0), Target(0), SourceFile(0) {} size_t Length; cmTarget* Target; - cmSourceFile* SourceFile; + cmSourceFile const* SourceFile; std::string SourceRel; }; LongestSourcePath LongestSource; diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index fdca7f7..32e1c1a 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -423,7 +423,8 @@ cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator() } //---------------------------------------------------------------------------- -void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source) +void cmMakefileTargetGenerator +::WriteObjectRuleFiles(cmSourceFile const& source) { // Identify the language of the source file. const std::string& lang = @@ -498,7 +499,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source) //---------------------------------------------------------------------------- void cmMakefileTargetGenerator -::AppendFortranFormatFlags(std::string& flags, cmSourceFile& source) +::AppendFortranFormatFlags(std::string& flags, cmSourceFile const& source) { const char* srcfmt = source.GetProperty("Fortran_FORMAT"); cmLocalGenerator::FortranFormat format = @@ -529,7 +530,7 @@ void cmMakefileTargetGenerator ::WriteObjectBuildFile(std::string &obj, const std::string& lang, - cmSourceFile& source, + cmSourceFile const& source, std::vector& depends) { this->LocalGenerator->AppendRuleDepend(depends, @@ -1194,7 +1195,7 @@ cmMakefileTargetGenerator //---------------------------------------------------------------------------- void cmMakefileTargetGenerator -::WriteObjectDependRules(cmSourceFile& source, +::WriteObjectDependRules(cmSourceFile const& source, std::vector& depends) { // Create the list of dependencies known at cmake time. These are diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index f59bd9b..7ff6da9 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -89,16 +89,16 @@ protected: friend struct MacOSXContentGeneratorType; // write the rules for an object - void WriteObjectRuleFiles(cmSourceFile& source); + void WriteObjectRuleFiles(cmSourceFile const& source); // write the build rule for an object void WriteObjectBuildFile(std::string &obj, const std::string& lang, - cmSourceFile& source, + cmSourceFile const& source, std::vector& depends); // write the depend.make file for an object - void WriteObjectDependRules(cmSourceFile& source, + void WriteObjectDependRules(cmSourceFile const& source, std::vector& depends); // write the build rule for a custom command @@ -126,7 +126,8 @@ protected: // Return the a string with -F flags on apple std::string GetFrameworkFlags(std::string const& l); - void AppendFortranFormatFlags(std::string& flags, cmSourceFile& source); + void AppendFortranFormatFlags(std::string& flags, + cmSourceFile const& source); // append intertarget dependencies void AppendTargetDepends(std::vector& depends); diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 149b129..3738ca7 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -126,7 +126,7 @@ void cmNinjaTargetGenerator::AddFeatureFlags(std::string& flags, // void cmMakefileTargetGenerator::WriteTargetLanguageFlags() // Refactor it. std::string -cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile *source, +cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile const* source, const std::string& language) { // TODO: Fortran support. @@ -211,7 +211,7 @@ bool cmNinjaTargetGenerator::needsDepFile(const std::string& lang) // void cmMakefileTargetGenerator::WriteTargetLanguageFlags(). std::string cmNinjaTargetGenerator:: -ComputeDefines(cmSourceFile *source, const std::string& language) +ComputeDefines(cmSourceFile const* source, const std::string& language) { std::set defines; @@ -269,14 +269,14 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const std::string cmNinjaTargetGenerator -::GetSourceFilePath(cmSourceFile* source) const +::GetSourceFilePath(cmSourceFile const* source) const { return ConvertToNinjaPath(source->GetFullPath().c_str()); } std::string cmNinjaTargetGenerator -::GetObjectFilePath(cmSourceFile* source) const +::GetObjectFilePath(cmSourceFile const* source) const { std::string path = this->LocalGenerator->GetHomeRelativeOutputPath(); if(!path.empty()) @@ -536,7 +536,7 @@ cmNinjaTargetGenerator void cmNinjaTargetGenerator -::WriteObjectBuildStatement(cmSourceFile* source) +::WriteObjectBuildStatement(cmSourceFile const* source) { std::string comment; const std::string language = source->GetLanguage(); diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 900e2bd..8669e6e 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -79,10 +79,10 @@ protected: * @note Generally it is the value of the variable whose name is computed * by LanguageFlagsVarName(). */ - std::string ComputeFlagsForObject(cmSourceFile *source, + std::string ComputeFlagsForObject(cmSourceFile const* source, const std::string& language); - std::string ComputeDefines(cmSourceFile *source, + std::string ComputeDefines(cmSourceFile const* source, const std::string& language); std::string ConvertToNinjaPath(const char *path) const { @@ -96,10 +96,10 @@ protected: cmNinjaDeps ComputeLinkDeps() const; /// @return the source file path for the given @a source. - std::string GetSourceFilePath(cmSourceFile* source) const; + std::string GetSourceFilePath(cmSourceFile const* source) const; /// @return the object file path for the given @a source. - std::string GetObjectFilePath(cmSourceFile* source) const; + std::string GetObjectFilePath(cmSourceFile const* source) const; /// @return the file path where the target named @a name is generated. std::string GetTargetFilePath(const std::string& name) const; @@ -110,7 +110,7 @@ protected: void WriteLanguageRules(const std::string& language); void WriteCompileRule(const std::string& language); void WriteObjectBuildStatements(); - void WriteObjectBuildStatement(cmSourceFile* source); + void WriteObjectBuildStatement(cmSourceFile const* source); void WriteCustomCommandBuildStatement(cmCustomCommand *cc); cmNinjaDeps GetObjects() const diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 7c55f64..cc1fdbc 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -562,7 +562,8 @@ void cmVisualStudio10TargetGenerator::WriteCustomCommands() } //---------------------------------------------------------------------------- -void cmVisualStudio10TargetGenerator::WriteCustomCommand(cmSourceFile* sf) +void cmVisualStudio10TargetGenerator +::WriteCustomCommand(cmSourceFile const* sf) { if(this->SourcesVisited.insert(sf).second) { @@ -585,7 +586,7 @@ void cmVisualStudio10TargetGenerator::WriteCustomCommand(cmSourceFile* sf) } void -cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile* source, +cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile const* source, cmCustomCommand const & command) { @@ -928,7 +929,7 @@ WriteGroupSources(const char* name, } void cmVisualStudio10TargetGenerator::WriteSource( - const char* tool, cmSourceFile* sf, const char* end) + const char* tool, cmSourceFile const* sf, const char* end) { // Visual Studio tools append relative paths to the current dir, as in: // @@ -1091,9 +1092,9 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() } bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( - cmSourceFile* source) + cmSourceFile const* source) { - cmSourceFile& sf = *source; + cmSourceFile const& sf = *source; std::string objectName; if(this->GeneratorTarget->HasExplicitObjectName(&sf)) diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 02b951c..8faeb8e 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -45,7 +45,7 @@ public: private: struct ToolSource { - cmSourceFile* SourceFile; + cmSourceFile const* SourceFile; bool RelativePath; }; struct ToolSources: public std::vector {}; @@ -55,7 +55,8 @@ private: void WriteString(const char* line, int indentLevel); void WriteProjectConfigurations(); void WriteProjectConfigurationValues(); - void WriteSource(const char* tool, cmSourceFile* sf, const char* end = 0); + void WriteSource(const char* tool, cmSourceFile const* sf, + const char* end = 0); void WriteSources(const char* tool, std::vector const&); void WriteAllSources(); void WriteDotNetReferences(); @@ -77,13 +78,13 @@ private: std::vector const & includes); void OutputIncludes(std::vector const & includes); void OutputLinkIncremental(std::string const& configName); - void WriteCustomRule(cmSourceFile* source, + void WriteCustomRule(cmSourceFile const* source, cmCustomCommand const & command); void WriteCustomCommands(); - void WriteCustomCommand(cmSourceFile* sf); + void WriteCustomCommand(cmSourceFile const* sf); void WriteGroups(); void WriteProjectReferences(); - bool OutputSourceSpecificFlags(cmSourceFile* source); + bool OutputSourceSpecificFlags(cmSourceFile const* source); void AddLibraries(cmComputeLinkInformation& cli, std::string& libstring); void WriteLibOptions(std::string const& config); void WriteEvents(std::string const& configName); @@ -111,7 +112,7 @@ private: cmGlobalVisualStudio10Generator* GlobalGenerator; cmGeneratedFileStream* BuildFileStream; cmLocalVisualStudio7Generator* LocalGenerator; - std::set SourcesVisited; + std::set SourcesVisited; typedef std::map ToolSourceMap; ToolSourceMap Tools; -- cgit v0.12 From 9ad804ac7be18efb92040434808f89174586b13d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 12 Mar 2014 23:06:05 +0100 Subject: cmGeneratorTarget: Constify cmSourceFile* in containers. Some of them will be used with other APIs which require value_type to be cmSourceFile const*. --- Source/cmGeneratorTarget.cxx | 27 +++++++++++++++---------- Source/cmGeneratorTarget.h | 18 ++++++++--------- Source/cmGlobalNinjaGenerator.cxx | 6 +++--- Source/cmGlobalUnixMakefileGenerator3.cxx | 6 +++--- Source/cmGlobalVisualStudioGenerator.cxx | 10 +++++----- Source/cmGlobalXCodeGenerator.cxx | 6 +++--- Source/cmLocalUnixMakefileGenerator3.cxx | 6 +++--- Source/cmMakefileTargetGenerator.cxx | 16 +++++++-------- Source/cmNinjaTargetGenerator.cxx | 20 +++++++++---------- Source/cmOSXBundleGenerator.cxx | 7 ++++--- Source/cmOSXBundleGenerator.h | 2 +- Source/cmVisualStudio10TargetGenerator.cxx | 32 +++++++++++++++--------------- Source/cmVisualStudio10TargetGenerator.h | 3 ++- 13 files changed, 84 insertions(+), 75 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index bde60b8..8efd7bb 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -97,7 +97,7 @@ struct DoAccept template<> struct DoAccept { - static void Do(std::vector& files, cmSourceFile* f) + static void Do(std::vector& files, cmSourceFile* f) { files.push_back(f); } @@ -120,7 +120,7 @@ struct DoAccept }; //---------------------------------------------------------------------------- -template > +template > struct TagVisitor { DataType& Data; @@ -306,7 +306,8 @@ static void handleSystemIncludesDep(cmMakefile *mf, cmTarget* depTgt, //---------------------------------------------------------------------------- void -cmGeneratorTarget::GetObjectSources(std::vector &data) const +cmGeneratorTarget +::GetObjectSources(std::vector &data) const { IMPLEMENT_VISIT(ObjectSources); if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY) @@ -342,34 +343,39 @@ bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const } //---------------------------------------------------------------------------- -void cmGeneratorTarget::GetIDLSources(std::vector& data) const +void cmGeneratorTarget +::GetIDLSources(std::vector& data) const { IMPLEMENT_VISIT(IDLSources); } //---------------------------------------------------------------------------- void -cmGeneratorTarget::GetHeaderSources(std::vector& data) const +cmGeneratorTarget +::GetHeaderSources(std::vector& data) const { IMPLEMENT_VISIT(HeaderSources); } //---------------------------------------------------------------------------- -void cmGeneratorTarget::GetExtraSources(std::vector& data) const +void cmGeneratorTarget +::GetExtraSources(std::vector& data) const { IMPLEMENT_VISIT(ExtraSources); } //---------------------------------------------------------------------------- void -cmGeneratorTarget::GetCustomCommands(std::vector& data) const +cmGeneratorTarget +::GetCustomCommands(std::vector& data) const { IMPLEMENT_VISIT(CustomCommands); } //---------------------------------------------------------------------------- void -cmGeneratorTarget::GetExternalObjects(std::vector& data) const +cmGeneratorTarget +::GetExternalObjects(std::vector& data) const { IMPLEMENT_VISIT(ExternalObjects); } @@ -384,7 +390,8 @@ cmGeneratorTarget::GetExpectedResxHeaders(std::set& srcs) const } //---------------------------------------------------------------------------- -void cmGeneratorTarget::GetResxSources(std::vector& srcs) const +void cmGeneratorTarget +::GetResxSources(std::vector& srcs) const { ResxData data; IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData) @@ -570,7 +577,7 @@ cmGeneratorTarget::UseObjectLibraries(std::vector& objs) const cmTarget* objLib = *ti; cmGeneratorTarget* ogt = this->GlobalGenerator->GetGeneratorTarget(objLib); - for(std::vector::const_iterator + for(std::vector::const_iterator si = ogt->ObjectSources.begin(); si != ogt->ObjectSources.end(); ++si) { diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 1c4276c..139e736 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -32,19 +32,19 @@ public: bool GetPropertyAsBool(const std::string& prop) const; void GetSourceFiles(std::vector& files) const; - void GetObjectSources(std::vector &) const; + void GetObjectSources(std::vector &) const; const std::string& GetObjectName(cmSourceFile const* file); void AddObject(cmSourceFile const* sf, std::string const&name); bool HasExplicitObjectName(cmSourceFile const* file) const; void AddExplicitObjectName(cmSourceFile const* sf); - void GetResxSources(std::vector&) const; - void GetIDLSources(std::vector&) const; - void GetExternalObjects(std::vector&) const; - void GetHeaderSources(std::vector&) const; - void GetExtraSources(std::vector&) const; - void GetCustomCommands(std::vector&) const; + void GetResxSources(std::vector&) const; + void GetIDLSources(std::vector&) const; + void GetExternalObjects(std::vector&) const; + void GetHeaderSources(std::vector&) const; + void GetExtraSources(std::vector&) const; + void GetCustomCommands(std::vector&) const; void GetExpectedResxHeaders(std::set&) const; cmTarget* Target; @@ -117,7 +117,7 @@ public: struct ResxData { mutable std::set ExpectedResxHeaders; - mutable std::vector ResxSources; + mutable std::vector ResxSources; }; private: friend class cmTargetTraceDependencies; @@ -127,7 +127,7 @@ private: std::map Objects; std::set ExplicitObjectName; - mutable std::vector ObjectSources; + mutable std::vector ObjectSources; std::vector ObjectLibraries; mutable std::map > SystemIncludesCache; diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 686414d..e9c31e9 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -634,14 +634,14 @@ std::string cmGlobalNinjaGenerator::GetEditCacheCommand() const // TODO: Refactor to combine with cmGlobalUnixMakefileGenerator3 impl. void cmGlobalNinjaGenerator::ComputeTargetObjects(cmGeneratorTarget* gt) const { - std::vector objectSources; + std::vector objectSources; gt->GetObjectSources(objectSources); // Compute the name of each object file. - for(std::vector::iterator + for(std::vector::iterator si = objectSources.begin(); si != objectSources.end(); ++si) { - cmSourceFile* sf = *si; + cmSourceFile const* sf = *si; std::string objectName = gt->LocalGenerator ->GetObjectFileNameWithoutTarget(*sf, gt->ObjectDirectory); gt->AddObject(sf, objectName); diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index f9ec0a9..6ce8678 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -108,14 +108,14 @@ void cmGlobalUnixMakefileGenerator3 ::ComputeTargetObjects(cmGeneratorTarget* gt) const { - std::vector objectSources; + std::vector objectSources; gt->GetObjectSources(objectSources); // Compute the name of each object file. - for(std::vector::iterator + for(std::vector::iterator si = objectSources.begin(); si != objectSources.end(); ++si) { - cmSourceFile* sf = *si; + cmSourceFile const* sf = *si; std::string objectName = gt->LocalGenerator ->GetObjectFileNameWithoutTarget(*sf, gt->ObjectDirectory); gt->AddObject(sf, objectName); diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index f3cba5a..bd57d0c 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -129,13 +129,13 @@ cmGlobalVisualStudioGenerator // Count the number of object files with each name. Note that // windows file names are not case sensitive. std::map counts; - std::vector objectSources; + std::vector objectSources; gt->GetObjectSources(objectSources); - for(std::vector::const_iterator + for(std::vector::const_iterator si = objectSources.begin(); si != objectSources.end(); ++si) { - cmSourceFile* sf = *si; + cmSourceFile const* sf = *si; std::string objectNameLower = cmSystemTools::LowerCase( cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())); objectNameLower += ".obj"; @@ -144,11 +144,11 @@ cmGlobalVisualStudioGenerator // For all source files producing duplicate names we need unique // object name computation. - for(std::vector::const_iterator + for(std::vector::const_iterator si = objectSources.begin(); si != objectSources.end(); ++si) { - cmSourceFile* sf = *si; + cmSourceFile const* sf = *si; std::string objectName = cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()); objectName += ".obj"; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 6c12040..4904d51 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3944,13 +3944,13 @@ cmGlobalXCodeGenerator // 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; + std::vector objectSources; gt->GetObjectSources(objectSources); - for(std::vector::const_iterator + for(std::vector::const_iterator si = objectSources.begin(); si != objectSources.end(); ++si) { - cmSourceFile* sf = *si; + cmSourceFile const* sf = *si; std::string objectName = cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()); objectName += ".o"; diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index a838ce3..79240e1 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -185,7 +185,7 @@ GetLocalObjectFiles(std::map &localObjectFiles) { continue; } - std::vector objectSources; + std::vector objectSources; gt->GetObjectSources(objectSources); // Compute full path to object file directory for this target. std::string dir_max; @@ -194,11 +194,11 @@ GetLocalObjectFiles(std::map &localObjectFiles) dir_max += this->GetTargetDirectory(*gt->Target); dir_max += "/"; // Compute the name of each object file. - for(std::vector::iterator + for(std::vector::iterator si = objectSources.begin(); si != objectSources.end(); ++si) { - cmSourceFile* sf = *si; + cmSourceFile const* sf = *si; bool hasSourceExtension = true; std::string objectName = this->GetObjectFileNameWithoutTarget(*sf, dir_max, diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 32e1c1a..6759d05 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -153,9 +153,9 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() // First generate the object rule files. Save a list of all object // files for this target. - std::vector customCommands; + std::vector customCommands; this->GeneratorTarget->GetCustomCommands(customCommands); - for(std::vector::const_iterator + for(std::vector::const_iterator si = customCommands.begin(); si != customCommands.end(); ++si) { @@ -176,27 +176,27 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() } } } - std::vector headerSources; + std::vector headerSources; this->GeneratorTarget->GetHeaderSources(headerSources); this->OSXBundleGenerator->GenerateMacOSXContentStatements( headerSources, this->MacOSXContentGenerator); - std::vector extraSources; + std::vector extraSources; this->GeneratorTarget->GetExtraSources(extraSources); this->OSXBundleGenerator->GenerateMacOSXContentStatements( extraSources, this->MacOSXContentGenerator); - std::vector externalObjects; + std::vector externalObjects; this->GeneratorTarget->GetExternalObjects(externalObjects); - for(std::vector::const_iterator + for(std::vector::const_iterator si = externalObjects.begin(); si != externalObjects.end(); ++si) { this->ExternalObjects.push_back((*si)->GetFullPath()); } - std::vector objectSources; + std::vector objectSources; this->GeneratorTarget->GetObjectSources(objectSources); - for(std::vector::const_iterator + for(std::vector::const_iterator si = objectSources.begin(); si != objectSources.end(); ++si) { // Generate this object file's rule file. diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 3738ca7..4319f3c 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -480,36 +480,36 @@ cmNinjaTargetGenerator << this->GetTargetName() << "\n\n"; - std::vector customCommands; + std::vector customCommands; this->GeneratorTarget->GetCustomCommands(customCommands); - for(std::vector::const_iterator + for(std::vector::const_iterator si = customCommands.begin(); si != customCommands.end(); ++si) { cmCustomCommand const* cc = (*si)->GetCustomCommand(); this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget()); } - std::vector headerSources; + std::vector headerSources; this->GeneratorTarget->GetHeaderSources(headerSources); this->OSXBundleGenerator->GenerateMacOSXContentStatements( headerSources, this->MacOSXContentGenerator); - std::vector extraSources; + std::vector extraSources; this->GeneratorTarget->GetExtraSources(extraSources); this->OSXBundleGenerator->GenerateMacOSXContentStatements( extraSources, this->MacOSXContentGenerator); - std::vector externalObjects; + std::vector externalObjects; this->GeneratorTarget->GetExternalObjects(externalObjects); - for(std::vector::const_iterator + for(std::vector::const_iterator si = externalObjects.begin(); si != externalObjects.end(); ++si) { this->Objects.push_back(this->GetSourceFilePath(*si)); } - std::vector objectSources; + std::vector objectSources; this->GeneratorTarget->GetObjectSources(objectSources); - for(std::vector::const_iterator + for(std::vector::const_iterator si = objectSources.begin(); si != objectSources.end(); ++si) { this->WriteObjectBuildStatement(*si); @@ -570,9 +570,9 @@ cmNinjaTargetGenerator } // Add order-only dependencies on custom command outputs. - std::vector customCommands; + std::vector customCommands; this->GeneratorTarget->GetCustomCommands(customCommands); - for(std::vector::const_iterator + for(std::vector::const_iterator si = customCommands.begin(); si != customCommands.end(); ++si) { diff --git a/Source/cmOSXBundleGenerator.cxx b/Source/cmOSXBundleGenerator.cxx index 835f892..6f16913 100644 --- a/Source/cmOSXBundleGenerator.cxx +++ b/Source/cmOSXBundleGenerator.cxx @@ -190,13 +190,14 @@ void cmOSXBundleGenerator::CreateCFBundle(const std::string& targetName, //---------------------------------------------------------------------------- void cmOSXBundleGenerator:: -GenerateMacOSXContentStatements(std::vector const& sources, - MacOSXContentGeneratorType* generator) +GenerateMacOSXContentStatements( + std::vector const& sources, + MacOSXContentGeneratorType* generator) { if (this->MustSkip()) return; - for(std::vector::const_iterator + for(std::vector::const_iterator si = sources.begin(); si != sources.end(); ++si) { cmGeneratorTarget::SourceFileFlags tsFlags = diff --git a/Source/cmOSXBundleGenerator.h b/Source/cmOSXBundleGenerator.h index 5acdd9f..f945c15 100644 --- a/Source/cmOSXBundleGenerator.h +++ b/Source/cmOSXBundleGenerator.h @@ -49,7 +49,7 @@ public: }; void GenerateMacOSXContentStatements( - std::vector const& sources, + std::vector const& sources, MacOSXContentGeneratorType* generator); std::string InitMacOSXContentDirectory(const char* pkgloc); diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index cc1fdbc..b8631ca 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -377,12 +377,12 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences() void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() { - std::vector resxObjs; + std::vector resxObjs; this->GeneratorTarget->GetResxSources(resxObjs); if(!resxObjs.empty()) { this->WriteString("\n", 1); - for(std::vector::const_iterator oi = resxObjs.begin(); + for(std::vector::const_iterator oi = resxObjs.begin(); oi != resxObjs.end(); ++oi) { std::string obj = (*oi)->GetFullPath(); @@ -551,9 +551,9 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues() void cmVisualStudio10TargetGenerator::WriteCustomCommands() { this->SourcesVisited.clear(); - std::vector customCommands; + std::vector customCommands; this->GeneratorTarget->GetCustomCommands(customCommands); - for(std::vector::const_iterator + for(std::vector::const_iterator si = customCommands.begin(); si != customCommands.end(); ++si) { @@ -746,12 +746,12 @@ void cmVisualStudio10TargetGenerator::WriteGroups() this->WriteGroupSources(ti->first.c_str(), ti->second, sourceGroups); } - std::vector resxObjs; + std::vector resxObjs; this->GeneratorTarget->GetResxSources(resxObjs); if(!resxObjs.empty()) { this->WriteString("\n", 1); - for(std::vector::const_iterator oi = resxObjs.begin(); + for(std::vector::const_iterator oi = resxObjs.begin(); oi != resxObjs.end(); ++oi) { std::string obj = (*oi)->GetFullPath(); @@ -902,7 +902,7 @@ WriteGroupSources(const char* name, for(ToolSources::const_iterator s = sources.begin(); s != sources.end(); ++s) { - cmSourceFile* sf = s->SourceFile; + cmSourceFile const* sf = s->SourceFile; std::string const& source = sf->GetFullPath(); cmSourceGroup* sourceGroup = this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); @@ -985,9 +985,9 @@ void cmVisualStudio10TargetGenerator::WriteSource( } void cmVisualStudio10TargetGenerator::WriteSources( - const char* tool, std::vector const& sources) + const char* tool, std::vector const& sources) { - for(std::vector::const_iterator + for(std::vector::const_iterator si = sources.begin(); si != sources.end(); ++si) { this->WriteSource(tool, *si); @@ -1002,16 +1002,16 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() } this->WriteString("\n", 1); - std::vector headerSources; + std::vector headerSources; this->GeneratorTarget->GetHeaderSources(headerSources); this->WriteSources("ClInclude", headerSources); - std::vector idlSources; + std::vector idlSources; this->GeneratorTarget->GetIDLSources(idlSources); this->WriteSources("Midl", idlSources); - std::vector objectSources; + std::vector objectSources; this->GeneratorTarget->GetObjectSources(objectSources); - for(std::vector::const_iterator + for(std::vector::const_iterator si = objectSources.begin(); si != objectSources.end(); ++si) { @@ -1050,7 +1050,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() } } - std::vector externalObjects; + std::vector externalObjects; this->GeneratorTarget->GetExternalObjects(externalObjects); if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10) { @@ -1062,7 +1062,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() { // If an object file is generated in this target, then vs10 will use // it in the build, and we have to list it as None instead of Object. - for(std::vector::const_iterator + for(std::vector::const_iterator si = externalObjects.begin(); si != externalObjects.end(); ++si) { @@ -1072,7 +1072,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() } } - std::vector extraSources; + std::vector extraSources; this->GeneratorTarget->GetExtraSources(extraSources); this->WriteSources("None", extraSources); diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 8faeb8e..d72c6fd 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -57,7 +57,8 @@ private: void WriteProjectConfigurationValues(); void WriteSource(const char* tool, cmSourceFile const* sf, const char* end = 0); - void WriteSources(const char* tool, std::vector const&); + void WriteSources(const char* tool, + std::vector const&); void WriteAllSources(); void WriteDotNetReferences(); void WriteEmbeddedResourceGroup(); -- cgit v0.12 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 From c481fadc07e72193f16a4f1fb9d477db133f1120 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 14 Mar 2014 11:02:47 +0100 Subject: cmGeneratorTarget: Don't store ObjectSources for object libraries. Compute them on demand instead. --- Source/cmGeneratorTarget.cxx | 10 ++++------ Source/cmGeneratorTarget.h | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 8efd7bb..2a144c6 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -310,10 +310,6 @@ cmGeneratorTarget ::GetObjectSources(std::vector &data) const { IMPLEMENT_VISIT(ObjectSources); - if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY) - { - this->ObjectSources = data; - } } //---------------------------------------------------------------------------- @@ -577,9 +573,11 @@ cmGeneratorTarget::UseObjectLibraries(std::vector& objs) const cmTarget* objLib = *ti; cmGeneratorTarget* ogt = this->GlobalGenerator->GetGeneratorTarget(objLib); + std::vector objectSources; + ogt->GetObjectSources(objectSources); for(std::vector::const_iterator - si = ogt->ObjectSources.begin(); - si != ogt->ObjectSources.end(); ++si) + si = objectSources.begin(); + si != objectSources.end(); ++si) { std::string obj = ogt->ObjectDirectory; obj += ogt->Objects[*si]; diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 139e736..53e27c5 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -127,7 +127,6 @@ private: std::map Objects; std::set ExplicitObjectName; - mutable std::vector ObjectSources; std::vector ObjectLibraries; mutable std::map > SystemIncludesCache; -- cgit v0.12 From 6c9dd0ec7b1e000b0bedd567fa52074671d639c9 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 11 Mar 2014 20:39:01 +0100 Subject: cmGlobalGenerator: Make ComputeTargetObjects non-virtual Implement it in terms of the ComputeObjectFilenames virtual method on the local generators. Remove the reimplementation from the global generators which are now all functionally identical. --- Source/cmGlobalGenerator.cxx | 21 +++++++++++++++++++-- Source/cmGlobalGenerator.h | 2 +- Source/cmGlobalNinjaGenerator.cxx | 23 ----------------------- Source/cmGlobalNinjaGenerator.h | 2 -- Source/cmGlobalUnixMakefileGenerator3.cxx | 24 ------------------------ Source/cmGlobalUnixMakefileGenerator3.h | 1 - Source/cmGlobalVisualStudioGenerator.cxx | 24 ------------------------ Source/cmGlobalVisualStudioGenerator.h | 1 - Source/cmGlobalXCodeGenerator.cxx | 24 ------------------------ Source/cmGlobalXCodeGenerator.h | 1 - 10 files changed, 20 insertions(+), 103 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index c9ae799..5b6d729 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1516,9 +1516,26 @@ cmGlobalGenerator::GetGeneratorTarget(cmTarget const* t) const } //---------------------------------------------------------------------------- -void cmGlobalGenerator::ComputeTargetObjects(cmGeneratorTarget*) const +void cmGlobalGenerator::ComputeTargetObjects(cmGeneratorTarget* gt) const { - // Implemented in generator subclasses that need this. + std::vector objectSources; + gt->GetObjectSources(objectSources); + + 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) + { + assert(!it->second.empty()); + gt->AddObject(it->first, it->second); + } } //---------------------------------------------------------------------------- diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index ed07b10..49a418d 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -443,7 +443,7 @@ private: void CreateGeneratorTargets(cmMakefile* mf); void CreateGeneratorTargets(); void ComputeGeneratorTargetObjects(); - virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const; + void ComputeTargetObjects(cmGeneratorTarget* gt) const; void ClearGeneratorMembers(); diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 08507eb..49ce1b5 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -632,29 +632,6 @@ std::string cmGlobalNinjaGenerator::GetEditCacheCommand() const return cmSystemTools::GetCMakeGUICommand(); } -// TODO: Refactor to combine with cmGlobalUnixMakefileGenerator3 impl. -void cmGlobalNinjaGenerator::ComputeTargetObjects(cmGeneratorTarget* gt) const -{ - std::vector objectSources; - gt->GetObjectSources(objectSources); - - 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) - { - assert(!it->second.empty()); - gt->AddObject(it->first, it->second); - } -} - //---------------------------------------------------------------------------- void cmGlobalNinjaGenerator ::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index e3a22e5..f2643af 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -310,8 +310,6 @@ protected: private: virtual std::string GetEditCacheCommand() const; - /// @see cmGlobalGenerator::ComputeTargetObjects - virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const; void OpenBuildFileStream(); void CloseBuildFileStream(); diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 91258ed..4632071 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -106,30 +106,6 @@ std::string cmGlobalUnixMakefileGenerator3::GetEditCacheCommand() const //---------------------------------------------------------------------------- void cmGlobalUnixMakefileGenerator3 -::ComputeTargetObjects(cmGeneratorTarget* gt) const -{ - std::vector objectSources; - gt->GetObjectSources(objectSources); - - 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); - } -} - -//---------------------------------------------------------------------------- -void -cmGlobalUnixMakefileGenerator3 ::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const { cmTarget* target = gt->Target; diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index 42453f2..d003789 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -199,7 +199,6 @@ protected: private: virtual const char* GetBuildIgnoreErrorsFlag() const { return "-i"; } virtual std::string GetEditCacheCommand() const; - virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const; }; #endif diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 9740fbfb..749517c 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -118,30 +118,6 @@ void cmGlobalVisualStudioGenerator::Generate() } //---------------------------------------------------------------------------- -void -cmGlobalVisualStudioGenerator -::ComputeTargetObjects(cmGeneratorTarget* gt) const -{ - std::vector objectSources; - gt->GetObjectSources(objectSources); - - 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); - } -} - -//---------------------------------------------------------------------------- void cmGlobalVisualStudioGenerator ::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const { diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h index f957056..1ab8990 100644 --- a/Source/cmGlobalVisualStudioGenerator.h +++ b/Source/cmGlobalVisualStudioGenerator.h @@ -117,7 +117,6 @@ private: virtual std::string GetVSMakeProgram() = 0; void PrintCompilerAdvice(std::ostream&, std::string const&, const char*) const {} - void ComputeTargetObjects(cmGeneratorTarget* gt) const; void FollowLinkDepends(cmTarget const* target, std::set& linked); diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 0a4b51c..d4eb85b 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3934,30 +3934,6 @@ bool cmGlobalXCodeGenerator::IsMultiConfig() return true; } - //---------------------------------------------------------------------------- -void -cmGlobalXCodeGenerator -::ComputeTargetObjects(cmGeneratorTarget* gt) const -{ - std::vector objectSources; - gt->GetObjectSources(objectSources); - - 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); - } -} - //---------------------------------------------------------------------------- void cmGlobalXCodeGenerator ::ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index f9dd58f..23616b4 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -217,7 +217,6 @@ protected: private: void PrintCompilerAdvice(std::ostream&, std::string const&, const char*) const {} - void ComputeTargetObjects(cmGeneratorTarget* gt) const; std::string GetObjectsNormalDirectory( const std::string &projName, -- cgit v0.12