From d1613ac880df62b171f7f929d98dfaa62dd78417 Mon Sep 17 00:00:00 2001 From: Johnny Jazeix Date: Sat, 24 Sep 2022 22:42:09 +0200 Subject: CPack/NSIS: Add options to set makensis arguments Fixes: #23446 --- Help/cpack_gen/nsis.rst | 31 ++++++++++++++++++++ .../dev/cpack-nsis-arguments-command-line.rst | 7 +++++ Source/CPack/cmCPackNSISGenerator.cxx | 34 ++++++++++++++++++++-- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 Help/release/dev/cpack-nsis-arguments-command-line.rst diff --git a/Help/cpack_gen/nsis.rst b/Help/cpack_gen/nsis.rst index 299cfec..df306c2 100644 --- a/Help/cpack_gen/nsis.rst +++ b/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 ` 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 ... "nsisFileName.nsi" ... + + where ``...`` is constructed from ``CPACK_NSIS_EXECUTABLE_PRE_ARGUMENTS`` + and ``...`` 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 ` 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 ... "nsisFileName.nsi" ... + + where ``...`` is constructed from ``CPACK_NSIS_EXECUTABLE_PRE_ARGUMENTS`` + and ``...`` is constructed from ``CPACK_NSIS_EXECUTABLE_POST_ARGUMENTS``. diff --git a/Help/release/dev/cpack-nsis-arguments-command-line.rst b/Help/release/dev/cpack-nsis-arguments-command-line.rst new file mode 100644 index 0000000..610a338 --- /dev/null +++ b/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. diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 217f716..6ca5783 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/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 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 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; -- cgit v0.12