summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorTushar Maheshwari <tushar27192@gmail.com>2018-12-27 11:58:30 (GMT)
committerBrad King <brad.king@kitware.com>2019-01-16 15:03:35 (GMT)
commit81650e488c734702384ef903630838015a3f81b1 (patch)
tree7391c238c012b6e34ed73130d588bf80a404122e /Source/cmSystemTools.cxx
parentc59eae7ebc5423c2b06befd762f8639b0f23b7a0 (diff)
downloadCMake-81650e488c734702384ef903630838015a3f81b1.zip
CMake-81650e488c734702384ef903630838015a3f81b1.tar.gz
CMake-81650e488c734702384ef903630838015a3f81b1.tar.bz2
cmFileCommand: Add CREATE_LINK subcommand
This brings the functionality of `cmake -E create_symlink` and more to scripts. The default behavior is to create hard links. The `SYMBOLIC` argument can be used to create symlinks instead. The `COPY_ON_ERROR` argument enables a fallback to copying the file in case the link fails. The `RESULT <var>` retrieves the error message generated by the system. It is set to "0" on success. Fixes: #16926
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx16
1 files changed, 16 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index be65853..a1c8c03 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -3134,3 +3134,19 @@ bool cmSystemTools::CreateSymlink(const std::string& origName,
return true;
}
+
+bool cmSystemTools::CreateLink(const std::string& origName,
+ const std::string& newName)
+{
+ uv_fs_t req;
+ int err =
+ uv_fs_link(nullptr, &req, origName.c_str(), newName.c_str(), nullptr);
+ if (err) {
+ std::string e =
+ "failed to create link '" + newName + "': " + uv_strerror(err);
+ cmSystemTools::Error(e.c_str());
+ return false;
+ }
+
+ return true;
+}