[CMake] How to use file(WRITE... to write the literal string $'\r' to a file

Matthew Woehlke matthew.woehlke at kitware.com
Wed Oct 31 20:17:08 EDT 2012


On 2012-10-31 19:34, Alan W. Irwin wrote:
> After a lot of thrashing around I finally discovered that
>
> file(WRITE <filename> "\$""'""\\r""'")
>
> worked to write the literal string
>
> $'\r'
>
> to a file, i.e, so that the od -a result was
>
> $   '   \   r   '
>
> Is there an easier way to write this literal string to a file that I
> missed?

file(WRITE <filename> "\$'\\r'")?

You're not going to get much simpler, as both '\' and '$' have special 
meaning and so need to be escaped.

I'm not sure why you found it necessary to add all the extra quotes?

(Tested on cmake 2.8.9 on Linux.)

-- 
Matthew



More information about the CMake mailing list