How to get cpack to create the right launcher shortcuts

I want to create an installer for some programs on windows with cmake and cpack. I want to be able to choose which programs to install, and the selected programs should appear as shortcuts in the start menu. Here is a simple attempt. We have done one component for each program but cannot figure out how to create an initial menu variable. Now all programs are always in the menu, even if they are not selected for installation. At first it is a simple installation program.

#include <iostream> #include <conio.h> int main() { std::cout << "prog1" << std::endl; _getch(); return 0; } 

and here is the CMakeLists.txt file

 cmake_minimum_required( VERSION 2.8 ) project ( CompoTest ) add_executable(prog1 prog1.cpp) add_executable(prog2 prog2.cpp) add_executable(prog3 prog3.cpp) install(TARGETS prog1 RUNTIME DESTINATION bin COMPONENT compo1) install(TARGETS prog2 RUNTIME DESTINATION bin COMPONENT compo2) install(TARGETS prog3 RUNTIME DESTINATION bin COMPONENT compo3) set ( CPACK_PACKAGE_VERSION "1.0.0" ) set(CPACK_PACKAGE_EXECUTABLES prog1 "prog 1" prog2 "prog 2" prog3 "prog 3" ) set ( CPACK_COMPONENTS_ALL compo1 compo2 compo3 ) include (CPack) 

The problem is creating shortcuts to the start menu depending on which program is selected in the installation. I thought it would be easy, but it seems that it is not. Is it possible to do this.

Update: I found that for any example, http://www.cmake.org/Wiki/CMake:Component_Install_With_CPack does not create any start menu shortcuts, or am I doing something wrong?

+6
source share
1 answer

This is a known issue with cpack. see http://public.kitware.com/Bug/print_bug_page.php?bug_id=9846

You need to use the NSIS template to create custom shortcuts for the start menu.

Steps:

  • Copy NSIS.template.in from the installed cmake directory. (e.g. C: \ Program Files \ CMake 2.8 \ share \ cmake-2.8 \ Modules \ NSIS.template.in) into your Cmake Source Dir project.

  • Update the copied NSIS.template.in similarly to the fragment below (taken from http://public.kitware.com/Bug/print_bug_page.php?bug_id=9846 ):

     if (executable file is in component 'x') if (installing component 'x') CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\x.lnk" "$INSTDIR\x.exe" if (uninstalling executable x) Delete "$SMPROGRAMS\$MUI_TEMP\x.lnk" 
  • Add the line below to CMakeLists.txt before including (cpack):

     set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH}) 
+11
source

Source: https://habr.com/ru/post/954439/


All Articles