Search code examples
cmakensiscpack

How add registry keys with CPACK_PACKAGE_INSTALL_REGISTRY_KEY?


I need to install some registry key for a NSIS installer. I'm working with CPACK and I found this command CPACK_PACKAGE_INSTALL_REGISTRY_KEY. There is not much doc on the Internet but I guess :

set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
"MyReg\\\\MyKey" "${INSTALL_DIR}\\\\" 
)

Or something not much different.

I also read this on an other topic:

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

But I didn't understand why use this last command instead of the CPACK command.

Thank you for your help


Solution

  • I don't know anything about CPack but I guess CPACK_PACKAGE_INSTALL_REGISTRY_KEY also maps to InstallDirRegKey and cannot be used to write generic values to the registry.

    Try something like this to insert raw NSIS instructions:

    SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
      WriteRegStr HKLM 'Software\\\\MyApp' 'MyValue' 'MyData'
      WriteRegDWORD HKLM 'Software\\\\MyApp' 'OtherValue' '4'
       ")
    SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
      DeleteRegKey HKLM 'Software\\\\MyApp' 
     ")