summaryrefslogtreecommitdiffstats
path: root/Source/cmMacroCommand.cxx
diff options
context:
space:
mode:
authorKen Martin <ken.martin@kitware.com>2004-04-26 15:11:57 (GMT)
committerKen Martin <ken.martin@kitware.com>2004-04-26 15:11:57 (GMT)
commit2d53fcf03522bfc13f0a3817c260576bbe496c7d (patch)
tree2b3113da979629bd37cd5396e9674278ff798ac7 /Source/cmMacroCommand.cxx
parent7c0844d2f4f98d40bc4bb7be89cc75740506db3c (diff)
downloadCMake-2d53fcf03522bfc13f0a3817c260576bbe496c7d.zip
CMake-2d53fcf03522bfc13f0a3817c260576bbe496c7d.tar.gz
CMake-2d53fcf03522bfc13f0a3817c260576bbe496c7d.tar.bz2
macros now support varargs
Diffstat (limited to 'Source/cmMacroCommand.cxx')
-rw-r--r--Source/cmMacroCommand.cxx33
1 files changed, 31 insertions, 2 deletions
diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx
index 391434e..a393eff 100644
--- a/Source/cmMacroCommand.cxx
+++ b/Source/cmMacroCommand.cxx
@@ -58,8 +58,10 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
// Expand the argument list to the macro.
std::vector<std::string> expandedArguments;
mf.ExpandArguments(lff.m_Arguments, expandedArguments);
- // make sure the number of arguments matches
- if (expandedArguments.size() != m_Args.size() - 1)
+
+ // make sure the number of arguments passed is at least the number
+ // required by the signature
+ if (expandedArguments.size() < m_Args.size() - 1)
{
cmOStringStream error;
error << "Error in cmake code at\n"
@@ -70,6 +72,10 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
return true;
}
+ // now set the new argcDef
+ char argcDef[64];
+ sprintf(argcDef,"%i",expandedArguments.size());
+
// Invoke all the functions that were collected in the block.
cmListFileFunction newLFF;
for(unsigned int c = 0; c < m_Functions.size(); ++c)
@@ -85,6 +91,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
k != m_Functions[c].m_Arguments.end(); ++k)
{
tmps = k->Value;
+ // replace formal arguments
for (unsigned int j = 1; j < m_Args.size(); ++j)
{
variable = "${";
@@ -93,6 +100,28 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
cmSystemTools::ReplaceString(tmps, variable.c_str(),
expandedArguments[j-1].c_str());
}
+ // replace argc, argv arguments
+ for (unsigned int j = 1; j < m_Args.size(); ++j)
+ {
+ variable = "${ARGC}";
+ cmSystemTools::ReplaceString(tmps, variable.c_str(),argcDef);
+ }
+ for (unsigned int j = 1; j < m_Args.size(); ++j)
+ {
+ // since this could be slow, first check if there is an ARGV
+ // only then do the inner loop. PS std::string sucks
+ char argvName[60];
+ if (tmps.find("${ARGV") != std::string::npos)
+ {
+ for (unsigned int t = 0; t < expandedArguments.size(); ++t)
+ {
+ sprintf(argvName,"${ARGV%i}",t);
+ cmSystemTools::ReplaceString(tmps, argvName,
+ expandedArguments[t].c_str());
+ }
+ }
+ }
+
arg.Value = tmps;
arg.Quoted = k->Quoted;
newLFF.m_Arguments.push_back(arg);