Skip to content

Commit

Permalink
launch arbitrary script with powershell on windows (#9)
Browse files Browse the repository at this point in the history
* use powershell on windows
* add closing quote to argument list
  • Loading branch information
justend29 authored Mar 11, 2024
1 parent f18db2f commit 6da01b3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions jgd-cmake-modules/JcmArbitraryScript.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if(CMAKE_SCRIPT_MODE_FILE STREQUAL CMAKE_CURRENT_LIST_FILE)

# Evaluate code
# interpret all escape sequences as their control characters
string(REPLACE \\n \n code ${CMAKE_ARGV${last_arg_idx}})
string(REPLACE \\n \n code "${CMAKE_ARGV${last_arg_idx}}")
string(REPLACE \\r \r code "${code}")
string(REPLACE \\t \t code "${code}")
string(REPLACE \\' ' code "${code}")
Expand Down Expand Up @@ -165,6 +165,7 @@ Examples
#]=======================================================================]
function(jcm_form_arbitrary_script_command)
jcm_parse_arguments(
OPTIONS "WITHOUT_WINDOWS_POWERSHELL"
ONE_VALUE_KEYWORDS "OUT_VAR"
MULTI_VALUE_KEYWORDS "CODE"
REQUIRES_ALL "OUT_VAR" "CODE"
Expand All @@ -183,7 +184,12 @@ function(jcm_form_arbitrary_script_command)
string(REPLACE " " "\ " code "${code}")
string(REPLACE \t \\t code "${code}")

set(${ARGS_OUT_VAR}
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_FUNCTION_LIST_FILE}" -- "'${code}'" PARENT_SCOPE)
if(CMAKE_HOST_SYSTEM_NAME MATCHES "^Windows" AND NOT ARGS_WITHOUT_WINDOWS_POWERSHELL)
set(${ARGS_OUT_VAR}
"powershell" "-Command" "{ Start-Process ${CMAKE_COMMAND} -Wait -ArgumentList \"-P '${CMAKE_CURRENT_FUNCTION_LIST_FILE}' -- '${code}' \"}" PARENT_SCOPE)
else()
set(${ARGS_OUT_VAR}
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_FUNCTION_LIST_FILE}" -- "'${code}'" PARENT_SCOPE)
endif()
endfunction()

0 comments on commit 6da01b3

Please sign in to comment.