Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 362
KyleL Avatar asked Sep 30 '15 18:09

KyleL


1 Answers

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 -DCOMPONENT=COMPONENT_1 ../
nmake package
cmake -DCOMPONENT=COMPONENT_2 ../
nmake package
...
cmake -DCOMPONENT=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)

like image 161
Timmo Avatar answered Sep 20 '22 16:09

Timmo