From 3cab24a9740ad1d35e548629f6dda12e166ef49e Mon Sep 17 00:00:00 2001
From: Daniel Nelson <torham@connect2.com>
Date: Fri, 13 Jan 2012 22:01:53 +0100
Subject: CPack  Add top level directory in component install for Archive
 Generators

This patch fixes bug #0012129
Signed-off-by: Eric NOULARD <eric.noulard@gmail.com>
---
 Source/CPack/cmCPackArchiveGenerator.cxx | 11 +++++++++--
 Source/CPack/cmCPackGenerator.cxx        |  5 +++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx
index 0ce5b01..12d1796 100644
--- a/Source/CPack/cmCPackArchiveGenerator.cxx
+++ b/Source/CPack/cmCPackArchiveGenerator.cxx
@@ -57,13 +57,20 @@ int cmCPackArchiveGenerator::addOneComponentToArchive(cmArchiveWrite& archive,
   std::string dir = cmSystemTools::GetCurrentWorkingDirectory();
   // Change to local toplevel
   cmSystemTools::ChangeDirectory(localToplevel.c_str());
+  std::string filePrefix;
+  if (this->IsOn("CPACK_INCLUDE_TOPLEVEL_DIRECTORY"))
+    {
+    filePrefix = this->GetOption("CPACK_PACKAGE_FILE_NAME");
+    filePrefix += "/";
+    }
   std::vector<std::string>::const_iterator fileIt;
   for (fileIt = component->Files.begin(); fileIt != component->Files.end();
        ++fileIt )
     {
+    std::string rp = filePrefix + *fileIt;
     cmCPackLogger(cmCPackLog::LOG_DEBUG,"Adding file: "
-                  << (*fileIt) << std::endl);
-    archive.Add(*fileIt);
+                  << rp << std::endl);
+    archive.Add(rp);
     if (!archive)
       {
       cmCPackLogger(cmCPackLog::LOG_ERROR, "ERROR while packaging files: "
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
index 083279f..01ed4df 100644
--- a/Source/CPack/cmCPackGenerator.cxx
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -691,6 +691,11 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
           //  one install directory for each component.
           tempInstallDirectory +=
             GetComponentInstallDirNameSuffix(installComponent);
+          if (this->IsOn("CPACK_INCLUDE_TOPLEVEL_DIRECTORY"))
+            {
+            tempInstallDirectory += "/";
+            tempInstallDirectory += this->GetOption("CPACK_PACKAGE_FILE_NAME");
+            }
           }
 
         if (!setDestDir)
-- 
cgit v0.12


From 5d18851b25af4f363d72371a5a6492741436eb37 Mon Sep 17 00:00:00 2001
From: Eric NOULARD <eric.noulard@gmail.com>
Date: Wed, 1 Feb 2012 23:32:50 +0100
Subject: CPackArchive restore default behavior and provide new variable.

CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY should be set by the user
in order to get the toplevel directory included in the archive
whenever a componentized archive is requested. This solves bug #12129
and keeps fully backward compatible behavior.
---
 Source/CPack/cmCPackArchiveGenerator.cxx | 2 +-
 Source/CPack/cmCPackGenerator.cxx        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx
index 12d1796..0ff9050 100644
--- a/Source/CPack/cmCPackArchiveGenerator.cxx
+++ b/Source/CPack/cmCPackArchiveGenerator.cxx
@@ -58,7 +58,7 @@ int cmCPackArchiveGenerator::addOneComponentToArchive(cmArchiveWrite& archive,
   // Change to local toplevel
   cmSystemTools::ChangeDirectory(localToplevel.c_str());
   std::string filePrefix;
-  if (this->IsOn("CPACK_INCLUDE_TOPLEVEL_DIRECTORY"))
+  if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY"))
     {
     filePrefix = this->GetOption("CPACK_PACKAGE_FILE_NAME");
     filePrefix += "/";
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
index 01ed4df..f7d8a4d 100644
--- a/Source/CPack/cmCPackGenerator.cxx
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -691,7 +691,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
           //  one install directory for each component.
           tempInstallDirectory +=
             GetComponentInstallDirNameSuffix(installComponent);
-          if (this->IsOn("CPACK_INCLUDE_TOPLEVEL_DIRECTORY"))
+          if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY"))
             {
             tempInstallDirectory += "/";
             tempInstallDirectory += this->GetOption("CPACK_PACKAGE_FILE_NAME");
-- 
cgit v0.12