CMP0157.rst 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. CMP0157
  2. -------
  3. .. versionadded:: 3.29
  4. Swift compilation mode is selected by an abstraction.
  5. The Swift compiler can compile modules in different modes. The desired build
  6. mode depends whether the developer is iterating and wants to incrementally make
  7. changes, or if they are building a release for distribution and want more
  8. optimizations applied to the resulting binary.
  9. CMake versions 3.26 through 3.28 build Swift binaries with whole-module
  10. optimizations enabled when configured in a non-debug build type.
  11. For CMake versions earlier than 3.26, the developer needs to specify
  12. the necessary flag manually for the :ref:`Ninja Generators`, and cannot
  13. not specify whole-module optimizations to the :generator:`Xcode` generator.
  14. CMake versions 3.29 and above prefer to set the compilation mode using
  15. the :prop_tgt:`Swift_COMPILATION_MODE` target property, which can be
  16. initialized by the :variable:`CMAKE_Swift_COMPILATION_MODE` variable.
  17. This policy provides compatibility for projects that have not been updated.
  18. The policy setting takes effect as of the first :command:`project` or
  19. :command:`enable_language` command that enables the ``Swift`` language.
  20. .. note::
  21. Once the policy has taken effect at the top of a project, that choice
  22. must be used throughout the tree. In projects that have nested projects
  23. in subdirectories, be sure to convert everything together.
  24. The ``OLD`` behavior for this policy builds all Swift targets in
  25. ``wholemodule`` mode for non-debug configurations. :ref:`Ninja Generators`
  26. prepend the ``-wmo`` flag to the default set of Swift flags.
  27. The :generator:`Xcode` generator sets the ``SWIFT_COMPILATION_MODE``
  28. attribute to ``wholemodule`` in the generated Xcode project file.
  29. The ``NEW`` behavior for this policy is to apply the compilation mode specified
  30. in the :prop_tgt:`Swift_COMPILATION_MODE` target property, initialized as each
  31. target is created by the :variable:`CMAKE_Swift_COMPILATION_MODE` variable.
  32. .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.29
  33. .. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
  34. .. include:: include/STANDARD_ADVICE.rst
  35. .. include:: include/DEPRECATED.rst