Skip to content

CMake module for building Windows Installer packages with WiX toolset

License

Notifications You must be signed in to change notification settings

apriorit/FindWiX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FindWiX Build status

CMake module for building Windows Installer packages with WiX toolset

Introduction

A native solution for building Windows Installer packages in CMake is CPack. However it has several drawbacks:

  • limited to one installer project (cannot created several installers, for example client.msi and server.msi)
  • cannot directly work with wsx files (hard to convert existings installer source code to CMake)

FindWiX comes to rescue in such cases.

Requirements

Usage

find_package()

Add FindWiX to the module search path and call find_package:

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package(WIX REQUIRED)

FindWiX will search for the installed WiX toolset, expose functions for creating installer packages and define the following variables:

  • WIX_FOUND - if false WiX toolset is absent
  • WIX_ROOT - path where WiX toolset is installed
  • WIX_COMPILE_FLAGS - flags to be used when compiling wxs source files
  • WIX_LINK_FLAGS - flags to be used when linking wixobj files

wix_add_project()

This function creates a new target for WiX project. It compiles one or several wsx files to wixobj files and then links them together into the resulting msi file.

wix_add_project(<name>
    source1 [source2 ...]
    [OUTPUT_NAME <msi_file_name>]
    [EXTENSIONS extension1 [extension2...]]
    [DEPENDS target1 [target2...]])

Where:

  • <name> - name of the project target
  • source1 [source2 ...] - one or several wsx files
  • OUTPUT_NAME - allows to set a name for the resulting msi file, if omitted the name is set to <name>
  • EXTENSIONS - add one or more WiX extensions (for example WixUIExtension)
  • DEPENDS - add project dependencies for the correct build order

Example:

wix_add_project(my_project 
    main.wxs one_more.wxs 
    OUTPUT_NAME "NameSample" 
    EXTENSIONS WixUIExtension WixUtilExtension
    DEPENDS CppExecutable)

WiX compile and link flags

You could do some fine tuning, for example treat warnings as errors:

set(WIX_COMPILE_FLAGS ${WIX_COMPILE_FLAGS} -wx)
set(WIX_LINK_FLAGS ${WIX_LINK_FLAGS} -wx)

CMake variables in WiX

FindWiX generates vars.wxi to make CMake variables available in WiX. Here is a fragment of vars.wxi:

<?xml version='1.0' encoding='UTF-8'?>
<Include>
    <?define ARGC='4' ?>
    <?define ARGN='Main.wxs;DEPENDS;CppExecutable' ?>
    <?define ARGV='WithExecutable;Main.wxs;DEPENDS;CppExecutable' ?>
    <?define ARGV0='WithExecutable' ?>
    <?define ARGV1='Main.wxs' ?>
    <?define ARGV2='DEPENDS' ?>
    <?define ARGV3='CppExecutable' ?>
    <?define CMAKE_AR='' ?>
    <?define CMAKE_AUTOMOC_COMPILER_PREDEFINES='ON' ?>
    <?define CMAKE_AUTOMOC_MACRO_NAMES='Q_OBJECT;Q_GADGET;Q_NAMESPACE' ?>
    ...
</Include>

To get access to those variables include vars.wxi into your wxs file:

<?include vars.wxi?> <!--cmake variables and their values-->

CMake project dependencies in WiX

Also FindWiX generates depends.wxi with file paths to CMake project dependencies. Here is a fragment of depends.wxi:

<?xml version='1.0' encoding='UTF-8'?>
<Include>
    <?define TARGET_FILE:CppExecutable='C:/my_proj/WithExecutable/Debug/CppExecutable.exe' ?>
    <?define TARGET_PDB_FILE:CppExecutable='C:/my_proj/WithExecutable/Debug/CppExecutable.pdb' ?>
    ...
</Include>

To get access to those variables include depends.wxi into your wxs file:

<?include depends.wxi?> <!--paths to cmake dependencies-->

Samples

Take a look at the samples folder to see how to use FindWiX.

License

Apriorit released FindWiX under the OSI-approved 3-clause BSD license. You can freely use it in your commercial or opensource software.

Version History

Version 1.0.0 (20 Sep 2018)

  • Initial public release