Customize CPack NSIS

Hello,
i’m trying to customize a NSIS installer generated via CPack.
Specifically, we do not need shortcuts and a custom install location, since the location of the to-be-installed files is fixed, and choosing a custom location for the uninstaller isn’t really necessary either- we’d like to make the installation process as seamless as possible.
I haven’t found any CMake / CPack variables to control this behaviour, therefore i turned to changing the NSIS-installer code directly.
I found out that the following is necessary to achieve our desired behaviour:
(Abort skips the page, the !define MUI_PAGE_CUSTOMFUNCTION_PRE skipPage just before the insertion of the macro calls the function after the opening of the page)

...
Function skipPage 
  Abort 
FunctionEnd

...
  
!insertmacro MUI_PAGE_WELCOME

!define MUI_PAGE_CUSTOMFUNCTION_PRE skipPage
!insertmacro MUI_PAGE_DIRECTORY
...

!define MUI_PAGE_CUSTOMFUNCTION_PRE skipPage
!insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER

However, i don’t know how to effectively and portably change the installer script in the cpack step.
Of course, i could simply modify the template file located in the cmake-modules folder, but i really dont want to do that.
My thought was that at some point the template from the modules-folder must be translated into the actual file that is used for generating the installer- at this point i could modify the script using file(APPEND...) or string(REPLACE...) commands.
However, it seems that the points in time i can execute custom cmake scripts simply do not allow for this kind of modification:

  • CPACK_INSTALL_SCRIPTS: At this time the template isn’t translated into the actual installer script yet.
  • CPACK_PRE_BUILD_SCRIPTS: Same as above
  • CPACK_POST_BUILD_SCRIPTS: Here the installer is already generated.

I know that there are the CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS and others, which would probably allow me to introduce the skipPage function, but i also need to add lines at very specific places in the file too, and i don’t see any way of doing so using the other NSIS CPack-variables

So to sum up, i need to execute a script right after the NSIS installer template is translated- is there anything different i could try here?

All the best,
Stephan

You can just use your own template file by putting it into a path mentioned in the CMAKE_MODULE_PATH path list.

Sure, i’ve read about this too. But i don’t really want to modify this global directory, especially since this will be used via CI builds. Also, this would mean that i need to keep track of changes to the original template with cmake-updates.

This is not a global directory, it is usually specific for the project.

OTOH, if you want something simple on Windows, generate an .msi with the wix cpack generator.

Sorry for the late reply, i was on vacation!
So you mean that i can simply append the CMAKE_MODULE_PATH with a folder that contains a custom nsis template, and CPack would pick it up and use it directly?
That would be a quite good solution, thank you!