Monday, February 1, 2010

WiX and CPack Integration

CMake and it's compliment CPack provide a very useful tool(s) for cross platform building and packaging of C & C++ applications.  For some time now CPack has been lacking support for WiX which allows users to create a standard .msi package.  This is very useful for those who wish to deploy in enterprise environments, as there are some key advantages over other methods.   Below is an outline of what steps I had to follow to add WiX support to CPack-2.8.0.  This will likely hit 90% user cases, for the last 10%, I pass the baton to you.

Patching CPack-2.8.0
1. Obtain the patch here & apply
2. Rebuild and install cmake (follow the online instructions)

or

use a diff tool to overlay *this on your windows cmake directory

So how does it work? 
There was no clean/fast way for me to create an XML generator, so I decided to leverage the tools which come with WiX and rely on the fact that CPack stages the install prior to compression.  The tool which is pivotal to the whole process is heat, which will generate an xml file based on the contents of the staged directory.  The key to making it automated is the fact that heat can take a .xsl file as input which then can transform the auto-generated goop into something useful for creating your installer.  You can find a simple example here

You will need to replace YOUR_ with something useful based on the context, but that should be straight forwards.  Once that is done you can make a couple simple changes to your CMakeLists.txt files and add the following:


set (CPACK_GENERATOR "WIX")

set (CPACK_WIX_XSL ${YOUR_PACKAGE_SOURCE_DIR}/win.xsl)


now you can run your PACKAGE target and it will create a .msi based on your .xsl.

For more information on customizing your installer please see the WiX documentation.