Hello.

With following patch, I have added support for multiple directories for 
make_directory command.


?Best Regards

Bartosz
From e189db26e60254712e3e73a11296c58d8f61fe68 Mon Sep 17 00:00:00 2001
From: Bartosz Kosiorek <gan...@poczta.onet.pl>
Date: Wed, 9 Dec 2015 15:59:43 +0100
Subject: [PATCH] Extend make_directory command to support multiple directories

---
 Help/manual/cmake.1.rst                               |  9 +++++----
 Source/cmcmd.cxx                                      | 19 ++++++++++++-------
 .../E_make_directory-directory-with-parent-result.txt |  1 +
 .../E_make_directory-directory-with-parent-stderr.txt |  0
 ...ke_directory-three-directories-and-file-result.txt |  1 +
 ...ke_directory-three-directories-and-file-stderr.txt |  1 +
 .../E_make_directory-three-directories-result.txt     |  1 +
 .../E_make_directory-three-directories-stderr.txt     |  0
 Tests/RunCMake/CommandLine/RunCMakeTest.cmake         | 14 ++++++++++++++
 9 files changed, 35 insertions(+), 11 deletions(-)
 create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-result.txt
 create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-stderr.txt
 create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-result.txt
 create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt
 create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-three-directories-result.txt
 create mode 100644 Tests/RunCMake/CommandLine/E_make_directory-three-directories-stderr.txt

diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst
index 4cbe976..3cd7888 100644
--- a/Help/manual/cmake.1.rst
+++ b/Help/manual/cmake.1.rst
@@ -167,7 +167,8 @@ Available commands are:
   Change the current working directory and run a command.
 
 ``compare_files <file1> <file2>``
-  Check if file1 is same as file2.
+  Check if ``<file1>`` is same as ``<file2>``. If files are the same,
+  then returns 0, if not itreturns 1.
 
 ``copy <file>... <destination>``
   Copy files to ``<destination>`` (either file or directory).
@@ -194,10 +195,10 @@ Available commands are:
   Run command in a modified environment.
 
 ``environment``
-  Display the current environment.
+  Display the current environment variables.
 
-``make_directory <dir>``
-  Create a directory.
+``make_directory <dir>...``
+  Create parent and <dir> directories.
 
 ``md5sum <file>...``
   Compute md5sum of files.
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 6a4234f..fb7b1f5 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -68,7 +68,7 @@ void CMakeCommandUsage(const char* program)
     << "  env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...\n"
     << "                            - run command in a modified environment\n"
     << "  environment               - display the current environment\n"
-    << "  make_directory dir        - create a directory\n"
+    << "  make_directory <dir>...   - create parent and <dir> directories\n"
     << "  md5sum <file>...          - compute md5sum of files\n"
     << "  remove [-f] <file>...     - remove the file(s), use -f to force "
        "it\n"
@@ -447,15 +447,20 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
       }
 #endif
 
-    else if (args[1] == "make_directory" && args.size() == 3)
+    else if (args[1] == "make_directory" && args.size() > 2)
       {
-      if(!cmSystemTools::MakeDirectory(args[2].c_str()))
+      // If error occurs we want to continue copying next files.
+      bool return_value = 0;
+      for (std::string::size_type cc = 2; cc < args.size(); cc ++)
         {
-        std::cerr << "Error making directory \"" << args[2]
-                  << "\".\n";
-        return 1;
+        if(!cmSystemTools::MakeDirectory(args[cc].c_str()))
+          {
+          std::cerr << "Error creating directory \""
+                    << args[cc] << "\".\n";
+          return_value = 1;
+          }
         }
-      return 0;
+      return return_value;
       }
 
     else if (args[1] == "remove_directory" && args.size() == 3)
diff --git a/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-result.txt b/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-stderr.txt b/Tests/RunCMake/CommandLine/E_make_directory-directory-with-parent-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-result.txt b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt
new file mode 100644
index 0000000..08a9428
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-and-file-stderr.txt
@@ -0,0 +1 @@
+^Error creating directory .*file_for_test.txt\".$
diff --git a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-result.txt b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CommandLine/E_make_directory-three-directories-stderr.txt b/Tests/RunCMake/CommandLine/E_make_directory-three-directories-stderr.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index 57036ba..5e2200f 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -140,6 +140,20 @@ unset(in)
 unset(out)
 unset(outfile)
 
+set(out ${RunCMake_BINARY_DIR}/make_directory_output)
+set(outfile ${out}/file_for_test.txt)
+file(REMOVE_RECURSE "${out}")
+file(MAKE_DIRECTORY ${out})
+file(WRITE ${outfile} "")
+run_cmake_command(E_make_directory-three-directories
+  ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${out}/d2)
+run_cmake_command(E_make_directory-directory-with-parent
+  ${CMAKE_COMMAND} -E make_directory ${out}/parent/child)
+run_cmake_command(E_make_directory-three-directories-and-file
+  ${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${outfile})
+unset(out)
+unset(outfile)
+
 
 run_cmake_command(E_env-no-command0 ${CMAKE_COMMAND} -E env)
 run_cmake_command(E_env-no-command1 ${CMAKE_COMMAND} -E env TEST_ENV=1)
-- 
2.5.0

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to