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/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index be7896df1..bdd5b5acd 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2112,18 +2112,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()); } } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 2296d5a33..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; @@ -2044,11 +2044,15 @@ 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; + this->StateSnapshot.SetProjectName(p); } +std::string cmMakefile::GetProjectName() const +{ + return this->StateSnapshot.GetProjectName(); +} void cmMakefile::AddGlobalLinkInformation(const std::string& name, cmTarget& target) diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 055170a62..81bb51002 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -274,15 +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 - { - return this->ProjectName.c_str(); - } + std::string GetProjectName() const; /** Get the configurations to be generated. */ std::string GetConfigurations(std::vector& configs, @@ -813,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/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"; diff --git a/Source/cmState.cxx b/Source/cmState.cxx index a40126508..b30c10b1a 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; std::vector Children; @@ -1322,6 +1324,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 3099384f0..99e537c07 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -88,6 +88,9 @@ public: Directory GetDirectory() const; + void SetProjectName(std::string const& name); + std::string GetProjectName() const; + struct StrictWeakOrder { bool operator()(const cmState::Snapshot& lhs,