CPackWIX: Simplifying Windows Installer Creation with CMake


Functionality

  • Integrates with CPack for including project files and resources in the installer.
  • Leverages pre-defined WiX templates for a streamlined creation process.
  • Generates WiX project files based on information provided in your CMakeLists.txt file.

Variables

CPackWIX exposes several variables you can set in your CMakeLists.txt to customize the installer behavior. These variables control aspects like:

  • UI Reference
    Controls the user interface layout of the installer. (CPACK_WIX_UI_REF)
  • Product Icon
    Sets the icon displayed for your program in the Add/Remove Programs list. (CPACK_WIX_PRODUCT_ICON)
  • License File
    Specifies the license agreement for your software. (CPACK_WIX_LICENSE_RTF)
  • Product GUID
    Unique identifier for your installer. (CPACK_WIX_PRODUCT_GUID)
  • Upgrade GUID
    Controls how upgrades to your software are handled. (CPACK_WIX_UPGRADE_GUID)
  • Offers customization options through variables.
  • Provides a consistent approach to packaging your project.
  • Simplifies installer creation for Windows by leveraging CMake and WiX.


  1. CMake Documentation
  1. Limited Code Examples

A discussion thread on the CMake forum showcases limited code examples demonstrating how to set some CPackWIX variables:

# Set the Upgrade GUID
set(CPACK_WIX_UPGRADE_GUID "{YOUR_UNIQUE_GUID_HERE}")

# Set the Product Name and Description
set(CPACK_PACKAGE_NAME "My Awesome Software")
set(CPACK_PACKAGE_DESCRIPTION "A fantastic program you'll love")

# Set the license file (assuming it's an RTF file)
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/License.rtf")

# Include your project files and resources
include(CPack)
cpack_add_component(MAIN_FILES "${PROJECT_SOURCE_DIR}/bin/MyApp.exe" "${PROJECT_SOURCE_DIR}/data/config.ini")

# Generate the MSI installer
cpack_wix()
  • Finally, cpack_wix generates the MSI installer using the provided information.
  • The cpack_add_component line includes your application binary and configuration file in the installer.
  • It specifies the license file location (assuming it's an RTF format).
  • It defines the Product Name and Description displayed during installation.
  • This code sets the Upgrade GUID for your installer. Remember to replace "{YOUR_UNIQUE_GUID_HERE}" with an actual GUID.


  1. NSIS (Nullsoft Scriptable Install System)
  • Offers a good balance of flexibility and ease of use.
  • Integrates with CMake through third-party modules like CPackNSIS.
  • Popular open-source installer creation tool with a scripting language for customization.
  1. Advanced Installer
  • Might be a good option if you prefer a GUI-based approach.
  • Provides pre-built templates and drag-and-drop functionality.
  • Commercial tool with a visual interface for creating MSI installers.
  1. Build Systems with Native Packaging Support
  • Less portable but might be suitable if you're already using a specific build system.
  • Some build systems like Make or MSBuild have built-in functionalities for generating installers on their respective platforms.
  1. Third-Party Installer Creation Tools
  • Research options like Inno Setup, InstallForge, WixToolset itself (if you prefer more control over WiX XML).
  • There are various commercial and open-source installer creation tools available.

Choosing the Right Alternative

Here are some factors to consider when selecting an alternative:

  • Budget
    NSIS and some build system functionalities are free, while others are commercial options.
  • Team Preference
    If your team is comfortable with scripting, NSIS could be a good fit. For a visual interface, consider Advanced Installer.
  • Project Complexity
    For simpler projects, NSIS with CPackNSIS can be sufficient. For complex requirements, Advanced Installer or WixToolset might be better.