diff --git a/Source/cmInstrumentation.cxx b/Source/cmInstrumentation.cxx index b7298fce2e..ae84725129 100644 --- a/Source/cmInstrumentation.cxx +++ b/Source/cmInstrumentation.cxx @@ -743,7 +743,11 @@ std::string cmInstrumentation::GetCommandStr( { std::string command_str; for (size_t i = 0; i < args.size(); ++i) { - command_str = cmStrCat(command_str, '"', args[i], '"'); + if (args[i].find(' ') != std::string::npos) { + command_str = cmStrCat(command_str, '"', args[i], '"'); + } else { + command_str = cmStrCat(command_str, args[i]); + } if (i < args.size() - 1) { command_str = cmStrCat(command_str, ' '); } diff --git a/Tests/RunCMake/Instrumentation/RunCMakeTest.cmake b/Tests/RunCMake/Instrumentation/RunCMakeTest.cmake index 456a88451e..51e08f2159 100644 --- a/Tests/RunCMake/Instrumentation/RunCMakeTest.cmake +++ b/Tests/RunCMake/Instrumentation/RunCMakeTest.cmake @@ -63,6 +63,10 @@ function(instrument test) set(copy_loc ${v1}/query/generated) # Copied files here should be cleared on configure endif() if (ARGS_COPY_QUERIES) + set(CMAKE_COMMAND_QUOTE ${CMAKE_COMMAND}) + if (CMAKE_COMMAND MATCHES " ") + set(CMAKE_COMMAND_QUOTE "\\\"${CMAKE_COMMAND}\\\"") + endif() file(MAKE_DIRECTORY ${copy_loc}) set(generated_queries "0;1;2") foreach(n IN LISTS generated_queries) diff --git a/Tests/RunCMake/Instrumentation/query/generated/query-1.json.in b/Tests/RunCMake/Instrumentation/query/generated/query-1.json.in index 5a77c5c58e..a8e63cfef0 100644 --- a/Tests/RunCMake/Instrumentation/query/generated/query-1.json.in +++ b/Tests/RunCMake/Instrumentation/query/generated/query-1.json.in @@ -1,7 +1,7 @@ { "callbacks" : [ - "\"@CMAKE_COMMAND@\" \"-E\" \"echo\" \"callback1\"" + "@CMAKE_COMMAND_QUOTE@ -E echo callback1" ], "hooks" : [ diff --git a/Tests/RunCMake/Instrumentation/query/generated/query-2.json.in b/Tests/RunCMake/Instrumentation/query/generated/query-2.json.in index d4badb07e8..d3c4e89360 100644 --- a/Tests/RunCMake/Instrumentation/query/generated/query-2.json.in +++ b/Tests/RunCMake/Instrumentation/query/generated/query-2.json.in @@ -1,8 +1,8 @@ { "callbacks" : [ - "\"@CMAKE_COMMAND@\" \"-E\" \"echo\" \"callback2\"", - "\"@CMAKE_COMMAND@\" \"-E\" \"echo\" \"callback3\"" + "@CMAKE_COMMAND_QUOTE@ -E echo callback2", + "@CMAKE_COMMAND_QUOTE@ -E echo callback3" ], "hooks" : [