Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active April 17, 2023 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scivision/37e68cbd2338ff082b20e4f8242d8221 to your computer and use it in GitHub Desktop.
Save scivision/37e68cbd2338ff082b20e4f8242d8221 to your computer and use it in GitHub Desktop.
Expand ~ tilde to home directory in CMake script
# expands ~ to user home directory
#
# usage:
# expanduser("~/code" x)
function(expanduser in outvar)
if(CMAKE_VERSION VERSION_LESS 3.21)
get_filename_component(out ${in} ABSOLUTE)
else()
file(REAL_PATH ${in} out EXPAND_TILDE)
endif()
set(${outvar} ${out} PARENT_SCOPE)
endfunction(expanduser)
@mcandre
Copy link

mcandre commented Apr 17, 2023

This fails in PowerShell, because it expands using forward slash, which most CLI programs do not handle in PowerShell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment