Browse Source

CPack/NSIS: Add options to set makensis arguments

Fixes: #23446
Johnny Jazeix 3 years ago
parent
commit
d1613ac880

+ 31 - 0
Help/cpack_gen/nsis.rst

@@ -207,3 +207,34 @@ on Windows Nullsoft Scriptable Install System.
  .. versionadded:: 3.22
 
  If set, do not display the page containing the license during installation.
+
+.. variable:: CPACK_NSIS_EXECUTABLE_PRE_ARGUMENTS
+
+ .. versionadded:: 3.25
+
+ This variable is a :ref:`semicolon-separated list <CMake Language Lists>` of
+ arguments to prepend to the nsis script to run.
+ If the arguments do not start with a ``/`` or a ``-``, it will add one
+ automatically to the corresponding arguments.
+ The command that will be run is::
+
+    makensis.exe <preArgs>... "nsisFileName.nsi" <postArgs>...
+
+ where ``<preArgs>...`` is constructed from ``CPACK_NSIS_EXECUTABLE_PRE_ARGUMENTS``
+ and ``<postArgs>...``  is constructed from ``CPACK_NSIS_EXECUTABLE_POST_ARGUMENTS``.
+
+
+.. variable:: CPACK_NSIS_EXECUTABLE_POST_ARGUMENTS
+
+ .. versionadded:: 3.25
+
+ This variable is a :ref:`semicolon-separated list <CMake Language Lists>` of
+ arguments to append to the nsis script to run.
+ If the arguments do not start with a ``/`` or a ``-``, it will add one
+ automatically to the corresponding arguments.
+ The command that will be run is::
+
+    makensis.exe <preArgs>... "nsisFileName.nsi" <postArgs>...
+
+ where ``<preArgs>...`` is constructed from ``CPACK_NSIS_EXECUTABLE_PRE_ARGUMENTS``
+ and ``<postArgs>...``  is constructed from ``CPACK_NSIS_EXECUTABLE_POST_ARGUMENTS``.

+ 7 - 0
Help/release/dev/cpack-nsis-arguments-command-line.rst

@@ -0,0 +1,7 @@
+cpack-nsis-arguments-command-line
+---------------------------------
+
+* The :cpack_gen:`CPack NSIS Generator` gained two new variables
+  :variable:`CPACK_NSIS_EXECUTABLE_PRE_ARGUMENTS` and
+  :variable:`CPACK_NSIS_EXECUTABLE_POST_ARGUMENTS`
+  to provide arguments to the nsis executable invocation.

+ 32 - 2
Source/CPack/cmCPackNSISGenerator.cxx

@@ -242,6 +242,33 @@ int cmCPackNSISGenerator::PackageFiles()
     this->SetOptionIfNotSet("CPACK_NSIS_LICENSE_PAGE", licenceCode);
   }
 
+  std::string nsisPreArguments;
+  if (cmValue nsisArguments =
+        this->GetOption("CPACK_NSIS_EXECUTABLE_PRE_ARGUMENTS")) {
+    std::vector<std::string> expandedArguments;
+    cmExpandList(nsisArguments, expandedArguments);
+
+    for (auto& arg : expandedArguments) {
+      if (!cmHasPrefix(arg, NSIS_OPT)) {
+        nsisPreArguments = cmStrCat(nsisPreArguments, NSIS_OPT);
+      }
+      nsisPreArguments = cmStrCat(nsisPreArguments, arg, ' ');
+    }
+  }
+
+  std::string nsisPostArguments;
+  if (cmValue nsisArguments =
+        this->GetOption("CPACK_NSIS_EXECUTABLE_POST_ARGUMENTS")) {
+    std::vector<std::string> expandedArguments;
+    cmExpandList(nsisArguments, expandedArguments);
+    for (auto& arg : expandedArguments) {
+      if (!cmHasPrefix(arg, NSIS_OPT)) {
+        nsisPostArguments = cmStrCat(nsisPostArguments, NSIS_OPT);
+      }
+      nsisPostArguments = cmStrCat(nsisPostArguments, arg, ' ');
+    }
+  }
+
   // Setup all of the component sections
   if (this->Components.empty()) {
     this->SetOptionIfNotSet("CPACK_NSIS_INSTALLATION_TYPES", "");
@@ -358,8 +385,11 @@ int cmCPackNSISGenerator::PackageFiles()
   this->ConfigureFile(nsisInInstallOptions, nsisInstallOptions);
   this->ConfigureFile(nsisInFileName, nsisFileName);
   std::string nsisCmd =
-    cmStrCat('"', this->GetOption("CPACK_INSTALLER_PROGRAM"), "\" \"",
-             nsisFileName, '"');
+    cmStrCat('"', this->GetOption("CPACK_INSTALLER_PROGRAM"), "\" ",
+             nsisPreArguments, " \"", nsisFileName, '"');
+  if (!nsisPostArguments.empty()) {
+    nsisCmd = cmStrCat(nsisCmd, " ", nsisPostArguments);
+  }
   cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << nsisCmd << std::endl);
   std::string output;
   int retVal = 1;