CMake / CPack可以为一个项目生成多个NSIS安装程序吗? [英] Can CMake/CPack generate multiple NSIS installers for a single project?
问题描述
我有一个项目(包含子项目),我想为其生成多个NSIS安装程序可执行文件,而不是在单个NSIS安装程序中列出多个组件。这可能吗?还是我需要将代码组织到单独的项目中?
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?
推荐答案
一个可以提供CMake属性,例如 COMPONENT
可以设置为一组预定义的程序包名称中的值,例如:COMPONENT_1 | COMPONENT_2 | ... COMPONENT_X
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
包名称甚至可以是与单个组件名称不对应的名称,而应与CPACK_COMPONENTS_ALL中添加的一组组件对应。如果COMPONENT等于ALL_COMPONENTS,则CPACK_COMPONENTS_ALL的值将包含所有可能的分量。
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.
cmake包装:
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
请记住,由于二进制文件是基于 nmake程序包
,随后对 cma的调用ke
和 nmake软件包
将仅重新配置软件包,并且仅构建请求的COMPONENT(aka COMPONENT)
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)
这篇关于CMake / CPack可以为一个项目生成多个NSIS安装程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!