separate_arguments WINDOWS_COMMAND does not treat backslashes literally
Consider the following CMake script file:
separate_arguments(args WINDOWS_COMMAND "cmd.exe /C dir C:\\Windows\\ /w")
foreach(arg IN LISTS args)
message("${arg}")
endforeach()
and its output when running it with cmake -P
:
cmd.exe
/C
dir
C:\Windows;/w
The sequence backslash-space is treated as an escaped space.
However the documentation of separate_arguments
states
Backslashes are literal unless they precede double-quotes.
From the documentation and the linked MSDN page "Parsing C command-line arguments" I would expect the script to have this output:
cmd.exe
/C
dir
C:\Windows\
/w