CMP0091.rst 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. CMP0091
  2. -------
  3. MSVC runtime library flags are selected by an abstraction.
  4. Compilers targeting the MSVC ABI have flags to select the MSVC runtime library.
  5. Runtime library selection typically varies with build configuration because
  6. there is a separate runtime library for Debug builds.
  7. In CMake 3.14 and below, MSVC runtime library selection flags are added to
  8. the default :variable:`CMAKE_<LANG>_FLAGS_<CONFIG>` cache entries by CMake
  9. automatically. This allows users to edit their cache entries to adjust the
  10. flags. However, the presence of such default flags is problematic for
  11. projects that want to choose a different runtime library programmatically.
  12. In particular, it requires string editing of the
  13. :variable:`CMAKE_<LANG>_FLAGS_<CONFIG>` variables with knowledge of the
  14. CMake builtin defaults so they can be replaced.
  15. CMake 3.15 and above prefer to leave the MSVC runtime library selection flags
  16. out of the default :variable:`CMAKE_<LANG>_FLAGS_<CONFIG>` values and instead
  17. offer a first-class abstraction. The :variable:`CMAKE_MSVC_RUNTIME_LIBRARY`
  18. variable and :prop_tgt:`MSVC_RUNTIME_LIBRARY` target property may be set to
  19. select the MSVC runtime library. If they are not set then CMake uses the
  20. default value ``MultiThreaded$<$<CONFIG:Debug>:Debug>DLL`` which is
  21. equivalent to the original flags.
  22. This policy provides compatibility with projects that have not been updated
  23. to be aware of the abstraction. The policy setting takes effect as of the
  24. first :command:`project` or :command:`enable_language` command that enables
  25. a language whose compiler targets the MSVC ABI.
  26. .. note::
  27. Once the policy has taken effect at the top of a project, that choice
  28. must be used throughout the tree. In projects that have nested projects
  29. in subdirectories, be sure to convert everything together.
  30. The ``OLD`` behavior for this policy is to place MSVC runtime library
  31. flags in the default :variable:`CMAKE_<LANG>_FLAGS_<CONFIG>` cache
  32. entries and ignore the :variable:`CMAKE_MSVC_RUNTIME_LIBRARY` abstraction.
  33. The ``NEW`` behavior for this policy is to *not* place MSVC runtime
  34. library flags in the default cache entries and use the abstraction instead.
  35. This policy was introduced in CMake version 3.15. Use the
  36. :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
  37. Unlike many policies, CMake version |release| does *not* warn
  38. when this policy is not set and simply uses ``OLD`` behavior.
  39. .. include:: DEPRECATED.txt