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

David Cole david.cole at kitware.com
Wed Oct 31 20:24:10 EDT 2012


The only character you need to escape in the whole sequence is the
backslash. You only have to escape a $ if it precedes a { to disambiguate
from a variable dereference.

This works for me:

$ cat w.cmake
file(WRITE "w.txt" "$'\\r'")

$ cmake -P w.cmake

$ cat w.txt
$'\r'


HTH,
David



On Wed, Oct 31, 2012 at 7:34 PM, Alan W. Irwin <irwin at beluga.phys.uvic.ca>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?
>
> Alan
> __________________________
> Alan W. Irwin
>
> Astronomical research affiliation with Department of Physics and Astronomy,
> University of Victoria (astrowww.phys.uvic.ca).
>
> Programming affiliations with the FreeEOS equation-of-state
> implementation for stellar interiors (freeeos.sf.net); the Time
> Ephemerides project (timeephem.sf.net); PLplot scientific plotting
> software package (plplot.sf.net); the libLASi project
> (unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
> and the Linux Brochure Project (lbproject.sf.net).
> __________________________
>
> Linux-powered Science
> __________________________
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/**
> opensource/opensource.html<http://www.kitware.com/opensource/opensource.html>
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/**CMake_FAQ<http://www.cmake.org/Wiki/CMake_FAQ>
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/**listinfo/cmake<http://www.cmake.org/mailman/listinfo/cmake>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20121031/205e9158/attachment-0001.htm>


More information about the CMake mailing list