From 6c632cd7205ed61fb629f8adbcf55ede782a35a0 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:39:05 +0200
Subject: [PATCH 2/3] added support for custom WIX namespaces in generated .wxs
 files: CPACK_WIX_NAMESPACES

---
 Source/CPack/WiX/cmCPackWIXGenerator.cxx          | 16 +++++++++++-----
 Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx |  5 +++--
 Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h   |  4 ++--
 Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx    |  5 +++--
 Source/CPack/WiX/cmWIXFeaturesSourceWriter.h      |  3 ++-
 Source/CPack/WiX/cmWIXFilesSourceWriter.cxx       |  5 +++--
 Source/CPack/WiX/cmWIXFilesSourceWriter.h         |  3 ++-
 Source/CPack/WiX/cmWIXSourceWriter.cxx            | 12 +++++++++++-
 Source/CPack/WiX/cmWIXSourceWriter.h              |  3 ++-
 9 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
index de3dc62..5a979b1 100644
--- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
@@ -417,13 +417,19 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles()
   // component guid "*" cannot be used
   cmWIXSourceWriter::GenerateComponentGuids =
     cmSystemTools::IsOn(GetOption("CPACK_WIX_SKIP_PROGRAM_FOLDER"));
+
+  std::string wixnamespaces;
+  if (const char* ns = GetOption("CPACK_WIX_NAMESPACES")) {
+    wixnamespaces = ns;
+  }
+
   std::string directoryDefinitionsFilename =
     this->CPackTopLevel + "/directories.wxs";
 
   this->WixSources.push_back(directoryDefinitionsFilename);
 
   cmWIXDirectoriesSourceWriter directoryDefinitions(
-    this->Logger, directoryDefinitionsFilename);
+    this->Logger, directoryDefinitionsFilename, wixnamespaces);
   directoryDefinitions.BeginElement("Fragment");
 
   std::string installRoot;
@@ -443,8 +449,8 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles()
 
   this->WixSources.push_back(fileDefinitionsFilename);
 
-  cmWIXFilesSourceWriter fileDefinitions(this->Logger,
-                                         fileDefinitionsFilename);
+  cmWIXFilesSourceWriter fileDefinitions(this->Logger, fileDefinitionsFilename,
+                                         wixnamespaces);
 
   // if install folder is supposed to be set absolutely, the default
   // component guid "*" cannot be used
@@ -458,8 +464,8 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles()
 
   this->WixSources.push_back(featureDefinitionsFilename);
 
-  cmWIXFeaturesSourceWriter featureDefinitions(this->Logger,
-                                               featureDefinitionsFilename);
+  cmWIXFeaturesSourceWriter featureDefinitions(
+    this->Logger, featureDefinitionsFilename, wixnamespaces);
 
   featureDefinitions.BeginElement("Fragment");
 
diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx
index 97e3a51..979c0fc 100644
--- a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.cxx
@@ -13,8 +13,9 @@
 #include "cmWIXDirectoriesSourceWriter.h"
 
 cmWIXDirectoriesSourceWriter::cmWIXDirectoriesSourceWriter(
-  cmCPackLog* logger, std::string const& filename)
-  : cmWIXSourceWriter(logger, filename)
+  cmCPackLog* logger, std::string const& filename,
+  std::string const& namespaces)
+  : cmWIXSourceWriter(logger, filename, false, namespaces)
 {
 }
 
diff --git a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h
index 023f4b8..71b791b 100644
--- a/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h
+++ b/Source/CPack/WiX/cmWIXDirectoriesSourceWriter.h
@@ -25,8 +25,8 @@
 class cmWIXDirectoriesSourceWriter : public cmWIXSourceWriter
 {
 public:
-  cmWIXDirectoriesSourceWriter(cmCPackLog* logger,
-                               std::string const& filename);
+  cmWIXDirectoriesSourceWriter(cmCPackLog* logger, std::string const& filename,
+                               std::string const& namespaces = "");
 
   void EmitStartMenuFolder(std::string const& startMenuFolder);
 
diff --git a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx
index ef1571c..d615450 100644
--- a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx
@@ -13,8 +13,9 @@
 #include "cmWIXFeaturesSourceWriter.h"
 
 cmWIXFeaturesSourceWriter::cmWIXFeaturesSourceWriter(
-  cmCPackLog* logger, std::string const& filename)
-  : cmWIXSourceWriter(logger, filename)
+  cmCPackLog* logger, std::string const& filename,
+  std::string const& namespaces)
+  : cmWIXSourceWriter(logger, filename, false, namespaces)
 {
 }
 
