From c3b80e86640630036e855775692268531e94f3c1 Mon Sep 17 00:00:00 2001 From: Pavel P Date: Sun, 21 Jan 2018 00:39:18 -0800 Subject: Windows: Add support for running CMake tools through a symlink When `cmake.exe` is executed through a symlink, `GetModuleFileNameW` will return location of the link instead of the real path of `cmake.exe`. This results in the following error output: CMake Error: Could not find CMAKE_ROOT !!! CMake has most likely not been installed correctly. Use `cmSystemTools::GetRealPath` in `FindCMakeResources` on Windows to resolve any symlink returned by `GetModuleFileNameW`. --- Source/cmSystemTools.cxx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 06b0b3c..ce08465 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -2107,8 +2107,12 @@ void cmSystemTools::FindCMakeResources(const char* argv0) (void)argv0; // ignore this on windows wchar_t modulepath[_MAX_PATH]; ::GetModuleFileNameW(NULL, modulepath, sizeof(modulepath)); - exe_dir = - cmSystemTools::GetFilenamePath(cmsys::Encoding::ToNarrow(modulepath)); + std::string path = cmsys::Encoding::ToNarrow(modulepath); + std::string realPath = cmSystemTools::GetRealPath(path, NULL); + if (realPath.empty()) { + realPath = path; + } + exe_dir = cmSystemTools::GetFilenamePath(realPath); #elif defined(__APPLE__) (void)argv0; // ignore this on OS X #define CM_EXE_PATH_LOCAL_SIZE 16384 -- cgit v0.12