From dc9245df6cbe4ed6211387f6090b531ce4414263 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Tue, 11 Mar 2008 10:29:56 -0400 Subject: [PATCH] ENH: add enum to IssueMessage --- Source/cmListFileCache.cxx | 4 ++-- Source/cmMakefile.cxx | 30 ++++++++++-------------------- Source/cmMakefile.h | 8 +++----- Source/cmPolicies.cxx | 6 +++--- Source/cmake.h | 7 +++++++ 5 files changed, 25 insertions(+), 30 deletions(-) diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 55604a630..594f42b27 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -146,7 +146,7 @@ bool cmListFile::ParseFile(const char* filename, switch (mf->GetPolicyStatus(cmPolicies::CMP_0000)) { case cmPolicies::WARN: - mf->IssueWarning( + mf->IssueMessage(cmake::AUTHOR_WARNING, mf->GetPolicies()->GetPolicyWarning(cmPolicies::CMP_0000) ); @@ -155,7 +155,7 @@ bool cmListFile::ParseFile(const char* filename, case cmPolicies::OLD: break; default: - mf->IssueError( + mf->IssueMessage(cmake::FATAL_ERROR, mf->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP_0000) ); return false; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 238e92aac..f245b718e 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -282,26 +282,16 @@ bool cmMakefile::CommandExists(const char* name) const return this->GetCMakeInstance()->CommandExists(name); } -//---------------------------------------------------------------------------- -void cmMakefile::IssueError(std::string const& msg) const -{ - this->IssueMessage(msg, true); -} //---------------------------------------------------------------------------- -void cmMakefile::IssueWarning(std::string const& msg) const -{ - this->IssueMessage(msg, false); -} - -//---------------------------------------------------------------------------- -void cmMakefile::IssueMessage(std::string const& text, bool isError) const +void cmMakefile::IssueMessage(cmake::MessageType t, std::string const& text) const { cmOStringStream msg; - + bool isError = false; // Construct the message header. - if(isError) + if(t == cmake::FATAL_ERROR) { + isError = true; msg << "CMake Error:"; } else @@ -439,7 +429,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, if(!status.GetNestedError()) { // The command invocation requested that we report an error. - this->IssueError(pcmd->GetError()); + this->IssueMessage(cmake::FATAL_ERROR, pcmd->GetError()); } result = false; if ( this->GetCMakeInstance()->GetScriptMode() ) @@ -459,7 +449,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, std::string error = "Command "; error += pcmd->GetName(); error += "() is not scriptable"; - this->IssueError(error); + this->IssueMessage(cmake::FATAL_ERROR, error); result = false; cmSystemTools::SetFatalErrorOccured(); } @@ -471,7 +461,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, std::string error = "Unknown CMake command \""; error += lff.Name; error += "\"."; - this->IssueError(error); + this->IssueMessage(cmake::FATAL_ERROR, error); result = false; cmSystemTools::SetFatalErrorOccured(); } @@ -619,7 +609,7 @@ bool cmMakefile::ReadListFile(const char* filename_in, { if(endScopeNicely) { - this->IssueError("cmake_policy PUSH without matching POP"); + this->IssueMessage(cmake::FATAL_ERROR, "cmake_policy PUSH without matching POP"); } this->PopPolicy(false); } @@ -3260,13 +3250,13 @@ bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg, switch (this->GetPolicyStatus(cmPolicies::CMP_0002)) { case cmPolicies::WARN: - this->IssueWarning(this->GetPolicies()-> + this->IssueMessage(cmake::AUTHOR_WARNING, this->GetPolicies()-> GetPolicyWarning(cmPolicies::CMP_0002)); case cmPolicies::OLD: return true; case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: - this->IssueError( + this->IssueMessage(cmake::FATAL_ERROR, this->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP_0002) ); return true; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index b679ff475..33309e1ff 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -25,6 +25,7 @@ #include "cmPropertyMap.h" #include "cmSystemTools.h" #include "cmTarget.h" +#include "cmake.h" #if defined(CMAKE_BUILD_WITH_CMAKE) #include "cmSourceGroup.h" @@ -784,9 +785,8 @@ public: void PopScope(); void RaiseScope(const char *var, const char *value); - /** Issue messages with the given text plus context information. */ - void IssueWarning(std::string const& msg) const; - void IssueError(std::string const& msg) const; + void IssueMessage(cmake::MessageType t, + std::string const& text) const; protected: // add link libraries and directories to the target @@ -891,8 +891,6 @@ private: CallStackType CallStack; friend class cmMakefileCall; - void IssueMessage(std::string const& text, bool isError) const; - cmTarget* FindBasicTarget(const char* name); std::vector ImportedTargetsOwned; std::map ImportedTargets; diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 647d6d4ef..cdb39e08d 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -202,8 +202,8 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf, // it is an error if the policy version is less than 2.4 if (majorVer < 2 || majorVer == 2 && minorVer < 4) - { - mf->IssueError( + { + mf->IssueMessage(cmake::FATAL_ERROR, "An attempt was made to set the policy version of CMake to something " "earlier than \"2.4\". " "In CMake 2.4 and below backwards compatibility was handled with the " @@ -213,7 +213,7 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf, "CMAKE_BACKWARDS_COMPATIBILITY variable. " "One way to so this is to set the policy version to 2.4 exactly." ); - } + } // now loop over all the policies and set them as appropriate std::map::iterator i diff --git a/Source/cmake.h b/Source/cmake.h index c7ed21ca8..b8ca27f86 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -58,6 +58,13 @@ class cmPolicies; class cmake { public: + enum MessageType + { AUTHOR_WARNING, + FATAL_ERROR, + MESSAGE, + WARNING, + LOG + }; typedef std::map RegisteredCommandsMap; ///! construct an instance of cmake