diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 67d0d5433..2f68ab031 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -705,7 +705,8 @@ cmTargetTraceDependencies e << "Evaluation output file\n \"" << sf->GetFullPath() << "\"\ndepends on the sources of a target it is used in. This " "is a dependency loop and is not allowed."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->GeneratorTarget + ->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str()); return; } if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second) diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 4fe52dde7..0f61225f5 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -529,7 +529,7 @@ cmGlobalUnixMakefileGenerator3 cmLocalUnixMakefileGenerator3* lg) { // Only subdirectories need these rules. - if(lg->IsRootMakefile()) + if(lg->GetMakefile()->IsRootMakefile()) { return; } @@ -1034,7 +1034,7 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule static_cast(this->LocalGenerators[i]); // for the passed in makefile or if this is the top Makefile wripte out // the targets - if (lg2 == lg || lg->IsRootMakefile()) + if (lg2 == lg || lg->GetMakefile()->IsRootMakefile()) { // for each target Generate the rule files for each target. cmTargets& targets = lg2->GetMakefile()->GetTargets(); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 98accf9cf..6f98ee2a0 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -68,9 +68,20 @@ cmLocalGenerator::~cmLocalGenerator() delete this->Makefile; } -bool cmLocalGenerator::IsRootMakefile() const +void cmLocalGenerator::IssueMessage(cmake::MessageType t, + std::string const& text) const { - return !this->StateSnapshot.GetBuildsystemDirectoryParent().IsValid(); + cmListFileContext lfc; + lfc.FilePath = this->StateSnapshot.GetCurrentSourceDirectory(); + lfc.FilePath += "/CMakeLists.txt"; + + if(!this->GlobalGenerator->GetCMakeInstance()->GetIsInTryCompile()) + { + cmOutputConverter converter(this->StateSnapshot); + lfc.FilePath = converter.Convert(lfc.FilePath, cmLocalGenerator::HOME); + } + lfc.Line = 0; + this->GlobalGenerator->GetCMakeInstance()->IssueMessage(t, text, lfc); } //---------------------------------------------------------------------------- @@ -98,7 +109,7 @@ void cmLocalGenerator::ComputeObjectMaxPath() w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax << ", which is less than the minimum of 128. " << "The value will be ignored."; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->IssueMessage(cmake::AUTHOR_WARNING, w.str()); } } else @@ -107,7 +118,7 @@ void cmLocalGenerator::ComputeObjectMaxPath() w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen << "\", which fails to parse as a positive integer. " << "The value will be ignored."; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->IssueMessage(cmake::AUTHOR_WARNING, w.str()); } } this->ObjectMaxPathViolations.clear(); @@ -1317,7 +1328,7 @@ void cmLocalGenerator::AddCompileOptions( "higher \"" << it->first << "_STANDARD\" \"" << standard << "\". " "This is not permitted. The COMPILE_FEATURES may not both depend on " "and be depended on by the link implementation." << std::endl; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(cmake::FATAL_ERROR, e.str()); return; } } @@ -1330,7 +1341,7 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, const std::string& lang, const std::string& config, bool stripImplicitInclDirs - ) + ) const { // Need to decide whether to automatically include the source and // binary directories at the beginning of the include path. @@ -2041,7 +2052,7 @@ AddCompilerRequirementFlag(std::string &flags, cmTarget const* target, "dialect \"" << lang << standardProp << "\" " << (ext ? "(with compiler extensions)" : "") << ", but CMake " "does not know the compile flags to use to enable it."; - this->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(cmake::FATAL_ERROR, e.str()); } else { @@ -2085,7 +2096,7 @@ AddCompilerRequirementFlag(std::string &flags, cmTarget const* target, std::string e = "CMAKE_" + lang + "_STANDARD_DEFAULT is set to invalid value '" + std::string(defaultStd) + "'"; - this->Makefile->IssueMessage(cmake::INTERNAL_ERROR, e); + this->IssueMessage(cmake::INTERNAL_ERROR, e); return; } @@ -2301,7 +2312,7 @@ bool cmLocalGenerator::GetShouldUseOldFlags(bool shared, << flagsVar << " was removed.\n" << cmPolicies::GetPolicyWarning(cmPolicies::CMP0018); - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->IssueMessage(cmake::AUTHOR_WARNING, e.str()); // fall through to OLD behaviour } case cmPolicies::OLD: @@ -2813,7 +2824,7 @@ cmLocalGenerator << " " << ssin << "\n" << "cannot be safely placed under this directory. " << "The build may not work correctly."; - this->Makefile->IssueMessage(cmake::WARNING, m.str()); + this->IssueMessage(cmake::WARNING, m.str()); } } #else diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 6a8c5aa5f..98f4d3a22 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -14,6 +14,7 @@ #include "cmStandardIncludes.h" #include "cmState.h" +#include "cmake.h" #include "cmOutputConverter.h" class cmMakefile; @@ -39,9 +40,6 @@ public: cmState::Snapshot snapshot); virtual ~cmLocalGenerator(); - /// @return whether we are processing the top CMakeLists.txt file. - bool IsRootMakefile() const; - /** * Generate the makefile for this directory. */ @@ -185,7 +183,7 @@ public: cmGeneratorTarget* target, const std::string& lang = "C", const std::string& config = "", - bool stripImplicitInclDirs = true); + bool stripImplicitInclDirs = true) const; void AddCompileOptions(std::string& flags, cmTarget* target, const std::string& lang, const std::string& config); void AddCompileDefinitions(std::set& defines, @@ -304,6 +302,9 @@ public: bool IsMinGWMake() const; bool IsNMake() const; + void IssueMessage(cmake::MessageType t, std::string const& text) const; + + void ComputeObjectMaxPath(); protected: ///! put all the libraries for a target on into the given stream diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 427ae106c..4db36fc5b 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -58,7 +58,7 @@ void cmLocalNinjaGenerator::Generate() #endif // We do that only once for the top CMakeLists.txt file. - if(this->IsRootMakefile()) + if(this->Makefile->IsRootMakefile()) { this->WriteBuildFileTop(); @@ -298,7 +298,7 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os) << "# Write statements declared in CMakeLists.txt:" << std::endl << "# " << this->Makefile->GetDefinition("CMAKE_CURRENT_LIST_FILE") << std::endl; - if(this->IsRootMakefile()) + if(this->Makefile->IsRootMakefile()) os << "# Which is the root file." << std::endl; cmGlobalNinjaGenerator::WriteDivider(os); os << std::endl; diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index 4e4d146a9..b097c95ed 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -149,9 +149,6 @@ public: void AddImplicitDepends(cmTarget const& tgt, const std::string& lang, const char* obj, const char* src); - void AppendGlobalTargetDepends(std::vector& depends, - cmTarget& target); - // write the target rules for the local Makefile into the stream void WriteLocalAllRules(std::ostream& ruleFileStream); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 1d75f81a7..40c388552 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -105,7 +105,7 @@ public: ++it; if(it == this->VarStack.rend()) { - cmLocalGenerator* plg = mf->GetLocalGenerator()->GetParent(); + cmLocalGenerator* plg = mf->LocalGenerator->GetParent(); if(!plg) { return false; @@ -264,8 +264,8 @@ void cmMakefile::IssueMessage(cmake::MessageType t, if(!this->GetCMakeInstance()->GetIsInTryCompile()) { - lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath, - cmLocalGenerator::HOME); + cmOutputConverter converter(this->StateSnapshot); + lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); } lfc.Line = 0; this->GetCMakeInstance()->IssueMessage(t, text, lfc); @@ -1620,6 +1620,11 @@ void cmMakefile::PopMacroScope(bool reportError) this->PopFunctionBlockerBarrier(reportError); } +bool cmMakefile::IsRootMakefile() const +{ + return !this->StateSnapshot.GetBuildsystemDirectoryParent().IsValid(); +} + //---------------------------------------------------------------------------- class cmMakefileCurrent { @@ -1975,8 +1980,8 @@ void cmMakefile::LogUnused(const char* reason, lfc.FilePath = path; lfc.Line = 0; } - lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath, - cmLocalGenerator::HOME); + cmOutputConverter converter(this->StateSnapshot); + lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); if (this->CheckSystemVars || cmSystemTools::IsSubDirectory(path, @@ -2873,8 +2878,9 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( { std::ostringstream msg; cmListFileContext lfc; - lfc.FilePath = this->LocalGenerator - ->Convert(filename, cmLocalGenerator::HOME); + cmOutputConverter converter(this->StateSnapshot); + lfc.FilePath = + converter.Convert(filename, cmOutputConverter::HOME); lfc.Line = line; msg << "uninitialized variable \'" << lookup << "\'"; this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index b3efb887c..b3ab273b1 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -90,6 +90,9 @@ public: */ void AddFunctionBlocker(cmFunctionBlocker* fb); + /// @return whether we are processing the top CMakeLists.txt file. + bool IsRootMakefile() const; + /** * Remove the function blocker whose scope ends with the given command. * This returns ownership of the function blocker object. diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx index db73a3438..b0a30a1ca 100644 --- a/Source/cmOutputConverter.cxx +++ b/Source/cmOutputConverter.cxx @@ -27,7 +27,7 @@ cmOutputConverter::cmOutputConverter(cmState::Snapshot snapshot) std::string cmOutputConverter::ConvertToOutputForExistingCommon(const std::string& remote, std::string const& result, - OutputFormat format) + OutputFormat format) const { // If this is a windows shell, the result has a space, and the path // already exists, we can use a short-path to reference it without a @@ -50,7 +50,7 @@ cmOutputConverter::ConvertToOutputForExistingCommon(const std::string& remote, std::string cmOutputConverter::ConvertToOutputForExisting(const std::string& remote, RelativeRoot local, - OutputFormat format) + OutputFormat format) const { static_cast(local); @@ -65,7 +65,7 @@ cmOutputConverter::ConvertToOutputForExisting(const std::string& remote, std::string cmOutputConverter::ConvertToOutputForExisting(RelativeRoot remote, const std::string& local, - OutputFormat format) + OutputFormat format) const { // Perform standard conversion. std::string result = this->Convert(remote, local, format, true); @@ -76,7 +76,7 @@ cmOutputConverter::ConvertToOutputForExisting(RelativeRoot remote, } //---------------------------------------------------------------------------- -const char* cmOutputConverter::GetRelativeRootPath(RelativeRoot relroot) +const char* cmOutputConverter::GetRelativeRootPath(RelativeRoot relroot) const { switch (relroot) { @@ -91,7 +91,7 @@ const char* cmOutputConverter::GetRelativeRootPath(RelativeRoot relroot) std::string cmOutputConverter::Convert(const std::string& source, RelativeRoot relative, - OutputFormat output) + OutputFormat output) const { // Convert the path to a relative path. std::string result = source; @@ -125,7 +125,7 @@ std::string cmOutputConverter::Convert(const std::string& source, //---------------------------------------------------------------------------- std::string cmOutputConverter::ConvertToOutputFormat(const std::string& source, - OutputFormat output) + OutputFormat output) const { std::string result = source; // Convert it to an output path. @@ -163,7 +163,7 @@ std::string cmOutputConverter::ConvertToOutputFormat(const std::string& source, std::string cmOutputConverter::Convert(RelativeRoot remote, const std::string& local, OutputFormat output, - bool optional) + bool optional) const { const char* remotePath = this->GetRelativeRootPath(remote); @@ -192,7 +192,7 @@ static bool cmOutputConverterNotAbove(const char* a, const char* b) std::string cmOutputConverter::ConvertToRelativePath(const std::vector& local, const std::string& in_remote, - bool force) + bool force) const { // The path should never be quoted. assert(in_remote[0] != '\"'); @@ -318,7 +318,7 @@ static bool cmOutputConverterIsShellOperator(const std::string& str) std::string cmOutputConverter::EscapeForShell(const std::string& str, bool makeVars, bool forEcho, - bool useWatcomQuote) + bool useWatcomQuote) const { // Do not escape shell operators. if(cmOutputConverterIsShellOperator(str)) diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h index 1d3f8c75f..482a64b1c 100644 --- a/Source/cmOutputConverter.h +++ b/Source/cmOutputConverter.h @@ -39,35 +39,35 @@ public: enum RelativeRoot { NONE, FULL, HOME, START, HOME_OUTPUT, START_OUTPUT }; enum OutputFormat { UNCHANGED, MAKERULE, SHELL, WATCOMQUOTE, RESPONSE }; std::string ConvertToOutputFormat(const std::string& source, - OutputFormat output); + OutputFormat output) const; std::string Convert(const std::string& remote, RelativeRoot local, - OutputFormat output = UNCHANGED); + OutputFormat output = UNCHANGED) const; std::string Convert(RelativeRoot remote, const std::string& local, OutputFormat output = UNCHANGED, - bool optional = false); + bool optional = false) const; /** * Get path for the specified relative root. */ - const char* GetRelativeRootPath(RelativeRoot relroot); + const char* GetRelativeRootPath(RelativeRoot relroot) const; ///! for existing files convert to output path and short path if spaces std::string ConvertToOutputForExisting(const std::string& remote, RelativeRoot local = START_OUTPUT, - OutputFormat format = SHELL); + OutputFormat format = SHELL) const; /** For existing path identified by RelativeRoot convert to output path and short path if spaces. */ std::string ConvertToOutputForExisting(RelativeRoot remote, const std::string& local = "", - OutputFormat format = SHELL); + OutputFormat format = SHELL) const; void SetLinkScriptShell(bool linkScriptShell); std::string EscapeForShell(const std::string& str, bool makeVars = false, bool forEcho = false, - bool useWatcomQuote = false); + bool useWatcomQuote = false) const; static std::string EscapeForCMake(const std::string& str); @@ -88,14 +88,14 @@ public: */ std::string ConvertToRelativePath(const std::vector& local, const std::string& in_remote, - bool force = false); + bool force = false) const; private: cmState* GetState() const; std::string ConvertToOutputForExistingCommon(const std::string& remote, std::string const& result, - OutputFormat format); + OutputFormat format) const; private: cmState::Snapshot StateSnapshot; diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx index 90bc1115e..46d7e0113 100644 --- a/Source/cmProjectCommand.cxx +++ b/Source/cmProjectCommand.cxx @@ -53,7 +53,7 @@ bool cmProjectCommand // CMAKE_PROJECT_NAME will match PROJECT_NAME, and cmake --build // will work. if(!this->Makefile->GetDefinition("CMAKE_PROJECT_NAME") - || (this->Makefile->GetLocalGenerator()->IsRootMakefile())) + || (this->Makefile->IsRootMakefile())) { this->Makefile->AddDefinition("CMAKE_PROJECT_NAME", args[0].c_str()); this->Makefile->AddCacheDefinition diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index f472ed8ee..53fea8379 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -368,8 +368,7 @@ bool cmQtAutoGenerators::InitializeAutogenTarget(cmTarget* target) #if defined(_WIN32) && !defined(__CYGWIN__) bool usePRE_BUILD = false; - cmLocalGenerator* localGen = makefile->GetLocalGenerator(); - cmGlobalGenerator* gg = localGen->GetGlobalGenerator(); + cmGlobalGenerator* gg = makefile->GetGlobalGenerator(); if(gg->GetName().find("Visual Studio") != std::string::npos) { cmGlobalVisualStudioGenerator* vsgg = diff --git a/Source/cmState.cxx b/Source/cmState.cxx index a13c13f14..58500cc10 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -219,13 +219,13 @@ void cmState::RemoveCacheEntryProperty(std::string const& key, ->GetCacheIterator(key.c_str()).SetProperty(propertyName, (void*)0); } -void cmState::Reset() +cmState::Snapshot cmState::Reset() { this->GlobalProperties.clear(); this->PropertyDefinitions.clear(); this->BuildsystemDirectory.Truncate(); - this->SnapshotData.Truncate(); + PositionType pos = this->SnapshotData.Truncate(); this->DefineProperty ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, @@ -246,6 +246,8 @@ void cmState::Reset() this->DefineProperty ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET, "", "", true); + + return Snapshot(this, pos); } void cmState::DefineProperty(const std::string& name, @@ -741,14 +743,14 @@ void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir) } std::vector const& -cmState::Snapshot::GetCurrentSourceDirectoryComponents() +cmState::Snapshot::GetCurrentSourceDirectoryComponents() const { return this->Position->BuildSystemDirectory ->CurrentSourceDirectoryComponents; } std::vector const& -cmState::Snapshot::GetCurrentBinaryDirectoryComponents() +cmState::Snapshot::GetCurrentBinaryDirectoryComponents() const { return this->Position->BuildSystemDirectory ->CurrentBinaryDirectoryComponents; diff --git a/Source/cmState.h b/Source/cmState.h index 353a6c60a..9c7574f7b 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -43,8 +43,10 @@ public: const char* GetCurrentBinaryDirectory() const; void SetCurrentBinaryDirectory(std::string const& dir); - std::vector const& GetCurrentSourceDirectoryComponents(); - std::vector const& GetCurrentBinaryDirectoryComponents(); + std::vector const& + GetCurrentSourceDirectoryComponents() const; + std::vector const& + GetCurrentBinaryDirectoryComponents() const; const char* GetRelativePathTopSource() const; const char* GetRelativePathTopBinary() const; @@ -103,7 +105,7 @@ public: void RemoveCacheEntryProperty(std::string const& key, std::string const& propertyName); - void Reset(); + Snapshot Reset(); // Define a property void DefineProperty(const std::string& name, cmProperty::ScopeType scope, const char *ShortDescription, diff --git a/Source/cmake.cxx b/Source/cmake.cxx index eeb6575c0..e51b260cd 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -186,7 +186,7 @@ cmake::~cmake() void cmake::CleanupCommandsAndMacros() { - this->State->Reset(); + this->CurrentSnapshot = this->State->Reset(); this->State->RemoveUserDefinedCommands(); } @@ -370,6 +370,7 @@ void cmake::ReadListFile(const std::vector& args, // read in the list file to fill the cache if(path) { + this->CurrentSnapshot = this->State->Reset(); std::string homeDir = this->GetHomeDirectory(); std::string homeOutputDir = this->GetHomeOutputDirectory(); this->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory());