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)