CMake:CPackNSISAdvancedTips: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
(Add explicit preformat markup)
Line 4: Line 4:
==NSIS script file creation==
==NSIS script file creation==
When CPack uses the NSIS generator, it reads the following files from the modules path:
When CPack uses the NSIS generator, it reads the following files from the modules path:
<pre>
   NSIS.template.in
   NSIS.template.in
   NSIS.InstallOptions.ini.in  
   NSIS.InstallOptions.ini.in  
</pre>


CPack fills in the variables and outputs it to this directory:
CPack fills in the variables and outputs it to this directory:
<pre>
   ${CMAKE_BINARY_DIR}\_CPack_Packages\${CPACK_TOPLEVEL_TAG}\${CPACK_GENERATOR}\
   ${CMAKE_BINARY_DIR}\_CPack_Packages\${CPACK_TOPLEVEL_TAG}\${CPACK_GENERATOR}\
</pre>


Both files get their name changed to
Both files get their name changed to
<pre>
   Project.nsi
   Project.nsi
   NSIS.InstallOptions.ini
   NSIS.InstallOptions.ini
</pre>


To start work on a custom NSIS script, simply create a file (or copy) into your module path (e.g. CPACK_MODULE_PATH) called NSIS.template.in.  CPack will automatically use your path over the default one.
To start work on a custom NSIS script, simply create a file (or copy) into your module path (e.g. CPACK_MODULE_PATH) called NSIS.template.in.  CPack will automatically use your path over the default one.
Line 22: Line 28:


With the NSIS.template.in, look for the Function .onInit  Within this function insert the following line:
With the NSIS.template.in, look for the Function .onInit  Within this function insert the following line:
<pre>
   !insertmacro INSTALLOPTIONS_EXTRACT_AS "@MY_PATH_TO_FILE@\@MY_FILENAME@" "@MY_FILENAME@"
   !insertmacro INSTALLOPTIONS_EXTRACT_AS "@MY_PATH_TO_FILE@\@MY_FILENAME@" "@MY_FILENAME@"
</pre>


Next, look for a section that says ReserveFile.  Again, just add the line:
Next, look for a section that says ReserveFile.  Again, just add the line:
<pre>
   ReserveFile "@MY_PATH_TO_FILE@\@MY_FILENAME@"
   ReserveFile "@MY_PATH_TO_FILE@\@MY_FILENAME@"
</pre>


Don't forget to define MY_PATH_TO_FILE and MY_FILENAME in either your CPackConfig file or your CMakeLists.txt
Don't forget to define MY_PATH_TO_FILE and MY_FILENAME in either your CPackConfig file or your CMakeLists.txt

Revision as of 18:32, 24 April 2018

CPack NSIS Advanced Tips

Those who are comfortable with both CMake/CPack and NSIS may wish to customize their own NSIS scripts to pass through CPack.

NSIS script file creation

When CPack uses the NSIS generator, it reads the following files from the modules path:

  NSIS.template.in
  NSIS.InstallOptions.ini.in 

CPack fills in the variables and outputs it to this directory:

  ${CMAKE_BINARY_DIR}\_CPack_Packages\${CPACK_TOPLEVEL_TAG}\${CPACK_GENERATOR}\

Both files get their name changed to

  Project.nsi
  NSIS.InstallOptions.ini

To start work on a custom NSIS script, simply create a file (or copy) into your module path (e.g. CPACK_MODULE_PATH) called NSIS.template.in. CPack will automatically use your path over the default one.

NOTE: It may be tempting to create custom Install options using NSIS.InstallOptions.ini.in, but it is NOT recommended. CPack uses this file to provide the option of modifying the PATH environment variable. Modifying this file or the references to it within NSIS.template.in may render this option useless. If custom InstallOptions files are desired, read the next section.

Integrating Custom InstallOptions files

At first glance, integrating a custom option file appears to be difficult, since CPack copies 2 specific files to a separate generated directory. However, integration is really quite simple.

With the NSIS.template.in, look for the Function .onInit Within this function insert the following line:

  !insertmacro INSTALLOPTIONS_EXTRACT_AS "@MY_PATH_TO_FILE@\@MY_FILENAME@" "@MY_FILENAME@"

Next, look for a section that says ReserveFile. Again, just add the line:

  ReserveFile "@MY_PATH_TO_FILE@\@MY_FILENAME@"

Don't forget to define MY_PATH_TO_FILE and MY_FILENAME in either your CPackConfig file or your CMakeLists.txt

Now, @MY_FILENAME@ can be referenced directly anywhere in the script.



CMake: [Welcome | Site Map]