CPackIFWConfigureFile — CMake 4.4.0 Documentation

# CPackIFWConfigureFile

Added in version 3.8.

This module provides a command similar to `configure_file()` for configuring file templates prepared in QtIFW/SDK/Creator style.

Load this module in a CMake project with:

    include(CPackIFWConfigureFile)

## Commands

This module provides the following command:

cpack_ifw_configure_file

  Copies a file template to output file and substitutes variable values referenced as `%{VAR}` or `%VAR%` from the input file template content:

      cpack_ifw_configure_file(<input> <output>)

  `<input>`

    Input file template. If given as a relative path, it is interpreted as relative to the current source directory (`CMAKE_CURRENT_SOURCE_DIR`).

  `<output>`

    Output file. If given as a relative path, it is interpreted as relative to the current binary directory (`CMAKE_CURRENT_BINARY_DIR`).

  Qt Installer Framework (QtIFW) uses `@` characters for embedding predefined variables (`TargetDir`, `StartMenuDir`, etc.) in Qt installer scripts:

  `example.qs`

      component.addOperation(
        "CreateShortcut",
        "@TargetDir@/example.com.html",
        "@StartMenuDir@/Example Web Site.lnk"
      );

  The purpose of this command is to preserve the QtIFW predefined variables containing the `@` characters (`@VAR@`), and instead use the `%` characters for template placeholders (`%VAR%`, `%{VAR}`) in Qt/IFW/SDK/Creator templates. The `configure_file()` command would otherwise replace all variable references containing the `@` characters.

  Each variable reference will be replaced with the current value of the variable, or the empty string if the variable is not defined.

## Examples

In the following example this module is used to create an IFW component script from a given template file `qt.tools.foo.qs.in`, where `%FOO_DOC_DIR%` variable reference will be replaced by the values of the `FOO_DOC_DIR` CMake variable.

`CMakeLists.txt`

    cmake_minimum_required(VERSION 3.8)

    project(Foo)

    # ...

    include(CPackIFWConfigureFile)

    set(FOO_DOC_DIR "doc/foo")

    cpack_ifw_configure_file(qt.tools.foo.qs.in qt.tools.foo.qs)

`qt.tools.foo.qs.in`

    function Component()
    {
    }

    Component.prototype.createOperations = function()
    {
      if (installer.value("os") === "win") {
        component.addOperation(
          "CreateShortcut",
          "@TargetDir@/%FOO_DOC_DIR%/example.com.html",
          "@StartMenuDir@/Example Web Site.lnk"
        );
      }

      component.createOperations();
    }

    // ...

## See Also

- The `CPack IFW Generator`.

- The `CPackIFW` module.