CMP0197.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. CMP0197
  2. -------
  3. .. versionadded:: 4.1
  4. MSVC link ``-machine:`` flag is not in ``CMAKE_*_LINKER_FLAGS``.
  5. When using MSVC-like compilers in CMake 4.0 and below, the linker's
  6. ``-machine:`` flag is added via language-agnostic linker flag variables:
  7. * :variable:`CMAKE_EXE_LINKER_FLAGS`
  8. * :variable:`CMAKE_SHARED_LINKER_FLAGS`
  9. * :variable:`CMAKE_MODULE_LINKER_FLAGS`
  10. * :variable:`CMAKE_STATIC_LINKER_FLAGS`
  11. This is problematic when multiple languages' toolchains disagree about
  12. if/how to pass the flag through a compiler driver to the linker.
  13. Furthermore, carrying the flag in public-facing variables allows projects
  14. or users to change it even though it is required.
  15. CMake 4.1 and above prefer to leave the ``-machine:`` flag out of
  16. ``CMAKE_*_LINKER_FLAGS`` variables, and instead generate the link
  17. flag automatically where needed.
  18. This policy provides compatibility with projects that have not been updated
  19. to expect the lack of the ``-machine:`` flags. The policy setting takes
  20. effect as of the first :command:`project` or :command:`enable_language`
  21. command that initializes the above-listed ``CMAKE_*_LINKER_FLAGS`` variables.
  22. .. note::
  23. Once the policy has taken effect at the top of a project for a given
  24. language, that choice must be used throughout the tree for that language.
  25. In projects that have nested projects in subdirectories, be sure to
  26. convert everything together.
  27. The ``OLD`` behavior for this policy is to place the MSVC ``-machine:``
  28. flag in ``CMAKE_*_LINKER_FLAGS``. The ``NEW`` behavior for this policy
  29. is to *not* place the MSVC ``-machine:`` flag in ``CMAKE_*_LINKER_FLAGS``.
  30. .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 4.1
  31. .. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
  32. .. include:: include/STANDARD_ADVICE.rst
  33. .. include:: include/DEPRECATED.rst