<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63286>63286</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            CMake policy CMP0091 should be upgraded to new form
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            cmake,
            platform:windows
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mstorsjo
      </td>
    </tr>
</table>

<pre>
    CC @zmodem @rnk @glandium 

After upgrading the minimum CMake version to 3.20, the CMake policy CMP0091 https://cmake.org/cmake/help/latest/policy/CMP0091.html changed to the new form, which broke a couple build scenarios, as mentioned in #62719. It also broke the LLVM custom parameters for setting what CRT to link against, as described in #32739.

This was temporarily remedied by switching the policy CMP0091 back to the old form in 7d47dac5f828efd1d378ba44a97559114f00fb64 / https://reviews.llvm.org/D150688 (and after a revert, when relanded in cbaa3597aaf6273e66b3f445ed36a6458143fe6a).

Switching the policy to old form is a temporary workaround, as newer CMake warns:
```
CMake Deprecation Warning at /home/martin/code/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):
  The OLD behavior for policy CMP0091 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
```

In order to switch to the new policy, the root cause of the issues in #62719 need to be fixed; compiler-rt has some custom code for selecting CRT, which doesn't work in the new mode. A pointer to this is https://github.com/llvm/llvm-project/blob/llvmorg-16.0.3/compiler-rt/CMakeLists.txt#L398. Also, the LLVM custom options for choosing the CRT to link, in https://github.com/llvm/llvm-project/blob/llvmorg-16.0.3/llvm/cmake/modules/ChooseMSVCCRT.cmake, need to be updated to use the new CMake mechanisms for selecting CRT, instead of meddling directly in the `CMAKE_${lang}_FLAGS_${build}` variables.
</pre>
<img width="1px" height="1px" alt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