<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Oct 9, 2013 at 7:44 PM, Johannes Zarl <span dir="ltr"><<a href="mailto:johannes.zarl@jku.at" target="_blank">johannes.zarl@jku.at</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I guess you search for something like this:<br>
<br>
function(info)<br>
set(msg)<br>
foreach(i RANGE ${ARGC})<br>
set(msg "${msg}${ARGV${i}}")<br>
endforeach()<br>
message(STATUS "[info] ${msg}")<br>
endfunction()<br>
<br>
message("Foo:bar;baz space" "FOO")<br>
info("Foo:bar;baz space" "FOO")<br>
message(two words)<br>
info(two words)<br>
<br>
...which yields the following output:<br>
<br>
Foo:bar;baz spaceFOO<br>
-- [info] Foo:bar;baz spaceFOO<br>
twowords<br>
-- [info] twowords<br>
<br>
The "IN LISTS" signature of foreach seems to do additional list splitting,<br>
leading to ("foo;bar" "baz") appearing as 3 elements. Accessing the ARGV array<br>
by the positional indices (e.g. ${ARGV0}) prevents the splitting.<br></blockquote><div><br></div><div>This works. Thank you so much.<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
HTH,<br>
Johannes<br>
<div><div><br>
On Wednesday, 9. October 2013, 05:33:26, Clark WANG wrote:<br>
> On Sat, Oct 5, 2013 at 1:38 AM, Matthew Woehlke<br>
> <<a href="mailto:matthew.woehlke@kitware.com" target="_blank">matthew.woehlke@kitware.com</a><br>
><br>
> > wrote:<br>
> ><br>
> > On 2013-09-27 04:18, Clark WANG wrote:<br>
> >> I'm trying to write some MESSAGE() wrappers like info(), warning(),<br>
> >> fatal(), etc which may be a bit easier to use. But I failed to simulate<br>
> >> the<br>
> >> correct MESSAGE() behavior no matter I use MACRO or FUNCTION. For<br>
> >> example: [snip]<br>
> ><br>
> > FUNCTION vs MACRO shouldn't make a difference in argument parsing AFAIK.<br>
> > The difference is primarily that FUNCTION creates a scope, while MACRO<br>
> > operates in the scope from which it is called.<br>
> ><br>
> > The behavior of MESSAGE seems to concatenate multiple arguments with no<br>
> > separators. So maybe you could do something like:<br>
> ><br>
> > set(msg "")<br>
> > foreach(part IN LISTS ARGN)<br>
> ><br>
> > set(msg "${msg}{$part}")<br>
> ><br>
> > endforeach()<br>
> > # ...do stuff with ${msg}<br>
><br>
> This does not work either. For example:<br>
><br>
> $ cat CMakeLists.txt<br>
> cmake_minimum_required(VERSION 2.8)<br>
><br>
> FUNCTION(info_f)<br>
> set(msg "")<br>
> foreach(part IN LISTS ARGN)<br>
> set(msg "${msg}${part}")<br>
> endforeach()<br>
> message("[info_f] ${msg}")<br>
> ENDFUNCTION()<br>
><br>
> MACRO(info_m)<br>
> set(msg "")<br>
> foreach(part IN LISTS ARGN)<br>
> set(msg "${msg}${part}")<br>
> endforeach()<br>
> message("[info_m] ${msg}")<br>
> ENDMACRO()<br>
><br>
> message("foo;bar")<br>
> info_f("foo;bar")<br>
> info_m("foo;bar")<br>
> $ cmake .<br>
> foo;bar<br>
> [info_f] foobar<br>
> [info_m]<br>
> $<br>
><br>
> > (I like ARGN since it is 'unnamed positional arguments'. Since you have<br>
> > no named arguments, ARGV == ARGN, but generally speaking I can't think<br>
> > of why you'd ever need to use ARGV.)<br>
><br>
> Good point.<br>
><br>
> > --<br>
> > Matthew<br>
> ><br>
> > --<br>
> ><br>
> > Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
> ><br>
> > Please keep messages on-topic and check the CMake FAQ at:<br>
</div></div>> > <a href="http://www.cmake.org/Wiki/**CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/**CMake_FAQ</a><<a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<div>> > ><br>
> ><br>
> > Kitware offers various services to support the CMake community. For more<br>
> > information on each offering, please visit:<br>
> ><br>
> > CMake Support:<br>
</div>> > <a href="http://cmake.org/cmake/help/**support.html" target="_blank">http://cmake.org/cmake/help/**support.html</a><<a href="http://cmake.org/cmake/help/s" target="_blank">http://cmake.org/cmake/help/s</a><br>
> > upport.html> CMake Consulting:<br>
> > <a href="http://cmake.org/cmake/help/**consulting.html" target="_blank">http://cmake.org/cmake/help/**consulting.html</a><<a href="http://cmake.org/cmake/hel" target="_blank">http://cmake.org/cmake/hel</a><br>
> > p/consulting.html> CMake Training Courses:<br>
> > <a href="http://cmake.org/cmake/help/**training.html" target="_blank">http://cmake.org/cmake/help/**training.html</a><<a href="http://cmake.org/cmake/help/" target="_blank">http://cmake.org/cmake/help/</a><br>
> > training.html><br>
> ><br>
> > Visit other Kitware open-source projects at <a href="http://www.kitware.com/**" target="_blank">http://www.kitware.com/**</a><br>
> > opensource/opensource.html<<a href="http://www.kitware.com/opensource/opensource.h" target="_blank">http://www.kitware.com/opensource/opensource.h</a><br>
> > tml><br>
<div>> ><br>
> > Follow this link to subscribe/unsubscribe:<br>
</div>> > <a href="http://www.cmake.org/mailman/**listinfo/cmake" target="_blank">http://www.cmake.org/mailman/**listinfo/cmake</a><<a href="http://www.cmake.org/mailma" target="_blank">http://www.cmake.org/mailma</a><br>
> > n/listinfo/cmake><br>
<div><div><br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</div></div></blockquote></div><br></div></div>