Swift_COMPILATION_MODE — CMake 3.29.3 Documentation

# Swift_COMPILATION_MODE

New in version 3.29.

Specify how Swift compiles a target.

The allowed values are:

`incremental`

  Compiles each Swift source in the module separately, resulting in better parallelism in the build. The compiler emits additional information into the build directory improving rebuild performance when small changes are made to the source between rebuilds. This is the best option to use while iterating on changes in a project.

`wholemodule`

  Whole-module optimizations are slowest to compile, but results in the most optimized library. The entire context is loaded into once instance of the compiler, so there is no parallelism across source files in the module.

`singlefile`

  Compiles each source in a Swift modules separately, resulting in better parallelism. Unlike the `incremental` build mode, no additional information is emitted by the compiler during the build, so rebuilding after making small changes to the source file will not run faster. This option should be used sparingly, preferring `incremental` builds, unless working around a compiler bug.

Use `generator expressions` to support per-configuration specification. For example, the code:

    add_library(foo foo.swift)
    set_property(TARGET foo PROPERTY
      Swift_COMPILATION_MODE "$<IF:$<CONFIG:Release>,wholemodule,incremental>")

sets the Swift compilation mode to wholemodule mode in the release configuration and sets the property to incremental mode in other configurations.

The property is initialized from the value of the `CMAKE_Swift_COMPILATION_MODE` variable, if it is set. If the property is not set or is empty, then CMake uses the default value `incremental` to specify the swift compilation mode.

Note

This property only has effect when policy `CMP0157` is set to `NEW` prior to the first `project()` or `enable_language()` command that enables the Swift language.