I&#39;ve written macros like this that work:<br><br>MACRO(abc var)<br>&nbsp; # Reset to empty:<br>&nbsp; SET(${var} &quot;&quot;)<br><br>&nbsp; # Append each optional arg to ${var} if it matches &quot;\\.h$&quot;<br>
&nbsp; FOREACH(item ${ARGN})<br>&nbsp;&nbsp;&nbsp; IF(&quot;${item}&quot; MATCHES &quot;\\.h$&quot;)<br>&nbsp;&nbsp; &nbsp;&nbsp; SET(${var} ${${var}} &quot;${item}&quot;)<br>&nbsp;&nbsp;&nbsp; ENDIF(&quot;${item}&quot; MATCHES &quot;\\.h$&quot;)<br>
&nbsp; ENDFOREACH(item)<br>
ENDMACRO(abc)<br>
<br># Call it like this:<br>abc(header_files a.cpp a.h b.cpp x.h)<br>MESSAGE(&quot;header_files=&#39;${header_files}&#39;&quot;)<br><br># Or like this:<br>
SET(all_files2 &quot;a.cpp;a.h;b.cpp;x.h&quot;)<br>abc(header_files2 ${all_files2})<br>

MESSAGE(&quot;all_files2=&#39;${all_files2}&#39;&quot;)<br>




MESSAGE(&quot;header_files2=&#39;${header_files2}&#39;&quot;)<br>
<br># Or like this:<br>

SET(all_files3 a.cpp a.h b.cpp x.h)<br>
abc(header_files3 ${all_files3})<br>

MESSAGE(&quot;all_files3=&#39;${all_files3}&#39;&quot;)<br>




MESSAGE(&quot;header_files3=&#39;${header_files3}&#39;&quot;)<br>


<br># Notes:<br>#<br># all_files2 and all_files3 are equivalent<br>#<br># If you call the macro abc with ${all_files2} it works like you expect, if you call it with &quot;${all_files2}&quot; (including<br># double quotes), then it appears as one optional argument inside the macro and you will get different results...
<br><br><br>HTH and good luck,<br>David<br><br><br><div><span class="gmail_quote">On 7/28/07, <b class="gmail_sendername">Christian Convey</b> &lt;<a href="mailto:christian.convey@gmail.com">christian.convey@gmail.com</a>
&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On 7/28/07, David Cole &lt;<a href="mailto:david.cole@kitware.com">david.cole@kitware.com
</a>&gt; wrote:<br>&gt; Try this:<br>&gt; MACRO(BAR)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;SET(bar_ARGV0 &quot;${ARGV0}&quot;)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;MESSAGE(&quot;bar_ARGV0 = ${bar_ARGV0}&quot;)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;SET(ARGV0_NAME bar_ARGV0)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;MESSAGE(&quot;bar_ARGV0 = ${${bar_ARGV0_NAME}}&quot;)
<br>&gt; ENDMACRO(BAR)<br>&gt;<br>&gt; I&#39;m not *the* expert to explain this behavior, but I can tell you this:<br>&gt; When a macro is called, it is evaluated in its entirety in terms of variable<br>&gt; substitutions. In other words, the text of the macro is scanned and variable
<br>&gt; substitutions for ${ARG*} and any formally named macro parameters are done<br>&gt; prior to executing the first line of the macro. The only &quot;variables&quot; that<br>&gt; exist as you execute are those that existed prior to calling the macro plus
<br>&gt; those that you explicitly set within the macro. The formal parameters and<br>&gt; the ARG* values are not variables. If they were, you could not achieve<br>&gt; macros calling macros without having local scope to macro variables.
<br>&gt;<br>&gt; So, in your example, doing a SET as the first line with &quot;${ARGV0}&quot; as the<br>&gt; value is substituted prior to running and it works as you expect. In your<br>&gt; original example, ${ARGV0} only appears inside a MESSAGE command, and there
<br>&gt; is no variable named that, so you cannot access it via double indirection<br>&gt; with ARGV0 as a variable name,,,<br>&gt;<br>&gt; This has the one nice effect that the macro parameters are hidden and so do<br>&gt; not pollute the CMake variable space, but it does take some getting used
<br>&gt; to... (as you were suggesting in your other thread -- it would be nice to<br>&gt; have a mechanism to achieve variables local in scope to a macro) -- Perhaps<br>&gt; you could see if it&#39;s already a feature request in CMake&#39;s bug tracker? If
<br>&gt; not, feel free to add a feature request for macro local variables.<br>&gt;<br>&gt;<br>&gt; HTH,<br>&gt; David<br>&gt;<br><br>Thanks David, that&#39;s a big help.<br><br>Given what you said, do you know how I can achieve my broader goal?
<br><br>I have a macro like this:<br><br>MACRO( EXTRACT_HEADER_FILENAMES OUTPUT_VARNAME)<br><br>The idea is that you invoke it like this:<br>&nbsp;&nbsp;&nbsp;&nbsp;EXTRACT_HEADER_FILENAMES(Foo a.cpp;a.h;b.cpp;x.h)<br>So that afteward ${Foo} = &quot;
a.h;x.h&quot;<br><br>I *wanted* to use a FOREACH loop to iterate through ARGV2, ARGV3, ...,<br>to test each filename to see if it ends in &quot;.h&quot;.&nbsp;&nbsp;I would append each<br>filename ending in &quot;.h&quot; to the ${OUTPUT_VARNAME} variable.
<br><br>Is there some way&nbsp;&nbsp;can iterate over that subset of ARGV like I want to?<br><br>Or is there some better way to extract the header filenames from a<br>variable that contains a list of filenames?&nbsp;&nbsp;(I had no luck with
<br>STRING(REGEX MATCH ALL ...) )<br><br>Thanks,<br>Christian<br>_______________________________________________<br>CMake mailing list<br><a href="mailto:CMake@cmake.org">CMake@cmake.org</a><br><a href="http://www.cmake.org/mailman/listinfo/cmake">
http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br>