Creating Windows Desktop Icon in CMake + CPack + NSIS
Asked Answered
P

5

12

I'm using NSIS package generator in CMake 2.8.1 to distribute a Qt application. Everything is working fine... except the use of CPACK_CREATE_DESKTOP_LINKS to create a desktop link to the application.

I've looked through the CMake source (including it's own "bootstrap" installation definition for windows), and as far as I can tell I'm doing the same thing.

Here's the relevant section of my CMakeLists.txt file.


set(CPACK_GENERATOR NSIS)
set(CPACK_NSIS_PACKAGE_NAME "${EWS_APP_NAME}")
set(CPACK_NSIS_DISPLAY_NAME "${EWS_APP_NAME}")
set(CPACK_NSIS_CONTACT "${EWS_EMAIL}")
set(CPACK_PACKAGE_EXECUTABLES "${EXE_TARGET_NAME}" "${EWS_APP_NAME}")
set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${CMAKE_PROJECT_NAME}-${EWS_VERSION}")

# this works
set(CPACK_NSIS_MENU_LINKS "${EWS_WEBSITE}" "Homepage for ${EWS_APP_NAME}")

# this doesn't
set(CPACK_CREATE_DESKTOP_LINKS "${EXE_TARGET_NAME}")

# Icon in the add/remove control panel. Must be an .exe file 
set(CPACK_NSIS_INSTALLED_ICON_NAME bin\\\\${EXE_TARGET_NAME}.exe)

set(CPACK_NSIS_URL_INFO_ABOUT "${EWS_WEBSITE}")
set(CPACK_NSIS_HELP_LINK "${EWS_WEBSITE}")

Any ideas or debugging tips are appreciated!

Pizor answered 14/4, 2010 at 20:24 Comment(0)
S
12

try adding this to your CMakeLists.txt:

set (CPACK_NSIS_MODIFY_PATH "ON")

I think that should add a page after the license that gives the option to add the install directory to the path, and add an option to create desktop links.

Satisfactory answered 4/6, 2010 at 18:41 Comment(0)
P
7

One work-around I figured out is to use CPACK_NSIS_EXTRA_INSTALL_COMMANDS and CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS to insert the link creation/deletion commands directly.

set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
    CreateShortCut \\\"$DESKTOP\\\\${EWS_APP_NAME}.lnk\\\" \\\"$INSTDIR\\\\bin\\\\${EXE_TARGET_NAME}.exe\\\"
")

set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
    Delete \\\"$DESKTOP\\\\${EWS_APP_NAME}.lnk\\\"
")

I'd much rather use the more general (and cross-platform?) CPACK_CREATE_DESKTOP_LINKS setting, so any followup ideas are appreciated. But this works in a pinch.

Pizor answered 15/4, 2010 at 2:38 Comment(0)
P
4

I am using the following macro to add links both to the program files menu to the desktop

macro(prepareNSIS_Link linkName appName params)
 #prepare start menu links
 LIST(APPEND CPACK_NSIS_CREATE_ICONS_EXTRA "  CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\${linkName}.lnk' '$INSTDIR\\\\bin\\\\${appName}.exe' '${params}'")
 LIST(APPEND CPACK_NSIS_DELETE_ICONS_EXTRA "  Delete '$SMPROGRAMS\\\\$START_MENU\\\\${linkName}.lnk'")

 #prepare desktop links
 LIST(APPEND CPACK_NSIS_CREATE_ICONS_EXTRA  "  CreateShortCut '$DESKTOP\\\\${linkName}.lnk' '$INSTDIR\\\\bin\\\\${appName}.exe' '${params}'")
 LIST(APPEND CPACK_NSIS_DELETE_ICONS_EXTRA  "  Delete '$DESKTOP\\\\${linkName}.lnk'")
endmacro()

To create a link to for [installFolder]/bin/app.exe -some -parameters call it as:

prepareNSIS_Link("My application" "app" "-some -parameters")

Once you set up all your links be nice and replace semicolons with new lines:

  string (REPLACE ";" "\n" CPACK_NSIS_CREATE_ICONS_EXTRA "${CPACK_NSIS_CREATE_ICONS_EXTRA}")
  string (REPLACE ";" "\n" CPACK_NSIS_DELETE_ICONS_EXTRA "${CPACK_NSIS_DELETE_ICONS_EXTRA}")
Passed answered 16/3, 2016 at 8:33 Comment(0)
J
2

For others who come across this thread, there's the CPACK_NSIS_CREATE_ICONS_EXTRA and CPACK_NSIS_DELETE_ICONS_EXTRA CMake variables which can be used to create arbitrary shortcuts (Start menu, desktop, etc.). The delete side of things can have a small gotcha, but it's still a relatively easy and flexible way to get shortcuts where you want them. The added bonus is that you can also add command-line arguments if required. This short article explains how to use these variables to create and delete Start menu items and includes links to documentation for other useful NSIS variables. It should be easy enough to use the approach for desktop shortcuts with the information presented there.

Jaela answered 29/8, 2015 at 1:26 Comment(0)
B
0

You most likely don't need to quote ${EXE_TARGET_NAME} as it is a string.

Bodgie answered 16/4, 2010 at 15:51 Comment(1)
True enough (just a habit on my part), but doesn't affect the result.Pizor

© 2022 - 2024 — McMap. All rights reserved.