How to create an installer with CMake + CPack + NSIS on Windows?

对着背影说爱祢 提交于 2019-11-29 23:05:10

... 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?

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.

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.

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

from your build directory in a VS command prompt.

This should yield your installer named MyLib-1.0.0-win64.exe, also in your build directory.


If you want to just use CMake, then an alternative to invoking msbuild is:

cmake --build . --target PACKAGE.vcxproj --config Release


Or you can build the solution first, then invoke CPack to create the installer:

cmake --build . --config Release
cpack -C Release
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!