2

I want to package a project of mine for windows with CPack and NSIS using an already existing GeneratorConfig.cmake file where I want to add an extra command that will copy an .ini file called myProject.ini into %APPDATA%/myProject/myProject.ini .

This is GeneratorConfig.cmake

SET(INSTALL_AN_ALREADY_EXISTING_DIR ".")
##########################################################################
## Begin NSIS Specific options
##------------------------------------------------------------------------
if(CPACK_GENERATOR MATCHES NSIS)
# Additional NSIS commands to uninstall start menu shortcuts
SET(CPACK_NSIS_DELETE_ICONS_EXTRA
  "Delete \"$SMPROGRAMS\\$MUI_TEMP\\${PROJECT_NAME}.lnk\" 
   StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2
   Delete \"$DESKTOP\\${PROJECT_NAME}.lnk\" ")
# The display name string that appears in the Windows Add/Remove Program control panel
SET(CPACK_NSIS_DISPLAY_NAME "${PROJECT_NAME} ${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}")
SET(CPACK_NSIS_DISPLAY_NAME_SET "TRUE")

# Extra NSIS commands that will be added to the end of the install Section, after your
# install tree is available on the target system.
SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS 
    "CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\${PROJECT_NAME}.lnk\" \"$INSTDIR\\.\\bin\\${PROJECT_EXE} \" -previousworkingdir \"$INSTDIR\\.\\bin\\app_icon.ico\"  
     StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2
     CreateShortCut \"$DESKTOP\\${PROJECT_NAME}.lnk\" \"$INSTDIR\\.\\bin\\${PROJECT_EXE} \" -previousworkingdir \"$INSTDIR\\.\\bin\\app_icon.ico\" 
     ")

# Extra commands to fix permissions of bin/licenses folder
SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS 
   "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}
    ExecWait 'icacls \\\"$INSTDIR\\\\bin\\\\licenses\\\" /grant:r Users:\\\(OI\\\)\\\(CI\\\)\\\(F\\\)'
    ")

# A path to the executable that contains the installer icon.
SET(CPACK_NSIS_INSTALLED_ICON_NAME "${PROJECT__DIR}\\bin\\${PROJECT_EXE}")

# The default installation directory presented to the end user by the NSIS installer
SET(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")

# Title displayed at the top of the installer
SET(CPACK_NSIS_PACKAGE_NAME "${PROJECT_NAME} ${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}")

SET(CPACK_NSIS_PAGE_COMPONENTS " ")

SET(CPACK_NSIS_MUI_FINISHPAGE_RUN ${PROJECT_EXE})
endif(CPACK_GENERATOR MATCHES NSIS)
##------------------------------------------------------------------------
## End NSIS Specific options
##########################################################################

I tried to do this with the code below but this builds the package but doesn't copy myProject.ini anywhere.

SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS 
  "CreateDirectory \"$ENV{APPDATA}\\myProject\",
   SetOutPath \"$ENV{APPDATA}\\myProject\",
   File \"myProject.ini\" 
   ")

Any help or suggestions will be appreciated.

1
  • I'm also having a similar problem. When you overcome this issue , could you please post the solution ? Commented Oct 25, 2014 at 11:02

2 Answers 2

2

From what i can tell you are using not enough '\' symbols.

To clarify: that string is evaluated twice, once by CMake and once by CPack, and each time substitutions such as \->\ and \" -> " occur. Please check generated nsis project for what the actual generated commands are and whether all '"' are correctly set.

To summarize: try using this:

SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS 
  "CreateDirectory \\\"$ENV{APPDATA}\\\\myProject\\\",
   SetOutPath \\\"$ENV{APPDATA}\\\\myProject\\\",
   File \\\"myProject.ini\\\" 
   ")
0

I want to copy a sample config file in the share/ folder in my source directory to %AppData%/MyCompany.

Building on Srv19's post, I ended up with the following, with some subtle differences :

set(CPACK_PACKAGE_VENDOR "MyCompany")

# Create the directory :
list(APPEND CPACK_NSIS_EXTRA_INSTALL_COMMANDS "CreateDirectory '$%AppData%\\\\${CPACK_PACKAGE_VENDOR}'")
# Set the NSIS variable OUTDIR :
list(APPEND CPACK_NSIS_EXTRA_INSTALL_COMMANDS "SetOutPath '$%AppData%\\\\${CPACK_PACKAGE_VENDOR}'")
# Add file to be extracted to $OUTDIR :
list(APPEND CPACK_NSIS_EXTRA_INSTALL_COMMANDS "File '${CMAKE_SOURCE_DIR}\\\\share\\\\MyProject.ini'")
# Replace ';' by '\n' in CPACK_NSIS_EXTRA_INSTALL_COMMANDS :
string (REPLACE ";" "\n" CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}")

Not the answer you're looking for? Browse other questions tagged or ask your own question.