Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping $ dollar sign in CMake

I'm trying to run a post build command in CMake 3.1.1 via:

ADD_CUSTOM_COMMAND(
   TARGET mytarget
    POST_BUILD
    COMMAND for i in `ls *` \; do echo \$i \; done \; 

However, the $i variable is evaluated to nothing although I escape the dollar sign. According to logs the command is evaluated to:

for i in `ls *` ; do echo  ; done ; 

I tried without escaping the dollar sign, but it led to the same problem. Double slash didn't work either. Now I'm puzzled...

Can you suggest a way to run a command that uses dollar signs?

P.S. This was just an example. My actual command is slightly more complicated and I don't think I can work it out without using dollar signs.

like image 299
Vyacheslav Avatar asked Apr 11 '15 23:04

Vyacheslav


1 Answers

You should use 'make' style escape with double dollar sign:

ADD_CUSTOM_COMMAND(
   TARGET mytarget
    POST_BUILD
    COMMAND for i in `ls *` \; do echo $$i \; done \;
)

Related links:

https://www.gnu.org/software/make/manual/html_node/Variables-in-Recipes.html

https://www.mail-archive.com/[email protected]/msg11302.html

like image 87
hank Avatar answered Sep 18 '22 13:09

hank