From e8c0341d86e3f2b9658dfc594641f9ba1b29165b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 2 Aug 2015 10:56:33 +0200 Subject: [PATCH 1/4] cmMakefile: Out-of-line GetProjectName. --- Source/cmMakefile.cxx | 4 ++++ Source/cmMakefile.h | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 2296d5a33..73911a591 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2049,6 +2049,10 @@ void cmMakefile::SetProjectName(const char* p) this->ProjectName = p; } +const char* cmMakefile::GetProjectName() const +{ + return this->ProjectName.c_str(); +} void cmMakefile::AddGlobalLinkInformation(const std::string& name, cmTarget& target) diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 055170a62..959f0e74f 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -279,10 +279,7 @@ public: /** * Get the name of the project for this build. */ - const char* GetProjectName() const - { - return this->ProjectName.c_str(); - } + const char* GetProjectName() const; /** Get the configurations to be generated. */ std::string GetConfigurations(std::vector& configs, From 6ce940ac9701c93be01ed169c6bd23b22e04782f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 2 Aug 2015 10:57:31 +0200 Subject: [PATCH 2/4] cmMakefile: Use std::string in ProjectName API. --- Source/cmCPluginAPI.cxx | 4 +++- Source/cmMakefile.cxx | 4 ++-- Source/cmMakefile.h | 4 ++-- Source/cmProjectCommand.cxx | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 591a2cd81..7da334ef1 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -115,7 +115,9 @@ void CCONV cmAddCacheDefinition(void *arg, const char* name, const char* CCONV cmGetProjectName(void *arg) { cmMakefile *mf = static_cast(arg); - return mf->GetProjectName(); + static std::string name; + name = mf->GetProjectName(); + return name.c_str(); } const char* CCONV cmGetHomeDirectory(void *arg) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 73911a591..abdd76762 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2044,12 +2044,12 @@ void cmMakefile::RemoveCacheDefinition(const std::string& name) this->GetState()->RemoveCacheEntry(name); } -void cmMakefile::SetProjectName(const char* p) +void cmMakefile::SetProjectName(std::string const& p) { this->ProjectName = p; } -const char* cmMakefile::GetProjectName() const +std::string cmMakefile::GetProjectName() const { return this->ProjectName.c_str(); } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 959f0e74f..dfd3e196d 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -274,12 +274,12 @@ public: /** * Specify the name of the project for this build. */ - void SetProjectName(const char*); + void SetProjectName(std::string const& name); /** * Get the name of the project for this build. */ - const char* GetProjectName() const; + std::string GetProjectName() const; /** Get the configurations to be generated. */ std::string GetConfigurations(std::vector& configs, diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx index 46d7e0113..71231259c 100644 --- a/Source/cmProjectCommand.cxx +++ b/Source/cmProjectCommand.cxx @@ -20,7 +20,7 @@ bool cmProjectCommand this->SetError("PROJECT called with incorrect number of arguments"); return false; } - this->Makefile->SetProjectName(args[0].c_str()); + this->Makefile->SetProjectName(args[0]); std::string bindir = args[0]; bindir += "_BINARY_DIR"; From b3f2299e0600f3488aaeb78ebf66d1108201ea17 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 2 Aug 2015 09:41:06 +0200 Subject: [PATCH 3/4] cmState: Move ProjectName from cmMakefile. --- Source/cmMakefile.cxx | 6 +++--- Source/cmMakefile.h | 2 -- Source/cmState.cxx | 12 ++++++++++++ Source/cmState.h | 3 +++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index abdd76762..dbf41cc82 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1525,7 +1525,7 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent) parent->GetProperty("LINK_DIRECTORIES")); // the initial project name - this->ProjectName = parent->ProjectName; + this->SetProjectName(parent->GetProjectName()); // Copy include regular expressions. this->ComplainFileRegularExpression = parent->ComplainFileRegularExpression; @@ -2046,12 +2046,12 @@ void cmMakefile::RemoveCacheDefinition(const std::string& name) void cmMakefile::SetProjectName(std::string const& p) { - this->ProjectName = p; + this->StateSnapshot.SetProjectName(p); } std::string cmMakefile::GetProjectName() const { - return this->ProjectName.c_str(); + return this->StateSnapshot.GetProjectName(); } void cmMakefile::AddGlobalLinkInformation(const std::string& name, diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index dfd3e196d..81bb51002 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -810,8 +810,6 @@ protected: mutable std::set CMP0054ReportedIds; - std::string ProjectName; // project name - // libraries, classes, and executables mutable cmTargets Targets; #if defined(CMAKE_BUILD_WITH_CMAKE) diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 53fdae0d6..6cd58b662 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -75,6 +75,8 @@ struct cmState::BuildsystemDirectoryStateType std::vector CompileOptions; std::vector CompileOptionsBacktraces; + std::string ProjectName; + cmPropertyMap Properties; }; @@ -1312,6 +1314,16 @@ cmState::Directory cmState::Snapshot::GetDirectory() const return Directory(this->Position->BuildSystemDirectory, *this); } +void cmState::Snapshot::SetProjectName(const std::string& name) +{ + this->Position->BuildSystemDirectory->ProjectName = name; +} + +std::string cmState::Snapshot::GetProjectName() const +{ + return this->Position->BuildSystemDirectory->ProjectName; +} + cmState::Directory::Directory( cmLinkedTree::iterator iter, const cmState::Snapshot& snapshot) diff --git a/Source/cmState.h b/Source/cmState.h index e503cd258..c3ff4e8d0 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -86,6 +86,9 @@ public: Directory GetDirectory() const; + void SetProjectName(std::string const& name); + std::string GetProjectName() const; + struct StrictWeakOrder { bool operator()(const cmState::Snapshot& lhs, From 637c56b4e0ce0205f3f28a670881aad07320ff17 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 2 Aug 2015 09:41:11 +0200 Subject: [PATCH 4/4] cmGlobalGenerator: Implement FillProjectMap in terms of cmState. --- Source/cmGlobalGenerator.cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 503c455f9..17bafbe60 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2102,18 +2102,19 @@ void cmGlobalGenerator::FillProjectMap() for(i = 0; i < this->LocalGenerators.size(); ++i) { // for each local generator add all projects - cmLocalGenerator *lg = this->LocalGenerators[i]; + cmState::Snapshot snp = this->LocalGenerators[i]->GetStateSnapshot(); std::string name; do { - if (name != lg->GetMakefile()->GetProjectName()) + std::string snpProjName = snp.GetProjectName(); + if (name != snpProjName) { - name = lg->GetMakefile()->GetProjectName(); + name = snpProjName; this->ProjectMap[name].push_back(this->LocalGenerators[i]); } - lg = lg->GetParent(); + snp = snp.GetBuildsystemDirectoryParent(); } - while (lg); + while (snp.IsValid()); } }