I have a custom command in a CMakeLists.txt :
set(testfiles "test1 test2")
add_custom_target(testtouch COMMAND touch ${testfiles})
When I run "make testtouch VERBOSE=1" I see that it executes :
touch test1\ test2
This is just an example, but I have this problem in a real project and the "\ " are breaking the command. Note that I get the variable (here testfiles) from a Find script and can't just get rid of the double quotes.
Why does CMake do that ?
How to avoid it ?
CMake will use whatever path the running CMake executable is in. Furthermore, it may get confused if you switch paths between runs without clearing the cache. So what you have to do is simply instead of running cmake <path_to_src> from the command line, run ~/usr/cmake-path/bin/cmake <path_to_src> .
You access a variable by using ${} , such as ${MY_VARIABLE} . 1. CMake has the concept of scope; you can access the value of the variable after you set it as long as you are in the same scope. If you leave a function or a file in a sub directory, the variable will no longer be defined.
You can use the command line to set entries in the Cache with the syntax cmake -D var:type=value , just cmake -D var=value or with cmake -C CMakeInitialCache. cmake . You can unset entries in the Cache with unset(... CACHE) .
CMake variable names are case sensitive and may only contain alphanumeric characters and underscores.
Because sometimes difference between cmake list variable type and cmake string literal become important.
Try to change the variable setup to the following to avoid the problem:
set(testfiles "test1" "test2")
I was trying something similar with multiple arguments some are strings and some are not, i.e.:
add_custom_target(externalProject COMMAND make -s VALUE1:="${argument1}" VALUE2:=${argument2} VALUE3:="${argument3}" ...)
Where argument3
contained "VAL1 VAL2 VAL3"
.
I found that replacing the spaces with semicolons ;
resolved the issue for me when cmake
creates the makefile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With