Why do CMake prefixes have backslashes when executing a command?

I have a user command in CMakeLists.txt:

set(testfiles "test1 test2") add_custom_target(testtouch COMMAND touch ${testfiles}) 

When I run "make testtouch VERBOSE = 1", I see that it does:

 touch test1\ test2 

This is just an example, but I have this problem in a real project, and "\" violate the command. Note that I get the variable (here testfiles) from the Find script and cannot just get rid of the double quotes.

Why does CMake do this?

How to avoid this?

+6
source share
1 answer

Because sometimes it’s important to distinguish between the type of the cmake list variable and the cmake string literal.

Try changing the variable setting to the following to avoid the problem:

 set(testfiles "test1" "test2") 
+5
source

Source: https://habr.com/ru/post/906386/


All Articles