CMAKE does not properly escape custom command argument for MSVC
Imagine following cmake code:
add_custom_command(TARGET WebInterface POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:core::bridge> $(TargetDir)
)
$(TargetDir) - valid MSVC variable which will contain a path Problem arise when $(TargetDir) has spaces. There is no way to tell CMAKE or somehow write comprehensible code the will contain $(TargetDir) escaping.
I managed to achieve the goal with the following solution:
add_custom_command(TARGET WebInterface POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:core::bridge> \"$(TargetDir)
)
NOTE: Opening " but no closing This will result in working command line: cmake.exe -E copy "C:/Users/dmitry/projects/MW API/Services/.build/lib/Debug/bridge.dll" "C:\Users\dmitry\projects\MW API\Services.build\src\Interface\Debug\
Note no closing quote and it works! Also note that $(TargetDir) is substituted with backslashes and its not possible to have closing " in cmake code. cmake -E copy ... will mistreat it.
How that could be solved?
Edited by Dmitry