[Cmake-commits] CMake branch, next, updated. v3.6.1-1233-gdf23706

Brad King brad.king at kitware.com
Wed Aug 10 13:29:26 EDT 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  df237068ee8618e19354d2fec3f0f99b5a9fee85 (commit)
       via  e4f508e42397549cd966e47349d4030cb793c354 (commit)
       via  4e9b97d7397fd526e6b4e4ce43dd305cb8341ac8 (commit)
       via  41c9e14afb0bc7e68e4530f76329b7c11cdfa0e4 (commit)
       via  3c3b37b0bbd3fb78aa60a2b38184b6397d2ea47f (commit)
       via  0a5dd3c700f1873be217707aa89a805d009bac3e (commit)
       via  3a5f609cbb4ae63fca1eb87918767a4296d16e5f (commit)
       via  f582dba6664e5ea814f3b33c71ae4d83db17b996 (commit)
       via  74f0d4abcd8de84283858fe144772e688669e46a (commit)
       via  94c29976d0020b48a5c565234b71f8f6abaf08be (commit)
      from  5afd0cbd9173fde8a7c73c2810a44d0e76c4a294 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=df237068ee8618e19354d2fec3f0f99b5a9fee85
commit df237068ee8618e19354d2fec3f0f99b5a9fee85
Merge: 5afd0cb e4f508e
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Wed Aug 10 13:29:23 2016 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Wed Aug 10 13:29:23 2016 -0400

    Merge topic 'autogen-same-name' into next
    
    e4f508e4 Tests/QtAutogen: Test same moc/qrc source names in different directories
    4e9b97d7 QtAutogen: Allow multiple qrc files with the same name
    41c9e14a QtAutogen: Allow multiple moc files with the same name
    3c3b37b0 QtAutogen: Use std:: instead of ::std::
    0a5dd3c7 cmFilePathUuid: Add class to generate deterministic unique file names
    3a5f609c cmCryptoHash: New ByteHash methods that return a byte vector
    f582dba6 cmCryptoHash: Return byte vector from internal Finalize method
    74f0d4ab cmCryptoHash: New byte hash to string function
    94c29976 cmCryptoHash: Documentation comments


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e4f508e42397549cd966e47349d4030cb793c354
commit e4f508e42397549cd966e47349d4030cb793c354
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Sat Aug 6 15:22:54 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 13:21:34 2016 -0400

    Tests/QtAutogen: Test same moc/qrc source names in different directories

diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt
index d5aca55..e35e1d1 100644
--- a/Tests/QtAutogen/CMakeLists.txt
+++ b/Tests/QtAutogen/CMakeLists.txt
@@ -110,6 +110,10 @@ set_target_properties(
   AUTOMOC TRUE
 )
 
+# Test AUTOMOC and AUTORCC on source files with the same name
+# but in different subdirectories
+add_subdirectory(sameName)
+
 include(GenerateExportHeader)
 # The order is relevant here. B depends on A, and B headers depend on A
 # headers both subdirectories use CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE and we
