Hi,

I extended cpack's NSIS-generator and want to contribute the attached patch.

It adds the CPACK_COMPONENT_<name>_EXTRA_INSTALL_COMMANDS option to cpack that allows to add NSIS commands exclusivly to the install section generated for the component <name>. So it adopts the option CPACK_NSIS_EXTRA_INSTALL_COMMANDS for single components/sections.

That way special code can be added to a section that ist only executed if the user chooses to install the section.

Perhaps this change could be merged into the cmake, because I think this could be of some use for other cpack users.

If this is not the right place to contribute, could someone please give me a pointer.

Best regards,

Marcel

>From 88dcca63c40aaa25902023a3b7c7ae8e9f9c44c2 Mon Sep 17 00:00:00 2001
From: Marcel <minusdre...@gmail.com>
Date: Mon, 14 Nov 2011 15:13:49 +0100
Subject: [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>.

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


--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to