Last active
April 17, 2023 18:56
-
-
Save scivision/37e68cbd2338ff082b20e4f8242d8221 to your computer and use it in GitHub Desktop.
Expand ~ tilde to home directory in CMake script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This fails in PowerShell, because it expands using forward slash, which most CLI programs do not handle in PowerShell.