diff options
author | Brad King <brad.king@kitware.com> | 2021-04-26 15:30:50 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-04-26 15:30:57 (GMT) |
commit | 6aabf2790c4e4f904aeaa166bf6a7abdd2f290e3 (patch) | |
tree | 9f50fc14b4aa9f030e7cd8019bd7e6f8c58c0e98 /Source | |
parent | 2fcd6a0242cba2d063aef2bc75c4d0f9982ca593 (diff) | |
parent | e4b793c614f2a499d4d235ec2267ad6bff56a697 (diff) | |
download | CMake-6aabf2790c4e4f904aeaa166bf6a7abdd2f290e3.zip CMake-6aabf2790c4e4f904aeaa166bf6a7abdd2f290e3.tar.gz CMake-6aabf2790c4e4f904aeaa166bf6a7abdd2f290e3.tar.bz2 |
Merge topic 'file-REAL_PATH-EXPAND_TILDE'
e4b793c614 file(REAL_PATH): add option EXPAND_TILDE
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Michael Hirsch <michael@scivision.dev>
Merge-request: !6033
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFileCommand.cxx | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 05ebcca..a943258 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -1246,9 +1246,12 @@ bool HandleRealPathCommand(std::vector<std::string> const& args, struct Arguments { std::string BaseDirectory; + bool ExpandTilde = false; }; - static auto const parser = cmArgumentParser<Arguments>{}.Bind( - "BASE_DIRECTORY"_s, &Arguments::BaseDirectory); + static auto const parser = + cmArgumentParser<Arguments>{} + .Bind("BASE_DIRECTORY"_s, &Arguments::BaseDirectory) + .Bind("EXPAND_TILDE"_s, &Arguments::ExpandTilde); std::vector<std::string> unparsedArguments; std::vector<std::string> keywordsMissingValue; @@ -1270,7 +1273,21 @@ bool HandleRealPathCommand(std::vector<std::string> const& args, arguments.BaseDirectory = status.GetMakefile().GetCurrentSourceDirectory(); } - cmCMakePath path(args[1]); + auto input = args[1]; + if (arguments.ExpandTilde && !input.empty()) { + if (input[0] == '~' && (input.length() == 1 || input[1] == '/')) { + std::string home; + if ( +#if defined(_WIN32) && !defined(__CYGWIN__) + cmSystemTools::GetEnv("USERPROFILE", home) || +#endif + cmSystemTools::GetEnv("HOME", home)) { + input.replace(0, 1, home); + } + } + } + + cmCMakePath path(input, cmCMakePath::auto_format); path = path.Absolute(arguments.BaseDirectory).Normal(); auto realPath = cmSystemTools::GetRealPath(path.GenericString()); |