7

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
  • Do you want installer executables be per-subproject? If so, why not to build every subproject alone, with its installer? For make NSIS installer(and any other) to separate installed files you need to assign them to different components. project() command, which starts every sub-project, has no sence for CPack.
    – Tsyvarev
    Commented Oct 1, 2015 at 0:06

1 Answer 1

2

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)

1
  • 1
    Thank you for the idea. I think there is a typo and the correct cmake sequence is -DCOMPONENT=COMPONENT_1
    – PJ127
    Commented Apr 29, 2022 at 7:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.