summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-06-10 15:11:06 +0000
committerKitware Robot <kwrobot@kitware.com>2022-06-10 11:11:26 -0400
commit970fcf7bec93952241655edee98ec217e705fe90 (patch)
tree572d356378cc5efd1d40dbbf1325eec51186815b /Source
parent75654a3b2cd413e61cbdb25d1a986c9ebe87c5bd (diff)
parenta54f7a698374c699540b790baaafca9dd0e3b0a4 (diff)
downloadcmake-970fcf7bec93952241655edee98ec217e705fe90.tar.gz
Merge topic 'update-kwsys'
a54f7a6983 Merge branch 'upstream-KWSys' into update-kwsys 975c44654d KWSys 2022-06-09 (9b65e88d) Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !7345
Diffstat (limited to 'Source')
-rw-r--r--Source/kwsys/SystemTools.cxx27
1 files changed, 27 insertions, 0 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index c38b456441..5889a4b0b4 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -94,6 +94,13 @@
# include <linux/fs.h>
#endif
+#if defined(__APPLE__) && \
+ (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0 >= 101200)
+# define KWSYS_SYSTEMTOOLS_HAVE_MACOS_COPYFILE_CLONE
+# include <copyfile.h>
+# include <sys/stat.h>
+#endif
+
// Windows API.
#if defined(_WIN32)
# include <windows.h>
@@ -2474,6 +2481,26 @@ Status SystemTools::CloneFileContent(std::string const& source,
close(out);
return status;
+#elif defined(__APPLE__) && \
+ defined(KWSYS_SYSTEMTOOLS_HAVE_MACOS_COPYFILE_CLONE)
+ // NOTE: we cannot use `clonefile` as the {a,c,m}time for the file needs to
+ // be updated by `copy_file_if_different` and `copy_file`.
+ if (copyfile(source.c_str(), destination.c_str(), nullptr,
+ COPYFILE_METADATA | COPYFILE_CLONE) < 0) {
+ return Status::POSIX_errno();
+ }
+# if KWSYS_CXX_HAS_UTIMENSAT
+ // utimensat is only available on newer Unixes and macOS 10.13+
+ if (utimensat(AT_FDCWD, destination.c_str(), nullptr, 0) < 0) {
+ return Status::POSIX_errno();
+ }
+# else
+ // fall back to utimes
+ if (utimes(destination.c_str(), nullptr) < 0) {
+ return Status::POSIX_errno();
+ }
+# endif
+ return Status::Success();
#else
(void)source;
(void)destination;