[CMake] How to write a correct wrapper of MESSAGE()?

Matthew Woehlke matthew.woehlke at kitware.com
Fri Oct 4 13:38:40 EDT 2013


On 2013-09-27 04:18, Clark WANG wrote:
> I'm trying to write some MESSAGE() wrappers like info(), warning(),
> fatal(), etc which may be a bit easier to use. But I failed to simulate the
> correct MESSAGE() behavior no matter I use MACRO or FUNCTION. For example:
> [snip]

FUNCTION vs MACRO shouldn't make a difference in argument parsing AFAIK. 
The difference is primarily that FUNCTION creates a scope, while MACRO 
operates in the scope from which it is called.

The behavior of MESSAGE seems to concatenate multiple arguments with no 
separators. So maybe you could do something like:

set(msg "")
foreach(part IN LISTS ARGN)
   set(msg "${msg}{$part}")
endforeach()
# ...do stuff with ${msg}

(I like ARGN since it is 'unnamed positional arguments'. Since you have 
no named arguments, ARGV == ARGN, but generally speaking I can't think 
of why you'd ever need to use ARGV.)

-- 
Matthew



More information about the CMake mailing list