summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorGeorg Schwab <georg.schwab@emocean.io>2021-05-06 09:26:09 (GMT)
committerBrad King <brad.king@kitware.com>2021-05-10 15:12:28 (GMT)
commitd0c31cbff94b86ae00fddac89c6f404cc4229370 (patch)
treebcec6ef443bf03a46c51167af9628ec9ba0fb67d /Source
parent2ee55f9718264d716eeabc9d61ede6e434443fd1 (diff)
downloadCMake-d0c31cbff94b86ae00fddac89c6f404cc4229370.zip
CMake-d0c31cbff94b86ae00fddac89c6f404cc4229370.tar.gz
CMake-d0c31cbff94b86ae00fddac89c6f404cc4229370.tar.bz2
Windows: Use real artifact versioning symlinks if possible
When cross compiling from Windows to a platform that uses SONAMEs, real symlinks are now created for the VERSION and SOVERSION links instead of copies, if the user has the necessary privileges. Fixes: #22128
Diffstat (limited to 'Source')
-rw-r--r--Source/cmcmd.cxx15
1 files changed, 13 insertions, 2 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 30347f2..98946b6 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -1643,10 +1643,21 @@ cmsys::Status cmcmd::SymlinkInternal(std::string const& file,
if (cmSystemTools::FileExists(link) || cmSystemTools::FileIsSymlink(link)) {
cmSystemTools::RemoveFile(link);
}
+ std::string linktext = cmSystemTools::GetFilenameName(file);
#if defined(_WIN32) && !defined(__CYGWIN__)
- return cmSystemTools::CopyFileAlways(file, link);
+ std::string errorMessage;
+ cmsys::Status status =
+ cmSystemTools::CreateSymlink(linktext, link, &errorMessage);
+ // Creating a symlink will fail with ERROR_PRIVILEGE_NOT_HELD if the user
+ // does not have SeCreateSymbolicLinkPrivilege, or if developer mode is not
+ // active. In that case, we try to copy the file.
+ if (status.GetWindows() == ERROR_PRIVILEGE_NOT_HELD) {
+ status = cmSystemTools::CopyFileAlways(file, link);
+ } else if (!status) {
+ cmSystemTools::Error(errorMessage);
+ }
+ return status;
#else
- std::string linktext = cmSystemTools::GetFilenameName(file);
return cmSystemTools::CreateSymlink(linktext, link);
#endif
}