diff --git a/Tests/QtAutogen/sameName/CMakeLists.txt b/Tests/QtAutogen/sameName/CMakeLists.txt
new file mode 100644
index 0000000..ed045fb
--- /dev/null
+++ b/Tests/QtAutogen/sameName/CMakeLists.txt
@@ -0,0 +1,21 @@
+# Test AUTOMOC and AUTORCC on source files with the same name
+# but in different subdirectories
+
+add_executable(sameName
+  aaa/bbb/item.cpp
+  aaa/bbb/data.qrc
+  aaa/item.cpp
+  aaa/data.qrc
+  bbb/aaa/item.cpp
+  bbb/aaa/data.qrc
+  bbb/item.cpp
+  bbb/data.qrc
+  ccc/item.cpp
+  ccc/data.qrc
+  item.cpp
+  data.qrc
+  main.cpp
+)
+target_include_directories(sameName PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_link_libraries(sameName ${QT_LIBRARIES})
+set_target_properties( sameName PROPERTIES AUTOMOC TRUE AUTORCC TRUE )
diff --git a/Tests/QtAutogen/sameName/aaa/bbb/data.qrc b/Tests/QtAutogen/sameName/aaa/bbb/data.qrc
new file mode 100644
index 0000000..0ea3537
--- /dev/null
+++ b/Tests/QtAutogen/sameName/aaa/bbb/data.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="aaa/bbb">
+  <file>item.hpp</file>
+  <file>item.cpp</file>
+</qresource>
+</RCC>
diff --git a/Tests/QtAutogen/sameName/aaa/bbb/item.cpp b/Tests/QtAutogen/sameName/aaa/bbb/item.cpp
new file mode 100644
index 0000000..20d0044
--- /dev/null
+++ b/Tests/QtAutogen/sameName/aaa/bbb/item.cpp
@@ -0,0 +1,10 @@
+#include "item.hpp"
+
+namespace aaa {
+namespace bbb {
+
+void Item::go()
+{
+}
+}
+}
diff --git a/Tests/QtAutogen/sameName/aaa/bbb/item.hpp b/Tests/QtAutogen/sameName/aaa/bbb/item.hpp
new file mode 100644
index 0000000..0855043
--- /dev/null
+++ b/Tests/QtAutogen/sameName/aaa/bbb/item.hpp
@@ -0,0 +1,18 @@
+#ifndef AAA_BBB_ITEM_HPP
+#define AAA_BBB_ITEM_HPP
+
+#include <QObject>
+
+namespace aaa {
+namespace bbb {
+
+class Item : public QObject
+{
+  Q_OBJECT
+  Q_SLOT
+  void go();
+};
+}
+}
+
+#endif
diff --git a/Tests/QtAutogen/sameName/aaa/data.qrc b/Tests/QtAutogen/sameName/aaa/data.qrc
new file mode 100644
index 0000000..379af60
--- /dev/null
+++ b/Tests/QtAutogen/sameName/aaa/data.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="aaa/">
+  <file>item.hpp</file>
+  <file>item.cpp</file>
+</qresource>
+</RCC>
diff --git a/Tests/QtAutogen/sameName/aaa/item.cpp b/Tests/QtAutogen/sameName/aaa/item.cpp
new file mode 100644
index 0000000..95dd3b6
--- /dev/null
+++ b/Tests/QtAutogen/sameName/aaa/item.cpp
@@ -0,0 +1,8 @@
+#include "item.hpp"
+
+namespace aaa {
+
+void Item::go()
+{
+}
+}
diff --git a/Tests/QtAutogen/sameName/aaa/item.hpp b/Tests/QtAutogen/sameName/aaa/item.hpp
new file mode 100644
index 0000000..b63466f
--- /dev/null
+++ b/Tests/QtAutogen/sameName/aaa/item.hpp
@@ -0,0 +1,16 @@
+#ifndef AAA_ITEM_HPP
+#define AAA_ITEM_HPP
+
+#include <QObject>
+
+namespace aaa {
+
+class Item : public QObject
+{
+  Q_OBJECT
+  Q_SLOT
+  void go();
+};
+}
+
+#endif
diff --git a/Tests/QtAutogen/sameName/bbb/aaa/data.qrc b/Tests/QtAutogen/sameName/bbb/aaa/data.qrc
new file mode 100644
index 0000000..da98009
--- /dev/null
+++ b/Tests/QtAutogen/sameName/bbb/aaa/data.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="bbb/aaa/">
+  <file>item.hpp</file>
+  <file>item.cpp</file>
+</qresource>
+</RCC>
diff --git a/Tests/QtAutogen/sameName/bbb/aaa/item.cpp b/Tests/QtAutogen/sameName/bbb/aaa/item.cpp
new file mode 100644
index 0000000..ac4b2c2
--- /dev/null
+++ b/Tests/QtAutogen/sameName/bbb/aaa/item.cpp
@@ -0,0 +1,10 @@
+#include "item.hpp"
+
+namespace bbb {
+namespace aaa {
+
+void Item::go()
+{
+}
+}
+}
diff --git a/Tests/QtAutogen/sameName/bbb/aaa/item.hpp b/Tests/QtAutogen/sameName/bbb/aaa/item.hpp
new file mode 100644
index 0000000..be07ca8
--- /dev/null
+++ b/Tests/QtAutogen/sameName/bbb/aaa/item.hpp
@@ -0,0 +1,18 @@
+#ifndef BBB_AAA_ITEM_HPP
+#define BBB_AAA_ITEM_HPP
+
+#include <QObject>
+
+namespace bbb {
+namespace aaa {
+
+class Item : public QObject
+{
+  Q_OBJECT
+  Q_SLOT
+  void go();
+};
+}
+}
+
+#endif
diff --git a/Tests/QtAutogen/sameName/bbb/data.qrc b/Tests/QtAutogen/sameName/bbb/data.qrc
new file mode 100644
index 0000000..5b080f5
--- /dev/null
+++ b/Tests/QtAutogen/sameName/bbb/data.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="bbb/">
+  <file>item.hpp</file>
+  <file>item.cpp</file>
+</qresource>
+</RCC>
diff --git a/Tests/QtAutogen/sameName/bbb/item.cpp b/Tests/QtAutogen/sameName/bbb/item.cpp
new file mode 100644
index 0000000..f97a143
--- /dev/null
+++ b/Tests/QtAutogen/sameName/bbb/item.cpp
@@ -0,0 +1,8 @@
+#include "item.hpp"
+
+namespace bbb {
+
+void Item::go()
+{
+}
+}
diff --git a/Tests/QtAutogen/sameName/bbb/item.hpp b/Tests/QtAutogen/sameName/bbb/item.hpp
new file mode 100644
index 0000000..5b7f985
--- /dev/null
+++ b/Tests/QtAutogen/sameName/bbb/item.hpp
@@ -0,0 +1,16 @@
+#ifndef BBB_ITEM_HPP
+#define BBB_ITEM_HPP
+
+#include <QObject>
+
+namespace bbb {
+
+class Item : public QObject
+{
+  Q_OBJECT
+  Q_SLOT
+  void go();
+};
+}
+
+#endif
diff --git a/Tests/QtAutogen/sameName/ccc/data.qrc b/Tests/QtAutogen/sameName/ccc/data.qrc
new file mode 100644
index 0000000..f934c39
--- /dev/null
+++ b/Tests/QtAutogen/sameName/ccc/data.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="ccc/">
+  <file>item.hpp</file>
+  <file>item.cpp</file>
+</qresource>
+</RCC>
diff --git a/Tests/QtAutogen/sameName/ccc/item.cpp b/Tests/QtAutogen/sameName/ccc/item.cpp
new file mode 100644
index 0000000..d90b2b8
--- /dev/null
+++ b/Tests/QtAutogen/sameName/ccc/item.cpp
@@ -0,0 +1,23 @@
+#include "item.hpp"
+
+namespace ccc {
+
+void Item::go()
+{
+}
+
+class MocTest : public QObject
+{
+  Q_OBJECT;
+  Q_SLOT
+  void go();
+};
+
+void MocTest::go()
+{
+}
+}
+
+// Include own moc files
+#include "item.moc"
+#include "moc_item.cpp"
diff --git a/Tests/QtAutogen/sameName/ccc/item.hpp b/Tests/QtAutogen/sameName/ccc/item.hpp
new file mode 100644
index 0000000..96fcc24
--- /dev/null
+++ b/Tests/QtAutogen/sameName/ccc/item.hpp
@@ -0,0 +1,16 @@
+#ifndef CCC_ITEM_HPP
+#define CCC_ITEM_HPP
+
+#include <QObject>
+
+namespace ccc {
+
+class Item : public QObject
+{
+  Q_OBJECT
+  Q_SLOT
+  void go();
+};
+}
+
+#endif
diff --git a/Tests/QtAutogen/sameName/data.qrc b/Tests/QtAutogen/sameName/data.qrc
new file mode 100644
index 0000000..4ce0b4e
--- /dev/null
+++ b/Tests/QtAutogen/sameName/data.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+  <file>main.cpp</file>
+</qresource>
+</RCC>
diff --git a/Tests/QtAutogen/sameName/item.cpp b/Tests/QtAutogen/sameName/item.cpp
new file mode 100644
index 0000000..e013cf3
--- /dev/null
+++ b/Tests/QtAutogen/sameName/item.cpp
@@ -0,0 +1,5 @@
+#include "item.hpp"
+
+void Item::go()
+{
+}
diff --git a/Tests/QtAutogen/sameName/item.hpp b/Tests/QtAutogen/sameName/item.hpp
new file mode 100644
index 0000000..91bba3b
--- /dev/null
+++ b/Tests/QtAutogen/sameName/item.hpp
@@ -0,0 +1,13 @@
+#ifndef ITEM_HPP
+#define ITEM_HPP
+
+#include <QObject>
+
+class Item : public QObject
+{
+  Q_OBJECT
+  Q_SLOT
+  void go();
+};
+
+#endif
diff --git a/Tests/QtAutogen/sameName/main.cpp b/Tests/QtAutogen/sameName/main.cpp
new file mode 100644
index 0000000..a4ffcb3
--- /dev/null
+++ b/Tests/QtAutogen/sameName/main.cpp
@@ -0,0 +1,16 @@
+#include "aaa/bbb/item.hpp"
+#include "aaa/item.hpp"
+#include "bbb/aaa/item.hpp"
+#include "bbb/item.hpp"
+#include "ccc/item.hpp"
+
+int main(int argv, char** args)
+{
+  // Object instances
+  ::aaa::Item aaa_item;
+  ::aaa::bbb::Item aaa_bbb_item;
+  ::bbb::Item bbb_item;
+  ::bbb::aaa::Item bbb_aaa_item;
+  ::ccc::Item ccc_item;
+  return 0;
+}

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4e9b97d7397fd526e6b4e4ce43dd305cb8341ac8
commit 4e9b97d7397fd526e6b4e4ce43dd305cb8341ac8
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Sat Aug 6 14:57:52 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 13:21:33 2016 -0400

    QtAutogen: Allow multiple qrc files with the same name
    
    Use cmFilePathUuid for qrc files.

diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx
index d5634e8..7efb333 100644
--- a/Source/cmQtAutoGeneratorInitializer.cxx
+++ b/Source/cmQtAutoGeneratorInitializer.cxx
@@ -13,6 +13,7 @@
 
 #include "cmQtAutoGeneratorInitializer.h"
 
+#include "cmFilePathUuid.h"
 #include "cmLocalGenerator.h"
 #include "cmMakefile.h"
 #include "cmSourceFile.h"
@@ -25,6 +26,34 @@
 #include "cmGlobalVisualStudioGenerator.h"
 #endif
 
+static std::string GetAutogenTargetName(cmGeneratorTarget const* target)
+{
+  std::string autogenTargetName = target->GetName();
+  autogenTargetName += "_automoc";
+  return autogenTargetName;
+}
+
+static std::string GetAutogenTargetDir(cmGeneratorTarget const* target)
+{
+  cmMakefile* makefile = target->Target->GetMakefile();
+  std::string targetDir = makefile->GetCurrentBinaryDirectory();
+  targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
+  targetDir += "/";
+  targetDir += GetAutogenTargetName(target);
+  targetDir += ".dir/";
+  return targetDir;
+}
+
+static std::string GetAutogenTargetBuildDir(cmGeneratorTarget const* target)
+{
+  cmMakefile* makefile = target->Target->GetMakefile();
+  std::string targetDir = makefile->GetCurrentBinaryDirectory();
+  targetDir += "/";
+  targetDir += GetAutogenTargetName(target);
+  targetDir += ".dir/";
+  return targetDir;
+}
+
 static void SetupSourceFiles(cmGeneratorTarget const* target,
                              std::vector<std::string>& skipMoc,
                              std::vector<std::string>& mocSources,
@@ -38,6 +67,7 @@ static void SetupSourceFiles(cmGeneratorTarget const* target,
 
   std::vector<std::string> newRccFiles;
 
+  cmFilePathUuid fpathUuid(makefile);
   for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
        fileIt != srcFiles.end(); ++fileIt) {
     cmSourceFile* sf = *fileIt;
@@ -55,13 +85,12 @@ static void SetupSourceFiles(cmGeneratorTarget const* target,
     if (target->GetPropertyAsBool("AUTORCC")) {
       if (ext == "qrc" &&
           !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) {
-        std::string basename =
-          cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile);
 
-        std::string rcc_output_dir = target->GetSupportDirectory();
-        cmSystemTools::MakeDirectory(rcc_output_dir.c_str());
-        std::string rcc_output_file = rcc_output_dir;
-        rcc_output_file += "/qrc_" + basename + ".cpp";
+        std::string rcc_output_file = GetAutogenTargetBuildDir(target);
+        // Create output directory
+        cmSystemTools::MakeDirectory(rcc_output_file.c_str());
+        rcc_output_file += fpathUuid.get(absFile, "qrc_", ".cpp");
+
         makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
                                  rcc_output_file.c_str(), false);
         makefile->GetOrCreateSource(rcc_output_file, true);
@@ -365,24 +394,6 @@ static void MergeRccOptions(std::vector<std::string>& opts,
   opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
 }
 
-std::string GetAutogenTargetName(cmGeneratorTarget const* target)
-{
-  std::string autogenTargetName = target->GetName();
-  autogenTargetName += "_automoc";
-  return autogenTargetName;
-}
-
-std::string GetAutogenTargetDir(cmGeneratorTarget const* target)
-{
-  cmMakefile* makefile = target->Target->GetMakefile();
-  std::string targetDir = makefile->GetCurrentBinaryDirectory();
-  targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
-  targetDir += "/";
-  targetDir += GetAutogenTargetName(target);
-  targetDir += ".dir/";
-  return targetDir;
-}
-
 static void copyTargetProperty(cmTarget* destinationTarget,
                                cmTarget* sourceTarget,
                                const std::string& propertyName)
@@ -737,6 +748,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
       ) {
     std::vector<cmSourceFile*> srcFiles;
     target->GetConfigCommonSourceFiles(srcFiles);
+    cmFilePathUuid fpathUuid(makefile);
     for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
          fileIt != srcFiles.end(); ++fileIt) {
       cmSourceFile* sf = *fileIt;
@@ -747,15 +759,13 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
       if (target->GetPropertyAsBool("AUTORCC")) {
         if (ext == "qrc" &&
             !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) {
-          std::string basename =
-            cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile);
-
-          std::string rcc_output_dir = target->GetSupportDirectory();
-          cmSystemTools::MakeDirectory(rcc_output_dir.c_str());
-          std::string rcc_output_file = rcc_output_dir;
-          rcc_output_file += "/qrc_" + basename + ".cpp";
-          rcc_output.push_back(rcc_output_file);
-
+          {
+            std::string rcc_output_file = GetAutogenTargetBuildDir(target);
+            // Create output directory
+            cmSystemTools::MakeDirectory(rcc_output_file.c_str());
+            rcc_output_file += fpathUuid.get(absFile, "qrc_", ".cpp");
+            rcc_output.push_back(rcc_output_file);
+          }
           if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) {
             if (qtMajorVersion == "5") {
               ListQt5RccInputs(sf, target, depends);
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index 33f7a54..a261962 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -88,6 +88,23 @@ static std::string extractSubDir(const std::string& absPath,
   return subDir;
 }
 
+static bool FileNameIsUnique(const std::string& filePath,
+                             const std::map<std::string, std::string>& fileMap)
+{
+  size_t count(0);
+  const std::string fileName = cmsys::SystemTools::GetFilenameName(filePath);
+  for (std::map<std::string, std::string>::const_iterator si = fileMap.begin();
+       si != fileMap.end(); ++si) {
+    if (cmsys::SystemTools::GetFilenameName(si->first) == fileName) {
+      ++count;
+      if (count > 1) {
+        return false;
+      }
+    }
+  }
+  return true;
+}
+
 cmQtAutoGenerators::cmQtAutoGenerators()
   : Verbose(cmsys::SystemTools::HasEnv("VERBOSE"))
   , ColorOutput(true)
@@ -1257,15 +1274,18 @@ bool cmQtAutoGenerators::GenerateQrcFiles()
 {
   // generate single map with input / output names
   std::map<std::string, std::string> qrcGenMap;
-  for (std::vector<std::string>::const_iterator si = this->RccSources.begin();
-       si != this->RccSources.end(); ++si) {
-    const std::string ext = cmsys::SystemTools::GetFilenameLastExtension(*si);
-    if (ext == ".qrc") {
-      std::string basename =
-        cmsys::SystemTools::GetFilenameWithoutLastExtension(*si);
-      std::string qrcOutputFile = "CMakeFiles/" + this->OriginTargetName +
-        ".dir/qrc_" + basename + ".cpp";
-      qrcGenMap[*si] = qrcOutputFile;
+  {
+    cmFilePathUuid fpathUuid(this->Srcdir, this->Builddir,
+                             this->ProjectSourceDir, this->ProjectBinaryDir);
+    for (std::vector<std::string>::const_iterator si =
+           this->RccSources.begin();
+         si != this->RccSources.end(); ++si) {
+      const std::string ext =
+        cmsys::SystemTools::GetFilenameLastExtension(*si);
+      if (ext == ".qrc") {
+        qrcGenMap[*si] =
+          (this->TargetBuildSubDir + fpathUuid.get(*si, "qrc_", ".cpp"));
+      }
     }
   }
 
@@ -1287,7 +1307,8 @@ bool cmQtAutoGenerators::GenerateQrcFiles()
   for (std::map<std::string, std::string>::const_iterator si =
          qrcGenMap.begin();
        si != qrcGenMap.end(); ++si) {
-    if (!this->GenerateQrc(si->first, si->second)) {
+    bool unique = FileNameIsUnique(si->first, qrcGenMap);
+    if (!this->GenerateQrc(si->first, si->second, unique)) {
       if (this->RunRccFailed) {
         return false;
       }
@@ -1297,10 +1318,23 @@ bool cmQtAutoGenerators::GenerateQrcFiles()
 }
 
 bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile,
-                                     const std::string& qrcOutputFile)
+                                     const std::string& qrcOutputFile,
+                                     bool unique_n)
 {
-  const std::string basename =
-    cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcInputFile);
+  std::string symbolName;
+  if (unique_n) {
+    symbolName =
+      cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcInputFile);
+  } else {
+    symbolName =
+      cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcOutputFile);
+    // Remove "qrc_" at string begin
+    symbolName.erase(0, 4);
+  }
+  // Replace '-' with '_'. The former is valid for
+  // file names but not for symbol names.
+  std::replace(symbolName.begin(), symbolName.end(), '-', '_');
+
   const std::string qrcBuildFile = this->Builddir + qrcOutputFile;
 
   int sourceNewerThanQrc = 0;
@@ -1327,7 +1361,7 @@ bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile,
     }
 
     command.push_back("-name");
-    command.push_back(basename);
+    command.push_back(symbolName);
     command.push_back("-o");
     command.push_back(qrcBuildFile);
     command.push_back(qrcInputFile);
diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h
index 216b0b0..fab2d19 100644
--- a/Source/cmQtAutoGenerators.h
+++ b/Source/cmQtAutoGenerators.h
@@ -51,7 +51,8 @@ private:
                   const std::string& uiOutputFile);
   bool GenerateQrcFiles();
   bool GenerateQrc(const std::string& qrcInputFile,
-                   const std::string& qrcOutputFile);
+                   const std::string& qrcOutputFile, bool unique_n);
+
   void ParseCppFile(
     const std::string& absFilename,
     const std::vector<std::string>& headerExtensions,

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=41c9e14afb0bc7e68e4530f76329b7c11cdfa0e4
commit 41c9e14afb0bc7e68e4530f76329b7c11cdfa0e4
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Sat Aug 6 13:33:46 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 13:21:33 2016 -0400

    QtAutogen: Allow multiple moc files with the same name
    
    Use cmFilePathUuid for moc files.
    
    Closes: #12873

diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index ea8db71..33f7a54 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -14,6 +14,7 @@
 #include "cmQtAutoGenerators.h"
 
 #include "cmAlgorithms.h"
+#include "cmFilePathUuid.h"
 #include "cmGlobalGenerator.h"
 #include "cmMakefile.h"
 #include "cmOutputConverter.h"
@@ -358,11 +359,13 @@ void cmQtAutoGenerators::WriteOldMocDefinitionsFile(
 
 void cmQtAutoGenerators::Init()
 {
+  this->TargetBuildSubDir = this->TargetName;
+  this->TargetBuildSubDir += ".dir/";
+
   this->OutMocCppFilenameRel = this->TargetName;
   this->OutMocCppFilenameRel += ".cpp";
 
-  this->OutMocCppFilename = this->Builddir;
-  this->OutMocCppFilename += this->OutMocCppFilenameRel;
+  this->OutMocCppFilenameAbs = this->Builddir + this->OutMocCppFilenameRel;
 
   std::vector<std::string> cdefList;
   cmSystemTools::ExpandListArgument(this->MocCompileDefinitionsStr, cdefList);
@@ -439,7 +442,7 @@ static std::string ReadAll(const std::string& filename)
 
 bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile)
 {
-  if (!cmsys::SystemTools::FileExists(this->OutMocCppFilename.c_str()) ||
+  if (!cmsys::SystemTools::FileExists(this->OutMocCppFilenameAbs.c_str()) ||
       (this->OldCompileSettingsStr != this->CurrentCompileSettingsStr)) {
     this->GenerateAll = true;
   }
@@ -933,6 +936,8 @@ void cmQtAutoGenerators::ParseHeaders(
   std::map<std::string, std::string>& notIncludedMocs,
   std::map<std::string, std::vector<std::string> >& includedUis)
 {
+  cmFilePathUuid fpathUuid(this->Srcdir, this->Builddir,
+                           this->ProjectSourceDir, this->ProjectBinaryDir);
   for (std::set<std::string>::const_iterator hIt = absHeaders.begin();
        hIt != absHeaders.end(); ++hIt) {
     const std::string& headerName = *hIt;
@@ -946,13 +951,10 @@ void cmQtAutoGenerators::ParseHeaders(
         this->LogInfo(err.str());
       }
 
-      const std::string basename =
-        cmsys::SystemTools::GetFilenameWithoutLastExtension(headerName);
-
-      const std::string currentMoc = "moc_" + basename + ".cpp";
       std::string macroName;
       if (requiresMocing(contents, macroName)) {
-        notIncludedMocs[headerName] = currentMoc;
+        notIncludedMocs[headerName] =
+          this->TargetBuildSubDir + fpathUuid.get(headerName, "moc_", ".cpp");
       }
     }
     this->ParseForUic(headerName, contents, includedUis);
@@ -1029,7 +1031,7 @@ bool cmQtAutoGenerators::GenerateMocFiles(
   // check if we even need to update _automoc.cpp
   if (!automocCppChanged) {
     // compare contents of the _automoc.cpp file
-    const std::string oldContents = ReadAll(this->OutMocCppFilename);
+    const std::string oldContents = ReadAll(this->OutMocCppFilenameAbs);
     if (oldContents == automocSource) {
       // nothing changed: don't touch the _automoc.cpp file
       if (this->Verbose) {
@@ -1052,7 +1054,7 @@ bool cmQtAutoGenerators::GenerateMocFiles(
   }
   {
     cmsys::ofstream outfile;
-    outfile.open(this->OutMocCppFilename.c_str(), std::ios::trunc);
+    outfile.open(this->OutMocCppFilenameAbs.c_str(), std::ios::trunc);
     outfile << automocSource;
     outfile.close();
   }
diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h
index 86913f0..216b0b0 100644
--- a/Source/cmQtAutoGenerators.h
+++ b/Source/cmQtAutoGenerators.h
@@ -123,8 +123,9 @@ private:
   std::string CurrentCompileSettingsStr;
   std::string OldCompileSettingsStr;
 
+  std::string TargetBuildSubDir;
   std::string OutMocCppFilenameRel;
-  std::string OutMocCppFilename;
+  std::string OutMocCppFilenameAbs;
   std::list<std::string> MocIncludes;
   std::list<std::string> MocDefinitions;
   std::vector<std::string> MocOptions;

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3c3b37b0bbd3fb78aa60a2b38184b6397d2ea47f
commit 3c3b37b0bbd3fb78aa60a2b38184b6397d2ea47f
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Sat Aug 6 14:05:23 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 13:21:33 2016 -0400

    QtAutogen: Use std:: instead of ::std::

diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index 174760f..ea8db71 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -1183,7 +1183,7 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName,
     cmsys::SystemTools::MakeDirectory(this->Builddir.c_str());
   }
 
-  const ::std::string uiBuildFile = this->Builddir + uiOutputFile;
+  const std::string uiBuildFile = this->Builddir + uiOutputFile;
 
   int sourceNewerThanUi = 0;
   bool success = cmsys::SystemTools::FileTimeCompare(uiInputFile, uiBuildFile,
@@ -1299,7 +1299,7 @@ bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile,
 {
   const std::string basename =
     cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcInputFile);
-  const ::std::string qrcBuildFile = this->Builddir + qrcOutputFile;
+  const std::string qrcBuildFile = this->Builddir + qrcOutputFile;
 
   int sourceNewerThanQrc = 0;
   bool generateQrc = !cmsys::SystemTools::FileTimeCompare(

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0a5dd3c700f1873be217707aa89a805d009bac3e
commit 0a5dd3c700f1873be217707aa89a805d009bac3e
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Sat Aug 6 13:09:59 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 13:21:33 2016 -0400

    cmFilePathUuid: Add class to generate deterministic unique file names
    
    The class generates a semi-unique (checksum based) pathless file name
    from a full source file path.

diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index a790994..cdc8fb1 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -238,6 +238,8 @@ set(SRCS
   cmFileLockPool.h
   cmFileLockResult.cxx
   cmFileLockResult.h
+  cmFilePathUuid.cxx
+  cmFilePathUuid.h
   cmFileTimeComparison.cxx
   cmFileTimeComparison.h
   cmFortranLexer.cxx
diff --git a/Source/cmFilePathUuid.cxx b/Source/cmFilePathUuid.cxx
new file mode 100644
index 0000000..2839b63
--- /dev/null
+++ b/Source/cmFilePathUuid.cxx
@@ -0,0 +1,132 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2016 Sebastian Holtermann (sebholt at xwmw.org)
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#include "cmFilePathUuid.h"
+
+#include "cmCryptoHash.h"
+#include "cmMakefile.h"
+#include "cmSystemTools.h"
+#include "cmsys/Base64.h"
+
+cmFilePathUuid::cmFilePathUuid(cmMakefile* makefile)
+{
+  initParentDirs(makefile->GetCurrentSourceDirectory(),
+                 makefile->GetCurrentBinaryDirectory(),
+                 makefile->GetHomeDirectory(),
+                 makefile->GetHomeOutputDirectory());
+}
+
+cmFilePathUuid::cmFilePathUuid(const std::string& currentSrcDir,
+                               const std::string& currentBinDir,
+                               const std::string& projectSrcDir,
+                               const std::string& projectBinDir)
+{
+  initParentDirs(currentSrcDir, currentBinDir, projectSrcDir, projectBinDir);
+}
+
+void cmFilePathUuid::initParentDirs(const std::string& currentSrcDir,
+                                    const std::string& currentBinDir,
+                                    const std::string& projectSrcDir,
+                                    const std::string& projectBinDir)
+{
+  parentDirs[0].first = cmsys::SystemTools::GetRealPath(currentSrcDir);
+  parentDirs[1].first = cmsys::SystemTools::GetRealPath(currentBinDir);
+  parentDirs[2].first = cmsys::SystemTools::GetRealPath(projectSrcDir);
+  parentDirs[3].first = cmsys::SystemTools::GetRealPath(projectBinDir);
+
+  parentDirs[0].second = "CurrentSource";
+  parentDirs[1].second = "CurrentBinary";
+  parentDirs[2].second = "ProjectSource";
+  parentDirs[3].second = "ProjectBinary";
+}
+
+std::string cmFilePathUuid::get(const std::string& filePath,
+                                const char* outputPrefix,
+                                const char* outputSuffix)
+{
+  std::string sourceFilename = cmsys::SystemTools::GetFilenameName(filePath);
+  std::string sourceBasename =
+    cmsys::SystemTools::GetFilenameWithoutLastExtension(sourceFilename);
+
+  // Acquire checksum string
+  std::string checksum;
+  {
+    std::string sourceRelPath;
+    std::string sourceRelSeed;
+    GetRelPathSeed(filePath, sourceRelPath, sourceRelSeed);
+    checksum = GetChecksumString(sourceFilename, sourceRelPath, sourceRelSeed);
+  }
+
+  // Compose the file name
+  std::string uuid;
+  if (outputPrefix) {
+    uuid += outputPrefix;
+  }
+  uuid += sourceBasename.substr(0, partLengthName);
+  uuid += "_";
+  uuid += checksum.substr(0, partLengthCheckSum);
+  if (outputSuffix) {
+    uuid += outputSuffix;
+  }
+  return uuid;
+}
+
+void cmFilePathUuid::GetRelPathSeed(const std::string& filePath,
+                                    std::string& sourceRelPath,
+                                    std::string& sourceRelSeed)
+{
+  const std::string sourceNameReal = cmsys::SystemTools::GetRealPath(filePath);
+  std::string parentDirectory;
+  // Find closest project parent directory
+  for (size_t ii = 0; ii != numParentDirs; ++ii) {
+    const std::string& pDir = parentDirs[ii].first;
+    if (!pDir.empty() &&
+        cmsys::SystemTools::IsSubDirectory(sourceNameReal, pDir)) {
+      sourceRelSeed = parentDirs[ii].second;
+      parentDirectory = pDir;
+      break;
+    }
+  }
+  // Check if the file path is below a known project directory
+  if (parentDirectory.empty()) {
+    // Use file syste root as fallback parent directory
+    sourceRelSeed = "FileSystemRoot";
+    cmsys::SystemTools::SplitPathRootComponent(sourceNameReal,
+                                               &parentDirectory);
+  }
+  sourceRelPath = cmsys::SystemTools::RelativePath(
+    parentDirectory, cmsys::SystemTools::GetParentDirectory(sourceNameReal));
+}
+
+std::string cmFilePathUuid::GetChecksumString(
+  const std::string& sourceFilename, const std::string& sourceRelPath,
+  const std::string& sourceRelSeed)
+{
+  std::string checksumBase64;
+  {
+    // Calculate the file ( seed + relative path + name ) checksum
+    std::vector<unsigned char> hashBytes =
+      cmCryptoHash::New("SHA256")->ByteHashString(
+        (sourceRelSeed + sourceRelPath + sourceFilename).c_str());
+    // Convert hash bytes to Base64 text string
+    std::vector<unsigned char> base64Bytes(hashBytes.size() * 2, 0);
+    cmsysBase64_Encode(&hashBytes[0], hashBytes.size(), &base64Bytes[0], 0);
+    checksumBase64 = reinterpret_cast<const char*>(&base64Bytes[0]);
+  }
+  // Base64 allows '/', '+' and '=' characters which are problematic
+  // when used in file names. Replace them with safer alternatives.
+  std::replace(checksumBase64.begin(), checksumBase64.end(), '/', '-');
+  std::replace(checksumBase64.begin(), checksumBase64.end(), '+', '_');
+  std::replace(checksumBase64.begin(), checksumBase64.end(), '=', '_');
+
+  return checksumBase64;
+}
diff --git a/Source/cmFilePathUuid.h b/Source/cmFilePathUuid.h
new file mode 100644
index 0000000..42e89b1
--- /dev/null
+++ b/Source/cmFilePathUuid.h
@@ -0,0 +1,77 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2016 Sebastian Holtermann (sebholt at xwmw.org)
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#ifndef cmFilePathUuid_h
+#define cmFilePathUuid_h
+
+#include "cmStandardIncludes.h"
+
+#include <string>
+#include <utility>
+
+class cmMakefile;
+
+/** \class cmFilePathUuid
+ * @brief Generates a unique pathless file name with a checksum component
+ *        calculated from the file path.
+ *
+ * The checksum is calculated from the relative file path to the
+ * closest known project directory. This guarantees reproducibility
+ * when source and build directory differ e.g. for different project
+ * build directories.
+ */
+class cmFilePathUuid
+{
+public:
+  /// Maximum number of characters to use from the file name
+  static const size_t partLengthName = 14;
+  /// Maximum number of characters to use from the path checksum
+  static const size_t partLengthCheckSum = 14;
+
+  /// @brief Initilizes the parent directories from a makefile
+  cmFilePathUuid(cmMakefile* makefile);
+
+  /// @brief Initilizes the parent directories manually
+  cmFilePathUuid(const std::string& currentSrcDir,
+                 const std::string& currentBinDir,
+                 const std::string& projectSrcDir,
+                 const std::string& projectBinDir);
+
+  /* @brief Calculates and returns the uuid for a file path
+   *
+   * @arg outputPrefix optional string to prepend to the result
+   * @arg outputSuffix optional string to append to the result
+   */
+  std::string get(const std::string& filePath, const char* outputPrefix = NULL,
+                  const char* outputSuffix = NULL);
+
+private:
+  void initParentDirs(const std::string& currentSrcDir,
+                      const std::string& currentBinDir,
+                      const std::string& projectSrcDir,
+                      const std::string& projectBinDir);
+
+  /// Returns the relative path and the parent directory key string (seed)
+  void GetRelPathSeed(const std::string& filePath, std::string& sourceRelPath,
+                      std::string& sourceRelSeed);
+
+  std::string GetChecksumString(const std::string& sourceFilename,
+                                const std::string& sourceRelPath,
+                                const std::string& sourceRelSeed);
+
+  /// Size of the parent directory list
+  static const size_t numParentDirs = 4;
+  /// List of (directory name, seed name) pairs
+  std::pair<std::string, std::string> parentDirs[numParentDirs];
+};
+
+#endif

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3a5f609cbb4ae63fca1eb87918767a4296d16e5f
commit 3a5f609cbb4ae63fca1eb87918767a4296d16e5f
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Wed Aug 10 11:30:06 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 13:21:32 2016 -0400

    cmCryptoHash: New ByteHash methods that return a byte vector

diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index 8d96421..9bd07a3 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -65,43 +65,57 @@ std::string cmCryptoHash::ByteHashToString(
   return res;
 }
 
-std::string cmCryptoHash::HashString(const std::string& input)
+std::vector<unsigned char> cmCryptoHash::ByteHashString(
+  const std::string& input)
 {
   this->Initialize();
   this->Append(reinterpret_cast<unsigned char const*>(input.c_str()),
                static_cast<int>(input.size()));
-  return ByteHashToString(this->Finalize());
+  return this->Finalize();
 }
 
-std::string cmCryptoHash::HashFile(const std::string& file)
+std::vector<unsigned char> cmCryptoHash::ByteHashFile(const std::string& file)
 {
   cmsys::ifstream fin(file.c_str(), std::ios::in | std::ios::binary);
-  if (!fin) {
-    return "";
+  if (fin) {
+    this->Initialize();
+    {
+      // Should be efficient enough on most system:
+      cm_sha2_uint64_t buffer[512];
+      char* buffer_c = reinterpret_cast<char*>(buffer);
+      unsigned char const* buffer_uc =
+        reinterpret_cast<unsigned char const*>(buffer);
+      // This copy loop is very sensitive on certain platforms with
+      // slightly broken stream libraries (like HPUX).  Normally, it is
+      // incorrect to not check the error condition on the fin.read()
+      // before using the data, but the fin.gcount() will be zero if an
+      // error occurred.  Therefore, the loop should be safe everywhere.
+      while (fin) {
+        fin.read(buffer_c, sizeof(buffer));
+        if (int gcount = static_cast<int>(fin.gcount())) {
+          this->Append(buffer_uc, gcount);
+        }
+      }
+    }
+    if (fin.eof()) {
+      // Success
+      return this->Finalize();
+    }
+    // Finalize anyway
+    this->Finalize();
   }
+  // Return without success
+  return std::vector<unsigned char>();
+}
 
-  this->Initialize();
+std::string cmCryptoHash::HashString(const std::string& input)
+{
+  return ByteHashToString(this->ByteHashString(input));
+}
 
-  // Should be efficient enough on most system:
-  cm_sha2_uint64_t buffer[512];
-  char* buffer_c = reinterpret_cast<char*>(buffer);
-  unsigned char const* buffer_uc =
-    reinterpret_cast<unsigned char const*>(buffer);
-  // This copy loop is very sensitive on certain platforms with
-  // slightly broken stream libraries (like HPUX).  Normally, it is
-  // incorrect to not check the error condition on the fin.read()
-  // before using the data, but the fin.gcount() will be zero if an
-  // error occurred.  Therefore, the loop should be safe everywhere.
-  while (fin) {
-    fin.read(buffer_c, sizeof(buffer));
-    if (int gcount = static_cast<int>(fin.gcount())) {
-      this->Append(buffer_uc, gcount);
-    }
-  }
-  if (fin.eof()) {
-    return ByteHashToString(this->Finalize());
-  }
-  return "";
+std::string cmCryptoHash::HashFile(const std::string& file)
+{
+  return ByteHashToString(this->ByteHashFile(file));
 }
 
 cmCryptoHashMD5::cmCryptoHashMD5()
diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index ab50e82..4e92b06 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -23,22 +23,37 @@ class cmCryptoHash
 {
 public:
   virtual ~cmCryptoHash() {}
+
   /// @brief Returns a new hash generator of the requested type
   /// @arg algo Hash type name. Supported hash types are
   ///      MD5, SHA1, SHA224, SHA256, SHA384, SHA512
   /// @return A valid auto pointer if algo is supported or
   ///         an invalid/NULL pointer otherwise
   static CM_AUTO_PTR<cmCryptoHash> New(const char* algo);
+
   /// @brief Converts a hex character to its binary value (4 bits)
   /// @arg input Hex character [0-9a-fA-F].
   /// @arg output Binary value of the input character (4 bits)
   /// @return True if input was a valid hex character
   static bool IntFromHexDigit(char input, char& output);
+
   /// @brief Converts a byte hash to a sequence of hex character pairs
   static std::string ByteHashToString(const std::vector<unsigned char>& hash);
+
+  /// @brief Calculates a binary hash from string input data
+  /// @return Binary hash vector
+  std::vector<unsigned char> ByteHashString(const std::string& input);
+
+  /// @brief Calculates a binary hash from file content
+  /// @see ByteHashString()
+  /// @return Non empty binary hash vector if the file was read successfully.
+  ///         An empty vector otherwise.
+  std::vector<unsigned char> ByteHashFile(const std::string& file);
+
   /// @brief Calculates a hash string from string input data
   /// @return Sequence of hex characters pairs for each byte of the binary hash
   std::string HashString(const std::string& input);
+
   /// @brief Calculates a hash string from file content
   /// @see HashString()
   /// @return Non empty hash string if the file was read successfully.

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f582dba6664e5ea814f3b33c71ae4d83db17b996
commit f582dba6664e5ea814f3b33c71ae4d83db17b996
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Wed Aug 10 11:08:15 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 13:21:32 2016 -0400

    cmCryptoHash: Return byte vector from internal Finalize method
    
    Some callers may want the raw byte vector instead of the hex character
    string.  Convert the internal implementation to use this so that we
    can later add public APIs to get it.

diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index 59b9abd..8d96421 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -70,7 +70,7 @@ std::string cmCryptoHash::HashString(const std::string& input)
   this->Initialize();
   this->Append(reinterpret_cast<unsigned char const*>(input.c_str()),
                static_cast<int>(input.size()));
-  return this->Finalize();
+  return ByteHashToString(this->Finalize());
 }
 
 std::string cmCryptoHash::HashFile(const std::string& file)
@@ -99,7 +99,7 @@ std::string cmCryptoHash::HashFile(const std::string& file)
     }
   }
   if (fin.eof()) {
-    return this->Finalize();
+    return ByteHashToString(this->Finalize());
   }
   return "";
 }
@@ -124,11 +124,11 @@ void cmCryptoHashMD5::Append(unsigned char const* buf, int sz)
   cmsysMD5_Append(this->MD5, buf, sz);
 }
 
-std::string cmCryptoHashMD5::Finalize()
+std::vector<unsigned char> cmCryptoHashMD5::Finalize()
 {
-  char md5out[32];
-  cmsysMD5_FinalizeHex(this->MD5, md5out);
-  return std::string(md5out, 32);
+  std::vector<unsigned char> hash(16, 0);
+  cmsysMD5_Finalize(this->MD5, &hash[0]);
+  return hash;
 }
 
 #define cmCryptoHash_SHA_CLASS_IMPL(SHA)                                      \
@@ -142,11 +142,11 @@ std::string cmCryptoHashMD5::Finalize()
   {                                                                           \
     SHA##_Update(this->SHA, buf, sz);                                         \
   }                                                                           \
-  std::string cmCryptoHash##SHA::Finalize()                                   \
+  std::vector<unsigned char> cmCryptoHash##SHA::Finalize()                    \
   {                                                                           \
-    char out[SHA##_DIGEST_STRING_LENGTH];                                     \
-    SHA##_End(this->SHA, out);                                                \
-    return std::string(out, SHA##_DIGEST_STRING_LENGTH - 1);                  \
+    std::vector<unsigned char> hash(SHA##_DIGEST_LENGTH, 0);                  \
+    SHA##_Final(&hash[0], this->SHA);                                         \
+    return hash;                                                              \
   }
 
 cmCryptoHash_SHA_CLASS_IMPL(SHA1) cmCryptoHash_SHA_CLASS_IMPL(SHA224)
diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index 80ab269..ab50e82 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -48,7 +48,7 @@ public:
 protected:
   virtual void Initialize() = 0;
   virtual void Append(unsigned char const*, int) = 0;
-  virtual std::string Finalize() = 0;
+  virtual std::vector<unsigned char> Finalize() = 0;
 };
 
 class cmCryptoHashMD5 : public cmCryptoHash
@@ -62,7 +62,7 @@ public:
 protected:
   void Initialize() CM_OVERRIDE;
   void Append(unsigned char const* buf, int sz) CM_OVERRIDE;
-  std::string Finalize() CM_OVERRIDE;
+  std::vector<unsigned char> Finalize() CM_OVERRIDE;
 };
 
 #define cmCryptoHash_SHA_CLASS_DECL(SHA)                                      \
@@ -77,7 +77,7 @@ protected:
   protected:                                                                  \
     virtual void Initialize();                                                \
     virtual void Append(unsigned char const* buf, int sz);                    \
-    virtual std::string Finalize();                                           \
+    virtual std::vector<unsigned char> Finalize();                            \
   }
 
 cmCryptoHash_SHA_CLASS_DECL(SHA1);

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=74f0d4abcd8de84283858fe144772e688669e46a
commit 74f0d4abcd8de84283858fe144772e688669e46a
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Wed Aug 10 10:35:19 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 13:09:55 2016 -0400

    cmCryptoHash: New byte hash to string function

diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index 8d60c1f..59b9abd 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -34,6 +34,37 @@ CM_AUTO_PTR<cmCryptoHash> cmCryptoHash::New(const char* algo)
   }
 }
 
+bool cmCryptoHash::IntFromHexDigit(char input, char& output)
+{
+  if (input >= '0' && input <= '9') {
+    output = char(input - '0');
+    return true;
+  } else if (input >= 'a' && input <= 'f') {
+    output = char(input - 'a' + 0xA);
+    return true;
+  } else if (input >= 'A' && input <= 'F') {
+    output = char(input - 'A' + 0xA);
+    return true;
+  }
+  return false;
+}
+
+std::string cmCryptoHash::ByteHashToString(
+  const std::vector<unsigned char>& hash)
+{
+  // Map from 4-bit index to hexadecimal representation.
+  static char const hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
+                                '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+
+  std::string res;
+  for (std::vector<unsigned char>::const_iterator vit = hash.begin();
+       vit != hash.end(); ++vit) {
+    res.push_back(hex[(*vit) >> 4]);
+    res.push_back(hex[(*vit) & 0xF]);
+  }
+  return res;
+}
+
 std::string cmCryptoHash::HashString(const std::string& input)
 {
   this->Initialize();
diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index 84dea9b..80ab269 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -29,6 +29,13 @@ public:
   /// @return A valid auto pointer if algo is supported or
   ///         an invalid/NULL pointer otherwise
   static CM_AUTO_PTR<cmCryptoHash> New(const char* algo);
+  /// @brief Converts a hex character to its binary value (4 bits)
+  /// @arg input Hex character [0-9a-fA-F].
+  /// @arg output Binary value of the input character (4 bits)
+  /// @return True if input was a valid hex character
+  static bool IntFromHexDigit(char input, char& output);
+  /// @brief Converts a byte hash to a sequence of hex character pairs
+  static std::string ByteHashToString(const std::vector<unsigned char>& hash);
   /// @brief Calculates a hash string from string input data
   /// @return Sequence of hex characters pairs for each byte of the binary hash
   std::string HashString(const std::string& input);

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=94c29976d0020b48a5c565234b71f8f6abaf08be
commit 94c29976d0020b48a5c565234b71f8f6abaf08be
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Wed Aug 10 09:54:49 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 13:09:54 2016 -0400

    cmCryptoHash: Documentation comments

diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index 6aaaf93..84dea9b 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -16,12 +16,26 @@
 
 #include <cm_auto_ptr.hxx>
 
+/**
+ * @brief Abstract base class for cryptographic hash generators
+ */
 class cmCryptoHash
 {
 public:
   virtual ~cmCryptoHash() {}
+  /// @brief Returns a new hash generator of the requested type
+  /// @arg algo Hash type name. Supported hash types are
+  ///      MD5, SHA1, SHA224, SHA256, SHA384, SHA512
+  /// @return A valid auto pointer if algo is supported or
+  ///         an invalid/NULL pointer otherwise
   static CM_AUTO_PTR<cmCryptoHash> New(const char* algo);
+  /// @brief Calculates a hash string from string input data
+  /// @return Sequence of hex characters pairs for each byte of the binary hash
   std::string HashString(const std::string& input);
+  /// @brief Calculates a hash string from file content
+  /// @see HashString()
+  /// @return Non empty hash string if the file was read successfully.
+  ///         An empty string otherwise.
   std::string HashFile(const std::string& file);
 
 protected:

-----------------------------------------------------------------------

Summary of changes:


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list