Search code examples
cmakensiscpack

CMake/CPack command for InstallDirRegKey


In an NSIS script file, it is possible to set the following, to use a registry entry as the install directory:

InstallDirRegKey HKCU "Software\Test" "RegEntry"

I was wondering if it would be possible to set this command from a cmake file, so that the NSIS script is automatically generated. Much in the same way the directory of an install can be set like:

SET(CPACK_PACKAGE_INSTALL_DIRECTORY "testDir")

Many thanks


Solution

  • I'm not following exactly what you're trying to do, but if you just want a custom command in the NSIS file, you can do this:

    list(APPEND CPACK_NSIS_EXTRA_INSTALL_COMMANDS " 
                    InstallDirRegKey HKCU \"Software\\Test\" \"RegEntry\"
                   ")
    

    Be careful of the backslashes, needed to escape the double quote and the literal backslash. I think you might need 4 backslashes instead of 2 for the literal backslash, but try it and see. Check the resulting NSIS file, and add more backslashes as necessary.

    EDIT:

    There's another, much more complete way to customize the NSIS install script. According to this: http://cmake.org/Wiki/CMake:CPackNSISAdvancedTips you can copy NSIS.template.in (from your CMake installation) into your source tree (in a directory that's on your CMAKE_MODULE_PATH) and modify it.