开发者

Creating Windows Desktop Icon in CMake + CPack + NSIS

开发者 https://www.devze.com 2022-12-27 02:44 出处:网络
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'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 a开发者_如何学编程n .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!


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.


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.


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}")


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消