如何在Windows上创建一个CMake + CPack + NSIS安装程序? [英] How to create an installer with CMake + CPack + NSIS on Windows?

查看:672
本文介绍了如何在Windows上创建一个CMake + CPack + NSIS安装程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我正在建立的基于C ++的系统创建一个跨平台安装程序。

I'd like to create a cross-platform installer for a C++ based system I am building.

我使用CMake构建一切,如果我可以使用CPack来做安装程序。我已经有CPack在OSX上工作,但我不能让它在Windows上工作。为了简化操作,我尝试了 http://www.cmake.org/Wiki/CMake:Packaging_With_CPack 使用NSIS安装程序软件。我在配置(使用VS 2010 Win64生成器)后找不到NSIS安装程序。

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,那么答案是肯定的。您可以使用 <$ c $来执行您所选的构建工具c> - 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之后,你的build目录中会有一个文件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

这将产生名为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安装程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