[PATCH] CPack: Added EXTRA_INSTALL_COMMANDS option for single COMPONENTs to NSIS-Generator. NSIS commands given to CPACK_COMPONENT_<name>_EXTRA_INSTALL_COMMANDS are added exclusivly to the install section generated for the component <name>.

Marcel minusdreidb at gmail.com
Mon Nov 14 09:13:49 EST 2011


This gives greater flexibility in contrast to
CPACK_NSIS_EXTRA_INSTALL_COMMANDS that only allows to add NSIS commands to
the overall install section, in case that extra commands should only be
executed if the user chooses to install a certain section.

Also, removed the constraint that only components with files are added
to the generated NSIS-Script, so that components with extra install
commands only can be created.

BUFIX: check for empty extraInstallCommands.
---
 Source/CPack/cmCPackComponentGroup.h  |    3 +++
 Source/CPack/cmCPackGenerator.cxx     |   20 ++++++++++++++++++++
 Source/CPack/cmCPackNSISGenerator.cxx |   31 +++++++++++++++++++++++++++----
 3 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/Source/CPack/cmCPackComponentGroup.h b/Source/CPack/cmCPackComponentGroup.h
index cebdd6d..af81fc2 100644
--- a/Source/CPack/cmCPackComponentGroup.h
+++ b/Source/CPack/cmCPackComponentGroup.h
@@ -89,6 +89,9 @@ public:
   /// The list of installed directories that are part of this component.
   std::vector<std::string> Directories;
 
+  /// Extra install commands that are added to this section
+  std::vector<std::string> ExtraInstallCommands;
+
   /// Get the total installed size of all of the files in this
   /// component, in bytes. installDir is the directory into which the 
   /// component was installed.
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
index 083279f..e086c26 100644
--- a/Source/CPack/cmCPackGenerator.cxx
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -1520,6 +1520,26 @@ cmCPackGenerator::GetComponent(const char *projectName, const char *name)
       component->Description = description;
       }
 
+    // Process extra install commands
+    const char* extraInstallCommands
+      = this->GetOption((macroPrefix + "_EXTRA_INSTALL_COMMANDS").c_str());
+    if (extraInstallCommands != NULL)
+      {
+      std::vector<std::string> eCommandsVector;
+      cmSystemTools::ExpandListArgument(extraInstallCommands, eCommandsVector);
+      std::vector<std::string>::iterator eCommIt;
+      for (eCommIt = eCommandsVector.begin();
+          eCommIt != eCommandsVector.end();
+          ++eCommIt)
+        {
+          if (!eCommIt->empty())
+            {
+              component->ExtraInstallCommands.push_back(*eCommIt);
+            }
+        }
+      }
+
+
     // Determine the installation types.
     const char *installTypes 
       = this->GetOption((macroPrefix + "_INSTALL_TYPES").c_str());
diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx
index 2b94067..e5e49ca 100644
--- a/Source/CPack/cmCPackNSISGenerator.cxx
+++ b/Source/CPack/cmCPackNSISGenerator.cxx
@@ -242,7 +242,10 @@ int cmCPackNSISGenerator::PackageFiles()
       if (compIt->second.Files.empty())
         {
         // NSIS cannot cope with components that have no files.
-        continue;
+           if (compIt->second.ExtraInstallCommands.empty())
+             {
+             continue;
+             }
         }
 
       anyDownloadedComponents =
@@ -819,8 +822,18 @@ CreateComponentDescription(cmCPackComponent *component,
     }
   else
     {
-    componentCode += "  File /r \"${INST_DIR}\\" +
-      component->Name + "\\*.*\"\n";
+      if (!component->Files.empty())
+        {
+        componentCode += "  File /r \"${INST_DIR}\\" +
+            component->Name + "\\*.*\"\n";
+        }
+    }
+  std::vector<std::string>::iterator extraIt;
+  for (extraIt = component->ExtraInstallCommands.begin();
+       extraIt != component->ExtraInstallCommands.end();
+       extraIt++)
+    {
+    componentCode += "  " + *extraIt + "\n";
     }
   componentCode += "SectionEnd\n";
 
@@ -972,9 +985,19 @@ CreateComponentGroupDescription(cmCPackComponentGroup *group,
        comp != group->Components.end(); 
        ++comp)
     {
+
     if ((*comp)->Files.empty())
       {
-      continue;
+      if ((*comp)->ExtraInstallCommands.empty())
+        {
+        continue;
+        }
+      else
+        {
+        cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+            "Adding section with no files but extra install commands."
+            << std::endl);
+        }
       }
 
     code += this->CreateComponentDescription(*comp, macrosOut);
-- 
1.7.6.msysgit.0



--------------040407070004010705030800--


More information about the CMake mailing list