How to avoid escaping $?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

How to avoid escaping $?

Thomas Törnblom
I have a need to add an argument like "-DImage$$= " to a compile
command, i.e. define a macro Image$$ to just expand to a single space

I'm using Windows 10  and I configure my project to use Unix Makefiles
for building. cmake appears to use "sh" (bash) to execute the build
commands, and I have this in one of my cmake files:
     function(config_setting_shared_compiler_flags tgt)
         embedded_set_target_compile_flags(TARGET ${tgt} LANGUAGE C
FLAGS ${COMMON_COMPILE_FLAGS} "-DImage$$= " "-DLoad$$LR$$= "
"-D$$ZI$$Base=$$Base" "-D$$ZI$$Limit=$$Limit" "-D$$RO$$Base=$$Base"
"-D$$RO$$Limit=$$Limit" "-D_DATA$$RW$$Base=_DATA$$Base"
"-D_DATA$$RW$$Limit=_DATA$$Limit" "-D_DATA$$ZI$$Base=_DATA$$Base"
"-D_DATA$$ZI$$Limit=_DATA$$Limit" "-D_STACK$$ZI$$Base=_STACK$$Base"
"-D_STACK$$ZI$$Limit=_STACK$$Limit" )

When doing a verbose build I see that the relevant part of the command
lines expands to:
"-DImage\$\$= "
I.e. cmake has escaped the dollar signs with a \, which is what a normal
unix shell needs, and this works fine on my system.

We've tried to build this project on a system with Windows 7, which has
no working bash, and it uses cmd.exe to run the build lines. cmd.exe
does not handle the \ escape the way bash does so the the build fails.

cmd.exe accepts the following syntax:
"-DImage$$= "

So no need to escape the dollar signs.

Is there a way to stop cmake from escaping dollar signs in this case?



Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: