Reputation: 2294
I am trying to customize an NSIS installer using CMAKE and CPACK. In particular I would like to include in the generated project.nsi an external script.
Something like:
!include "@SCRIPT_PATH@\@[email protected]"
To do so I am following the example shown here: https://gitlab.kitware.com/cmake/community/-/wikis/doc/cpack/NSISAdvancedTips
I have copied the template script file (NSIS.template.in) and added the required commands. I now need to configure the two variables "@SCRIPT_PATH@ and @SCRIPT_NAME@ accordingly.
I tried to set them like standard CMAKE variables
SET(SCRIPT_PATH "somePath")
SET(SCRIPT_NAME "someName")
but the template variables are simply left blank by CPACK
Any clue?
Upvotes: 1
Views: 3761
Reputation: 109
I know this is old but it may help some folks out there:
The solution to your problem is to prefix your variables, SCRIPT_PATH
and SCRIPT_NAME
by CPACK
. So that it will be CPACK_SCRIPT_PATH
...
That way when CMake process your CmakeLists it knows that your variables should be set for CPack (in other word when generating CPackConfig.cmake).
Upvotes: 0
Reputation: 2294
I have found a working solution.
Start by adding a placeholder in the main NSIS.template.in where you want to insert new commands, for instance:
@NSIS_ADDITIONAL_SCRIPT@
Then you need to configure a template file containing options that will be passed to the CPACK build.
The CPackOptions.cmake contains the following:
SET(NSIS_ADDITIONAL_SCRIPT ${NSIS_ADDITIONAL_SCRIPT})
Then in your CMAKE script before including CPACK you need to set the NSIS_ADDITIONAL_SCRIPT variable (the path is reworked in order to have the correct set of backslashes on window systems)
SET(scriptPath "[path to the script location]" )
FILE(TO_NATIVE_PATH ${scriptPath} scriptPath )
STRING(REPLACE "\\" "\\\\" scriptPath ${scriptPath} )
and finally configure the CPackOption.cmake file (watch out for the correct number of slashes and comas)
SET(NSIS_ADDITIONAL_SCRIPT " \"!include \\\"${scriptPath}\\\" \\n \" ")
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/CMakeConf/CPackOptions.cmake ${PROJECT_BINARY_DIR}/CPackOptions.cmake)
If you do everything correctly:
Upvotes: 2