summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-01-13 13:54:12 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-01-13 13:54:21 (GMT)
commit5dddc49e035cbc449f47ed9c7526a56873a9d0a8 (patch)
tree7eba7a7ad1e617b673f29c19223bbc1def40f0c1
parenta547f315dd54e4814d52e129b441628c18f7163d (diff)
parentc1170b5602d609f6ccd2506e5db9916c74388187 (diff)
downloadCMake-5dddc49e035cbc449f47ed9c7526a56873a9d0a8.zip
CMake-5dddc49e035cbc449f47ed9c7526a56873a9d0a8.tar.gz
CMake-5dddc49e035cbc449f47ed9c7526a56873a9d0a8.tar.bz2
Merge topic 'fea/add-copy_directory_if_different'
c1170b5602 cmake: Add -E copy_directory_if_different Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !8059
-rw-r--r--Help/manual/cmake.1.rst10
-rw-r--r--Help/release/dev/cmake-E-copy-directory-if-different.rst4
-rw-r--r--Source/cmcmd.cxx11
-rw-r--r--Tests/RunCMake/CommandLine/RunCMakeTest.cmake9
4 files changed, 31 insertions, 3 deletions
diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst
index dc51383..9f77562 100644
--- a/Help/manual/cmake.1.rst
+++ b/Help/manual/cmake.1.rst
@@ -876,6 +876,16 @@ Available commands are:
The command now fails when the source directory does not exist.
Previously it succeeded by creating an empty destination directory.
+.. option:: copy_directory_if_different <dir>... <destination>
+
+ .. versionadded:: 3.26
+
+ Copy changed content of ``<dir>...`` directories to ``<destination>`` directory.
+ If ``<destination>`` directory does not exist it will be created.
+
+ ``copy_directory_if_different`` does follow symlinks.
+ The command fails when the source directory does not exist.
+
.. option:: copy_if_different <file>... <destination>
Copy files to ``<destination>`` (either file or directory) if
diff --git a/Help/release/dev/cmake-E-copy-directory-if-different.rst b/Help/release/dev/cmake-E-copy-directory-if-different.rst
new file mode 100644
index 0000000..6e642c0
--- /dev/null
+++ b/Help/release/dev/cmake-E-copy-directory-if-different.rst
@@ -0,0 +1,4 @@
+cmake-E-copy-directory-if-different
+-----------------------------------
+
+* The :manual:`cmake(1)` ``-E`` option learned a new ``copy_directory_if_different`` command.
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 4303f96..21d0cc9 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -110,6 +110,8 @@ void CMakeCommandUsage(std::string const& program)
"(either file or directory)\n"
<< " copy_directory <dir>... destination - copy content of <dir>... "
"directories to 'destination' directory\n"
+ << " copy_directory_if_different <dir>... destination - copy changed content of <dir>... "
+ "directories to 'destination' directory\n"
<< " copy_if_different <file>... destination - copy files if it has "
"changed\n"
<< " echo [<string>...] - displays arguments as text\n"
@@ -731,12 +733,15 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
return return_value;
}
- // Copy directory content
- if (args[1] == "copy_directory" && args.size() > 3) {
+ // Copy directory contents
+ if ((args[1] == "copy_directory" ||
+ args[1] == "copy_directory_if_different") &&
+ args.size() > 3) {
// If error occurs we want to continue copying next files.
bool return_value = false;
+ const bool copy_always = (args[1] == "copy_directory");
for (auto const& arg : cmMakeRange(args).advance(2).retreat(1)) {
- if (!cmSystemTools::CopyADirectory(arg, args.back())) {
+ if (!cmSystemTools::CopyADirectory(arg, args.back(), copy_always)) {
std::cerr << "Error copying directory from \"" << arg << "\" to \""
<< args.back() << "\".\n";
return_value = true;
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index 480ad09..f48e845 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -594,6 +594,15 @@ unset(in)
unset(out)
set(in ${RunCMake_SOURCE_DIR}/copy_input)
+set(out ${RunCMake_BINARY_DIR}/copy_directory_different_output)
+file(REMOVE_RECURSE "${out}")
+file(MAKE_DIRECTORY ${out})
+run_cmake_command(E_copy_directory_if_different
+ ${CMAKE_COMMAND} -E copy_directory_if_different ${in} ${out})
+unset(in)
+unset(out)
+
+set(in ${RunCMake_SOURCE_DIR}/copy_input)
set(out ${RunCMake_BINARY_DIR}/copy_directory_output)
set(outfile ${out}/file_for_test.txt)
file(REMOVE_RECURSE "${out}")