I wanted to build a Windows installer for a 64 bit Visual Studio application that was build-managed using CMake. This post makes use of the example source code downloadable from https://cmake.org/Wiki/File:ComponentExampleStart.zip.
Add in CPACK macros to CMakeLists.txt
- Download and extract the example zip file into a folder e.g. D:\Temp\ComponentExampleStart\ as shown below. I then created a build sub-folder build underneath the D:\Temp\ComponentExampleStart\Source\ folder.
- Use a text editor and edit the CMakeLists.txt file to add in CPACK macros according to the Wiki. An edited example is shown below.
Generate the Visual Studio solution
- Open up a Command Prompt. Change to the build directory.
D:> cd \temp\ComponentExampleStart\Source\build
- Use the cmake command to generate the build files.
D:> cmake -G "Visual Studio 14 2015 Win64" ..
The build files are generated.
Build the Visual Studio solution and generate the installer
- Using Visual Studio, open up the generated solution e.g. MyLib.sln.
- Since I wanted a release build, in Visual Studio I changed from Debug to Release, as shown below. Then I selected Build.
The release binaries are generated.
- Next, in the Solution Explorer, select and mouse right click on the PACKAGE project.
A pop down menu appears.
- Choose Build.
CPack processing message appears.
The NSIS installer is generated.