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)


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:



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.


  1. Thanks a lot! I have been using this patch to create MSI installers for my Windows application. I really hope this functionality finds its way into the official CMAKE releases.

  2. Hey, nice work :)

    the issue of integration into the official cmake release has been bumped on the cmake mailinglist, they say for integration this lacks a test and documentation ..

  3. I will try to complete the circle with upstream in the not too distant future. They have some requirements that I need to cleanup in order to accept.

  4. So after belaboring this to death I've started to go against my original thoughts and decided that I would leverage the install target to a PREFIX location on windows then use a bat file to gen the WiX package. Why would I do this, well in part the cmake folks are a bit pokey. The second reason is that I found some glaring issues with CPack, and in all honesty I'm not a big fan of how some of it's innards function.

  5. Hi,
    I applied your patch and tried it on my project, but it fails when I try to "make package" with the following: "error when compressing folder".

    Could you possibly enhance your patch so it forwards wix's outputs to the terminal ?


  6. Hi,

    Is this patch now part of a main stream?
    What is the status?


  7. WiX support was in the cmake/cpack ~2.8.10 release. I'm sorry I don't know the exact release when it was introduced, but I do use the WIX generator in the current 2.8.12 download to successfully generate MSIs.