Skip to content

Instantly share code, notes, and snippets.

@scivision
Created January 30, 2025 13:48
Show Gist options
  • Save scivision/f3758ee710638b39bae1106bd1fc0631 to your computer and use it in GitHub Desktop.
Save scivision/f3758ee710638b39bae1106bd1fc0631 to your computer and use it in GitHub Desktop.
CMake execute_process on Windows with paths having spaces
# Toy example--execute_process() on Windows is challenging to handle paths with spaces
# Non-Winows sh -c just works.
set(setvars "set CC=gcc")
set(cmd "cc main.c")
set(cmd $ENV{COMSPEC} /c "${setvars} && ${cmd}")
string(REPLACE "C:/Program Files/" "C:/Progra~1/" cmd "$cmd}")
string(REPLACE "C:/Program Files (x86)/" "C:/Progra~2/" cmd "${cmd}")
execute_process(COMMAND ${cmd})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment