From 461a99b1d58f5a264fa9a1536f2302b8e6a50f7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20St=C3=BCrmer?= <michael.stuermer@schaeffler.com>
Date: Tue, 6 Sep 2016 12:11:00 +0200
Subject: [PATCH 1/3] fixed setting of invalid "*" guids in WIX source files if
 CPACK_WIX_SKIP_PROGRAM_FOLDER is active

---
 Source/CPack/WiX/cmCPackWIXGenerator.cxx       |  7 ++++++-
 Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx |  3 ++-
 Source/CPack/WiX/cmWIXFilesSourceWriter.cxx    |  8 +-------
 Source/CPack/WiX/cmWIXSourceWriter.cxx         | 17 +++++++++++++++++
 Source/CPack/WiX/cmWIXSourceWriter.h           |  4 ++++
 5 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
index d7f69a1..de3dc62 100644
--- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
@@ -413,6 +413,10 @@ void cmCPackWIXGenerator::AddDefinition(cmWIXSourceWriter& source,
 
 bool cmCPackWIXGenerator::CreateWiXSourceFiles()
 {
+  // if install folder is supposed to be set absolutely, the default
+  // component guid "*" cannot be used
+  cmWIXSourceWriter::GenerateComponentGuids =
+    cmSystemTools::IsOn(GetOption("CPACK_WIX_SKIP_PROGRAM_FOLDER"));
   std::string directoryDefinitionsFilename =
     this->CPackTopLevel + "/directories.wxs";
 
@@ -764,7 +768,8 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType(
 
   fileDefinitions.BeginElement("Component");
   fileDefinitions.AddAttribute("Id", componentId);
-  fileDefinitions.AddAttribute("Guid", "*");
+  fileDefinitions.AddAttribute(
+    "Guid", cmWIXSourceWriter::GetGuidFromComponentId(componentId));
 
   this->Patch->ApplyFragment(componentId, fileDefinitions);
 
diff --git a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx
index 1747b62..ef1571c 100644
--- a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx
@@ -24,7 +24,8 @@ void cmWIXFeaturesSourceWriter::CreateCMakePackageRegistryEntry(
   BeginElement("Component");
   AddAttribute("Id", "CM_PACKAGE_REGISTRY");
   AddAttribute("Directory", "TARGETDIR");
-  AddAttribute("Guid", "*");
+  AddAttribute(
+    "Guid", cmWIXSourceWriter::GetGuidFromComponentId("CM_PACKAGE_REGISTRY"));
 
   std::string registryKey =
     std::string("Software\\Kitware\\CMake\\Packages\\") + package;
diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
index dde9635..44765de 100644
--- a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
@@ -130,13 +130,7 @@ std::string cmWIXFilesSourceWriter::EmitComponentFile(
   std::string componentId = std::string("CM_C") + id;
   std::string fileId = std::string("CM_F") + id;
 
-  std::string guid = "*";
-  if (this->GenerateComponentGuids) {
-    std::string md5 = cmSystemTools::ComputeStringMD5(componentId);
-    cmUuid uuid;
-    std::vector<unsigned char> ns;
-    guid = uuid.FromMd5(ns, md5);
-  }
+  std::string guid = cmWIXSourceWriter::GetGuidFromComponentId(componentId);
 
   BeginElement("DirectoryRef");
   AddAttribute("Id", directoryId);
diff --git a/Source/CPack/WiX/cmWIXSourceWriter.cxx b/Source/CPack/WiX/cmWIXSourceWriter.cxx
index 2c0384e..27d9854 100644
--- a/Source/CPack/WiX/cmWIXSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXSourceWriter.cxx
@@ -14,8 +14,12 @@
 
 #include <CPack/cmCPackGenerator.h>
 
+#include <cmUuid.h>
+
 #include <windows.h>
 
+bool cmWIXSourceWriter::GenerateComponentGuids(false);
+
 cmWIXSourceWriter::cmWIXSourceWriter(cmCPackLog* logger,
                                      std::string const& filename,
                                      bool isIncludeFile)
@@ -173,6 +177,19 @@ std::string cmWIXSourceWriter::CMakeEncodingToUtf8(std::string const& value)
 #endif
 }
 
+std::string cmWIXSourceWriter::GetGuidFromComponentId(
+  std::string const& componentId)
+{
+  std::string guid = "*";
+  if (cmWIXSourceWriter::GenerateComponentGuids) {
+    std::string md5 = cmSystemTools::ComputeStringMD5(componentId);
+    cmUuid uuid;
+    std::vector<unsigned char> ns;
+    guid = uuid.FromMd5(ns, md5);
+  }
+  return guid;
+}
+
 void cmWIXSourceWriter::WriteXMLDeclaration()
 {
   File << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
diff --git a/Source/CPack/WiX/cmWIXSourceWriter.h b/Source/CPack/WiX/cmWIXSourceWriter.h
index 4efc026..0300820 100644
--- a/Source/CPack/WiX/cmWIXSourceWriter.h
+++ b/Source/CPack/WiX/cmWIXSourceWriter.h
@@ -47,6 +47,10 @@ public:
 
   static std::string CMakeEncodingToUtf8(std::string const& value);
 
+  static std::string GetGuidFromComponentId(std::string const& componentId);
+
+  static bool GenerateComponentGuids;
+
 protected:
   cmCPackLog* Logger;
 
-- 
2.8.0.windows.1

