summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorJon Chronopoulos <patches@crondog.com>2018-06-11 07:28:09 (GMT)
committerBrad King <brad.king@kitware.com>2018-09-18 15:24:08 (GMT)
commitafb7f6e4ff8a0c1a68c8d8cf2d6cf72401cfb8ff (patch)
treef79c1b7cf4d0e408d3e0b98b06503b2e1cc7e5f8 /Source/cmSystemTools.cxx
parent49cb2a504d1e00e51774a23bf1b91c982fa69e5d (diff)
downloadCMake-afb7f6e4ff8a0c1a68c8d8cf2d6cf72401cfb8ff.zip
CMake-afb7f6e4ff8a0c1a68c8d8cf2d6cf72401cfb8ff.tar.gz
CMake-afb7f6e4ff8a0c1a68c8d8cf2d6cf72401cfb8ff.tar.bz2
cmake: Add '-E create_symlink' support on Windows
The allows `-E create_symlink` to work on Windows. It utilizes `uv_fs_symlink`. I am still unsure exactly which Windows platforms will work without requiring Administrator privileges or needing a user/group with the "Create Symbolic Links" User Rights. It does work with my Windows 10 Pro with Developer Mode turned on. In the test suite check that the symlink either worked or failed with a permissions error. Use recent changes in cmSystemTools::FileExists to check that a symlink is broken.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx25
1 files changed, 23 insertions, 2 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 79e5ccf..8339aac 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -6,6 +6,7 @@
#include "cmDuration.h"
#include "cmProcessOutput.h"
#include "cm_sys_stat.h"
+#include "cm_uv.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
# include "cmArchiveWrite.h"
@@ -55,8 +56,6 @@
# include <wincrypt.h>
# include <fcntl.h> /* _O_TEXT */
-
-# include "cm_uv.h"
#else
# include <sys/time.h>
# include <unistd.h>
@@ -2988,3 +2987,25 @@ bool cmSystemTools::StringToULong(const char* str, unsigned long* value)
*value = strtoul(str, &endp, 10);
return (*endp == '\0') && (endp != str) && (errno == 0);
}
+
+bool cmSystemTools::CreateSymlink(const std::string& origName,
+ const std::string& newName)
+{
+ uv_fs_t req;
+ int flags = 0;
+#if defined(_WIN32)
+ if (cmsys::SystemTools::FileIsDirectory(origName)) {
+ flags |= UV_FS_SYMLINK_DIR;
+ }
+#endif
+ int err = uv_fs_symlink(nullptr, &req, origName.c_str(), newName.c_str(),
+ flags, nullptr);
+ if (err) {
+ std::string e =
+ "failed to create symbolic link '" + newName + "': " + uv_strerror(err);
+ cmSystemTools::Error(e.c_str());
+ return false;
+ }
+
+ return true;
+}