diff --git a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h
index ee9c17a..eb90e5f 100644
--- a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h
+++ b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.h
@@ -23,7 +23,8 @@
 class cmWIXFeaturesSourceWriter : public cmWIXSourceWriter
 {
 public:
-  cmWIXFeaturesSourceWriter(cmCPackLog* logger, std::string const& filename);
+  cmWIXFeaturesSourceWriter(cmCPackLog* logger, std::string const& filename,
+                            std::string const& namespaces = "");
 
   void CreateCMakePackageRegistryEntry(std::string const& package,
                                        std::string const& upgradeGuid);
diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
index 44765de..6829bba 100644
--- a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
@@ -24,8 +24,9 @@
 #include <sys/stat.h>
 
 cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(cmCPackLog* logger,
-                                               std::string const& filename)
-  : cmWIXSourceWriter(logger, filename)
+                                               std::string const& filename,
+                                               std::string const& namespaces)
+  : cmWIXSourceWriter(logger, filename, false, namespaces)
   , GenerateComponentGuids(false)
 {
 }
diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.h b/Source/CPack/WiX/cmWIXFilesSourceWriter.h
index eeb84cb..06c3173 100644
--- a/Source/CPack/WiX/cmWIXFilesSourceWriter.h
+++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.h
@@ -26,7 +26,8 @@
 class cmWIXFilesSourceWriter : public cmWIXSourceWriter
 {
 public:
-  cmWIXFilesSourceWriter(cmCPackLog* logger, std::string const& filename);
+  cmWIXFilesSourceWriter(cmCPackLog* logger, std::string const& filename,
+                         std::string const& namespaces = "");
 
   void EmitShortcut(std::string const& id, cmWIXShortcut const& shortcut,
                     std::string const& shortcutPrefix, size_t shortcutIndex);
diff --git a/Source/CPack/WiX/cmWIXSourceWriter.cxx b/Source/CPack/WiX/cmWIXSourceWriter.cxx
index 27d9854..77898fe 100644
--- a/Source/CPack/WiX/cmWIXSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXSourceWriter.cxx
@@ -22,7 +22,8 @@ bool cmWIXSourceWriter::GenerateComponentGuids(false);
 
 cmWIXSourceWriter::cmWIXSourceWriter(cmCPackLog* logger,
                                      std::string const& filename,
-                                     bool isIncludeFile)
+                                     bool isIncludeFile,
+                                     std::string const& namespaces)
   : Logger(logger)
   , File(filename.c_str())
   , State(DEFAULT)
@@ -37,6 +38,15 @@ cmWIXSourceWriter::cmWIXSourceWriter(cmCPackLog* logger,
   }
 
   AddAttribute("xmlns", "http://schemas.microsoft.com/wix/2006/wi");
+  std::vector<std::string> namespacesList;
+  if (!namespaces.empty()) {
+    cmSystemTools::ExpandListArgument(namespaces, namespacesList);
+    if (namespacesList.size() % 2 == 0) {
+      for (unsigned int j = 0; j < namespacesList.size(); j = j + 2) {
+        AddAttribute(namespacesList[j], namespacesList[j + 1]);
+      }
+    }
+  }
 }
 
 cmWIXSourceWriter::~cmWIXSourceWriter()
diff --git a/Source/CPack/WiX/cmWIXSourceWriter.h b/Source/CPack/WiX/cmWIXSourceWriter.h
index 0300820..e450a46 100644
--- a/Source/CPack/WiX/cmWIXSourceWriter.h
+++ b/Source/CPack/WiX/cmWIXSourceWriter.h
@@ -27,7 +27,8 @@ class cmWIXSourceWriter
 {
 public:
   cmWIXSourceWriter(cmCPackLog* logger, std::string const& filename,
-                    bool isIncludeFile = false);
+                    bool isIncludeFile = false,
+                    std::string const& namespaces = "");
 
   ~cmWIXSourceWriter();
 
-- 
2.8.0.windows.1

