[CMake] how to escape the $ dollar sign?

Brandon Van Every bvanevery at gmail.com
Tue Jan 15 14:21:39 EST 2008


On Jan 15, 2008 7:59 AM, Christopher Lang <christopher.lang at acurana.de> wrote:
>
> Hi,
>
> I am trying desperately to get the dollar sign ($) escaped properly in the
> following:
>
> ADD_CUSTOM_TARGET (read_potfiles_in ALL
>         COMMAND grep -Ev '^\#|^\\[|^$' POTFILES.in > POTFILES.in.cmake
>         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
> )
>
> I searched everything but did not find a solution to get that dollar sign
> escaped.
>
> The result always looks like this:
>
> ...
> cd /home/chris/workspace/l2nl/po && grep -Ev '^#|^\[|^ POTFILES.in >
> POTFILES.in.cmake
>
> Escaping with signle or double \\ does not work.

Welcome to escape hell.  :-)  I can't comment on the special kind of
hell that is the COMMAND statement, whether VERBATIM or not.   I
haven't been doing many of those lately.  I can tell you all about $
escapes within regular expression strings though.

In a regex, outside of [] you need \\$
In a regex, inside of [] you do not need anything.  [$] is fine.
In a non-regex string, in front of a curly bracket you need \${
set(blah "whatever but \${do_not_evaluate}")
In a regex string, in front of a curly bracket you need \\\${
string(REGEX REPLACE
  ".*whatever but \\\${do not evaluate}"

I am still too lazy to write this up on
http://www.cmake.org/Wiki/CMake:VariablesListsStrings
I think because I perceive this wiki page as a bit buried in the shuffle.


Cheers,
Brandon Van Every


More information about the CMake mailing list