diff options
author | Brad King <brad.king@kitware.com> | 2009-10-27 13:01:33 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-10-27 13:01:33 (GMT) |
commit | 9f43fa602d53d131adffd1a3bb8188b549a96a01 (patch) | |
tree | ec0f927882fd92f02908a70fa726a4fee4ff67c8 /Source/cmIfCommand.cxx | |
parent | 92caf3473337f45e4f54fdf727db3c3359c90b42 (diff) | |
download | CMake-9f43fa602d53d131adffd1a3bb8188b549a96a01.zip CMake-9f43fa602d53d131adffd1a3bb8188b549a96a01.tar.gz CMake-9f43fa602d53d131adffd1a3bb8188b549a96a01.tar.bz2 |
Report expanded arguments in if() command errors
The if() command reports its arguments at the beginning of some error
messages. Originally it reported the un-expanded form of the arguments
because in ancient CMake versions no context information was available.
Now it is more useful to see the real arguments, which may be mentioned
in the main error message. Since full context information is now
available, users can refer back to the source if they need to see the
unexpanded form of the arguments.
For example, the code
set(regex "++")
if("x" MATCHES "${regex}")
endif()
now produces the message
if given arguments:
"x" "MATCHES" "++"
Regular expression "++" cannot compile
instead of
if given arguments
"x" MATCHES "${regex}"
Regular expression "++" cannot compile
Diffstat (limited to 'Source/cmIfCommand.cxx')
-rw-r--r-- | Source/cmIfCommand.cxx | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index 8cba111..5c8f07a 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -16,6 +16,22 @@ #include <list> #include <cmsys/RegularExpression.hxx> + +static std::string cmIfCommandError( + cmMakefile* mf, std::vector<std::string> const& args) +{ + cmLocalGenerator* lg = mf->GetLocalGenerator(); + std::string err = "given arguments:\n "; + for(std::vector<std::string>::const_iterator i = args.begin(); + i != args.end(); ++i) + { + err += " "; + err += lg->EscapeForCMake(i->c_str()); + } + err += "\n"; + return err; +} + //========================================================================= bool cmIfFunctionBlocker:: IsFunctionBlocked(const cmListFileFunction& lff, @@ -85,16 +101,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, if (errorString.size()) { - std::string err = "given arguments\n "; - unsigned int i; - for(i =0; i < this->Functions[c].Arguments.size(); ++i) - { - err += (this->Functions[c].Arguments[i].Quoted?"\"":""); - err += this->Functions[c].Arguments[i].Value; - err += (this->Functions[c].Arguments[i].Quoted?"\"":""); - err += " "; - } - err += "\n"; + std::string err = cmIfCommandError(&mf, expandedArguments); err += errorString; mf.IssueMessage(messType, err); if (messType == cmake::FATAL_ERROR) @@ -175,16 +182,7 @@ bool cmIfCommand if (errorString.size()) { - std::string err = "given arguments\n "; - unsigned int i; - for(i =0; i < args.size(); ++i) - { - err += (args[i].Quoted?"\"":""); - err += args[i].Value; - err += (args[i].Quoted?"\"":""); - err += " "; - } - err += "\n"; + std::string err = cmIfCommandError(this->Makefile, expandedArguments); err += errorString; if (status == cmake::FATAL_ERROR) { |