[CMake] How to avoid escaping $?
Thomas Törnblom
thomas.tornblom at iar.com
Mon Sep 2 05:05:41 EDT 2019
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
character.
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" )
endfunction()
---
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?
/Thomas
More information about the CMake
mailing list