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

后端 未结 1 786
误落风尘
误落风尘 2020-12-08 01:27

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

I use CMake to build everything, and it would be great if I could use CPack to m

相关标签:
1条回答
  • 2020-12-08 01:44

    ... 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
    
    0 讨论(0)
提交回复
热议问题