[CMake] multi-line strings... is this expected?

Matthew Woehlke mw_triad at users.sourceforge.net
Tue Apr 8 09:58:11 EDT 2014


On 2014-03-27 13:54, Matthew Woehlke wrote:
> I have¹ a CTest like:
>
> execute_process(...)
> set(expected "
> ...text...
> ...text...
> ")
> string(REGEX MATCH ${expected} match ${out})
>
> This works great... *IF* the script file has UNIX line endings. I'm
> wondering if that is expected? It seems that CTest must be processing
> the script in binary mode in order for the string to contain '\r'
> characters...

For the record: no. It turns out the line endings is actually a) a red 
herring (although the problem was a platform difference in a way), and 
b) not actually an issue (on further investigation, both CMake 2.8.x and 
3.0 seem to be behaving as expected in this respect).

Can anyone spot the problem above? :-)


It turns out that what is *actually* happening is that this:

   string(REGEX MATCH ${expected} match ${out})

...strips any ';'s from ${out}. And incidentally, the work-around I was 
using ('string(REPLACE "\r" "" expected ${expected})') does likewise, so 
that the combination results in neither string containing ';'s, which 
then can match. I was only seeing issues on Windows because the relevant 
';'s are path separators, which are of course ':'s on other platforms 
and so are not affected.

Quoting the argument to REGEX MATCH is the actual correct fix :-).

-- 
Matthew



More information about the CMake mailing list