Can CMake/CPack generate multiple NSIS installers for a single project?

你说的曾经没有我的故事 提交于 2019-12-07 03:32:30

问题


I have a single project (with sub-projects) for which I would like to generate multiple NSIS installer executables, instead of having multiple components listed in a single NSIS installer. Is this possible? Or do I need to organize my code into separate projects?


回答1:


One could provide a CMake attribute e.g. COMPONENT which can be set to a value from a predefined set of package names like: COMPONENT_1|COMPONENT_2|...COMPONENT_X

The package name could even be a name that does not correspond to a single component name but a set of components that would be added in the CPACK_COMPONENTS_ALL. If the COMPONENT is equal to ALL_COMPONENTS then the value of CPACK_COMPONENTS_ALL would contain all possible components.

The cmake packaging:

if (WIN32)
  set (CPACK_COMPONENTS_ALL ${COMPONENT})
  set (CPACK_PACKAGE_NAME ${COMPONENT})
  set (CPACK_COMPONENT_${COMPONENT}_DISPLAY_NAME "${COMPONENT}")
  set (CPACK_COMPONENT_${COMPONENT}_DESCRIPTION "${COMPONENT}")  
  set (CPACK_NSIS_DISPLAY_NAME "${COMPONENT}")
  set (CPACK_NSIS_PACKAGE_NAME "${COMPONENT}")
  set (CPACK_NSIS_INSTALL_ROOT "C:")
  set (CPACK_GENERATOR NSIS)
else()
  ...
endif()

To create an installer for each COMPONENT you would run for example:

cmake -COMPONENT=COMPONENT_1 ../
nmake package
cmake -COMPONENT=COMPONENT_2 ../
nmake package
...
cmake -COMPONENT=COMPONENT_X ../
nmake package

Bear in mind that since the binaries are build on the first execution of nmake package, the subsequent calls to cmake and nmake package will only re-configure the packaging and only build the requested COMPONENT(aka COMPONENT)



来源:https://stackoverflow.com/questions/32873339/can-cmake-cpack-generate-multiple-nsis-installers-for-a-single-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!