summaryrefslogtreecommitdiff
path: root/Source/cmForEachCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-03-17 15:10:15 -0400
committerBrad King <brad.king@kitware.com>2009-03-17 15:10:15 -0400
commitecb0f3af55f8fde908edcec7f5ccf2cef4002050 (patch)
tree97e95149d7112b5832cc1094f666383ed1e6a5bf /Source/cmForEachCommand.cxx
parentee00616289403ca0c8d7273eeea3a30eeb11a348 (diff)
downloadcmake-ecb0f3af55f8fde908edcec7f5ccf2cef4002050.tar.gz
ENH: New foreach(<var> IN ...) mode
This creates a new mode of the foreach command which allows precise iteration even over empty elements. This mode may be safely extended with more keyword arguments in the future. The cost now is possibly breaking scripts that iterate over a list of items beginning with 'IN', but there is no other way to extend the syntax in a readable way.
Diffstat (limited to 'Source/cmForEachCommand.cxx')
-rw-r--r--Source/cmForEachCommand.cxx48
1 files changed, 48 insertions, 0 deletions
diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx
index 7a826c6310..7a035237fb 100644
--- a/Source/cmForEachCommand.cxx
+++ b/Source/cmForEachCommand.cxx
@@ -16,6 +16,8 @@
=========================================================================*/
#include "cmForEachCommand.h"
+#include <cmsys/auto_ptr.hxx>
+
bool cmForEachFunctionBlocker::
IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
cmExecutionStatus &inStatus)
@@ -116,6 +118,10 @@ bool cmForEachCommand
this->SetError("called with incorrect number of arguments");
return false;
}
+ if(args.size() > 1 && args[1] == "IN")
+ {
+ return this->HandleInMode(args);
+ }
// create a function blocker
cmForEachFunctionBlocker *f = new cmForEachFunctionBlocker();
@@ -197,3 +203,45 @@ bool cmForEachCommand
return true;
}
+//----------------------------------------------------------------------------
+bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args)
+{
+ cmsys::auto_ptr<cmForEachFunctionBlocker> f(new cmForEachFunctionBlocker());
+ f->Args.push_back(args[0]);
+
+ enum Doing { DoingNone, DoingLists, DoingItems };
+ Doing doing = DoingNone;
+ for(unsigned int i=2; i < args.size(); ++i)
+ {
+ if(doing == DoingItems)
+ {
+ f->Args.push_back(args[i]);
+ }
+ else if(args[i] == "LISTS")
+ {
+ doing = DoingLists;
+ }
+ else if(args[i] == "ITEMS")
+ {
+ doing = DoingItems;
+ }
+ else if(doing == DoingLists)
+ {
+ const char* value = this->Makefile->GetDefinition(args[i].c_str());
+ if(value && *value)
+ {
+ cmSystemTools::ExpandListArgument(value, f->Args, true);
+ }
+ }
+ else
+ {
+ cmOStringStream e;
+ e << "Unknown argument:\n" << " " << args[i] << "\n";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return true;
+ }
+ }
+
+ this->Makefile->AddFunctionBlocker(f.release()); // TODO: pass auto_ptr
+ return true;
+}