I'm trying to write a custom CMake command that will execute llvm-cov
as a part of the coverage analysis. What I have is a string variable tests
that holds the list of test executables and was defined as:
set(tests "\"path/to/test1\" -object \"path/to/test2\" -object \"path/to/test3\"")
Note that -object
specifier precedes every test except the first one, since that's the format that llvm-cov expects. When I print that variable, I get:
"path/to/test1" -object "path/to/test2" -object "path/to/test3"
which is what I wanted to achieve.
However, when I create a custom CMake command like this:
add_custom_command(
TARGET coverage
COMMAND llvm-cov show -instr-profile ${profdata_file} ${tests} -format html -o coverage)
The command is not correctly executed since it expands to:
llvm-cov show -instr-profile path/to/profdata "/path/to/test1"\ -object\ "path/to/test2"\ -object\ "path/to/test3" -format html -o coverage
The problem is that backslashes are added for some reason before space characters. I've tried using VERBATIM
and COMMAND_EXPAND_LISTS
options of add_custom_command
, but neither worked. How can I solve this formatting issue?