How to create an installer with CMake + CPack + NSIS on Windows?(如何在 Windows 上使用 CMake + CPack + NSIS 创建安装程序?)
问题描述
我想为我正在构建的基于 C++ 的系统创建一个跨平台安装程序.
I'd like to create a cross-platform installer for a C++ based system I am building.
我使用 CMake 来构建所有东西,如果我可以使用 CPack 来制作安装程序就太好了.我已经在 OSX 上使用了 CPack,但我无法让它在 Windows 上工作.为了让事情更容易,我尝试在 http://www.cmake.org/Wiki 上获取示例/CMake:Packaging_With_CPack 使用 NSIS 安装程序软件.配置后我在任何地方都找不到 NSIS 安装程序(使用 VS 2010 Win64 生成器).
I use CMake to build everything, and it would be great if I could use CPack to make the installer. I already have CPack working on OSX, but I cannot get it to work on Windows. To make things easier, I tried to get the example at http://www.cmake.org/Wiki/CMake:Packaging_With_CPack to work with the NSIS installer software. I cannot find the NSIS installer anywhere after configuring (with VS 2010 Win64 generator).
也许我很困惑,但我认为可以创建仅包含源代码、CMake、CPack 和 NSIS 的安装包,而无需任何 Visual Studio.这可能吗?
Maybe I am confused, but I thought it would be possible to create the installation package with only the source, CMake, CPack, and NSIS without any need for Visual Studio. Is this possible?
完整教程的链接(http://www.cmake.org/Wiki/CMake:Component_Install_With_CPack 跳过了相关信息以使 NSIS 工作并且没有提到生成器或编译器)将非常有帮助,或者对我如何获得这个神话般的生成 NSIS 安装程序的基本解释会很棒.
A link to a full tutorial (the one at http://www.cmake.org/Wiki/CMake:Component_Install_With_CPack skips over the relevant information to get NSIS working and doesn't mention generators or compilers) would be very helpful, or a basic explanation of how I can get to this mythical generated NSIS installer would be great.
这里是上面例子的 CMakeLists.txt:
Here is CMakeLists.txt for the example above:
cmake_minimum_required(VERSION 2.6.0 FATAL_ERROR)
project(StPMS)
add_library(mylib mylib.cpp)
add_executable(mylibapp mylibapp.cpp)
target_link_libraries(mylibapp mylib)
install(TARGETS mylib
ARCHIVE
DESTINATION lib
COMPONENT libraries)
install(TARGETS mylibapp
RUNTIME
DESTINATION bin
COMPONENT applications)
install(FILES mylib.h
DESTINATION include
COMPONENT headers)
set(CPACK_GENERATOR NSIS)
set(CPACK_PACKAGE_NAME "MyLib")
set(CPACK_PACKAGE_VENDOR "CMake.org")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
SET(CPACK_NSIS_MODIFY_PATH ON)
INCLUDE(CPack)
推荐答案
... 我认为可以只使用源代码、CMake、CPack 和 NSIS 来创建安装包,而无需任何 Visual Studio.这可能吗?
... I thought it would be possible to create the installation package with only the source, CMake, CPack, and NSIS without any need for Visual Studio. Is this possible?
有点.这取决于您所说的不需要 Visual Studio"是什么意思.您需要一个构建工具来实际创建 lib 和 exe.在 Windows 上,您需要类似 Visual Studio 的 msbuild,尤其是当您指定 "Visual Studio 10 Win64"
作为生成器时.
Kind of. It depends on what you mean by "without any need for Visual Studio". You need a build tool to actually create the lib and exe. On Windows, you need something like Visual Studio's msbuild, especially if you specified "Visual Studio 10 Win64"
as the generator.
如果您的意思是不运行 Visual Studio",那么答案是肯定的.您可以使用 让 CMake 执行您选择的构建工具--build
参数.
If you mean "without running Visual Studio", then the answer is yes. You can have CMake execute your chosen build tool using the --build
argument.
运行 CMake 后,您最终会在构建目录中得到一个文件 PACKAGE.vcxproj.它正在构建这将创建安装程序.您可以从 Visual Studio 内部构建 PACKAGE 项目,也可以通过执行以下操作直接调用 msbuild:
After running CMake, you end up with a file PACKAGE.vcxproj in your build directory. It is building this which will create the installer. You can either build the PACKAGE project from inside Visual Studio, or you can invoke msbuild directly by doing:
msbuild /P:Configuration=Release PACKAGE.vcxproj
从 VS 命令提示符中的构建目录.
from your build directory in a VS command prompt.
这应该会生成名为 MyLib-1.0.0-win64.exe 的安装程序,也在您的构建目录中.
This should yield your installer named MyLib-1.0.0-win64.exe, also in your build directory.
如果您只想使用 CMake,那么调用 msbuild 的替代方法是:
If you want to just use CMake, then an alternative to invoking msbuild is:
cmake --build . --target PACKAGE.vcxproj --config Release
或者您可以先构建解决方案,然后调用 CPack 来创建安装程序:
Or you can build the solution first, then invoke CPack to create the installer:
cmake --build . --config Release
cpack -C Release
这篇关于如何在 Windows 上使用 CMake + CPack + NSIS 创建安装程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Windows 上使用 CMake + CPack + NSIS 创建安装程序?
基础教程推荐
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01