# Customize CPack NSIS

**URL:** https://discourse.cmake.org/t/customize-cpack-nsis/3902
**Category:** Usage
**Tags:** os:windows
**Created:** [August 11, 2021, 10:59am UTC](https://discourse.cmake.org/t/customize-cpack-nsis/3902 "2021-08-11T10:59:13Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![vallant](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vallant/32/1503_2.png) [@vallant](https://discourse.cmake.org/u/vallant)
#### Post date: [August 11, 2021, 10:59am UTC](https://discourse.cmake.org/t/customize-cpack-nsis/3902/1 "2021-08-11T10:59:14Z")

</div>

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)

```auto
...
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

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [August 11, 2021, 2:26pm UTC](https://discourse.cmake.org/t/customize-cpack-nsis/3902/2 "2021-08-11T14:26:04Z")

</div>

You can just use your own template file by putting it into a path mentioned in the CMAKE\_MODULE\_PATH path list.

---

<div class="post-metadata">

### Author: ![vallant](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vallant/32/1503_2.png) [@vallant](https://discourse.cmake.org/u/vallant)
#### Post date: [August 11, 2021, 2:30pm UTC](https://discourse.cmake.org/t/customize-cpack-nsis/3902/3 "2021-08-11T14:30:41Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [August 11, 2021, 4:28pm UTC](https://discourse.cmake.org/t/customize-cpack-nsis/3902/4 "2021-08-11T16:28:52Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![vallant](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vallant/32/1503_2.png) [@vallant](https://discourse.cmake.org/u/vallant)
#### Post date: [September 2, 2021, 12:39pm UTC](https://discourse.cmake.org/t/customize-cpack-nsis/3902/5 "2021-09-02T12:39:04Z")

</div>

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!
