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

    <tr>
        <th>Summary</th>
        <td>
            Backport 73d862e478738675f5d919c6a196429acd7b5f50 to release/19.x
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          peterwaller-arm
      </td>
    </tr>
</table>

<pre>
    This is a backport request to for 73d862e478738675f5d919c6a196429acd7b5f50 which is a revert for f6f88f4b99638821af803d1911ab6a7dac04880b. The latter unfortunately breaks cross compiled ENABLE_RUNTIMES=compiler-rt. It has been fixed on main in the commit requested for backport. If I diff the CMakeCache of the bad commit, then I see that with LLVM_CMAKE_DIR passed, it results in various details of the runtimes build not being correct - we see LLVM_DIR=/usr/lib/llvm-14 in the CMakeCache for example, rather than `path/to/build/lib/cmake/llvm` for the working version.

The below cmake line on a x86 ubuntu 2204 or 2404 machine targetting aarch64-none-linux-gnu reproduces the issue.

```
sudo apt install -y cmake ninja-build clang lld g++-aarch64-linux-gnu qemu-user
git clone --depth=1 https://github.com/llvm/llvm-project
CC=clang CXX=clang++ cmake -Bbld -Sllvm-project/llvm -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' -DCMAKE_BUILD_TYPE=Release -DLLVM_RUNTIME_TARGETS="aarch64-none-linux-gnu" -DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-none-linux-gnu -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;compiler-rt" -DLLVM_USE_LINKER=lld -GNinja
ninja -C bld compiler-rt
echo $'#include <iostream>\nint main(int argc, char *argv[]) { std::cout << "lo\\n"; return 0; }' > test.cxx
bld/bin/clang++ -rtlib=compiler-rt test.cxx
qemu-aarch64 -L /usr/aarch64-linux-gnu ./a.out

# outputs: "lo"
```

In the bad case this fails with something like this, because the broken compiler-rt build does not produce a builtins build:
```
/usr/lib/gcc-cross/aarch64-linux-gnu/11/../../../../aarch64-linux-gnu/bin/ld: cannot find /home/ubuntu/bld/lib/clang/19/lib/aarch64-none-linux-gnu/libclang_rt.builtins.a
```

cc @tru for release manager
cc @omjavaid @jhuber6 for involvement in patches.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVttu4zgS_Rr6pSBBomRZfvBDfBt4J93bSKcXs08BSZUtdijSw4vj_vsFKbmT7KQXO4Ah0GLx1KnboZhz8qQRV2S-JvPtjAXfG7s6o0f7wpRCmzE7zLjpfqwee-lAOmDAmXg-G-vB4p8BnQdv4GgsLKqubSjWi3ZRtc1ifpx3y3IpGlYum5oumegWfH6cF_DSS9GPWBYvaH06fmyObXus-XLZVG1LS3Zsi6orl2XJeMMWHRNF3bYFz-GxR1DMe7QQ9NFYHzTzqH4At8ieHQhrnANhhrNU2MHu8936fvf08O3z4-HT7iupttOWzazP4eChZw44ooajvGIHRsPApAapwfcYgQb5M1rsEttbEnI4HOEAnTwek_HmE3vGDRM9ghnfcNZNEIRu4hsNB3CI4Hvm4UX6Hu7v__XpafPp7vfd0_bwAGfmHHbROrl1QXkXyVyYlSY46NAzqdzNgQ3aywEd8CBVB9p44Cj1CYSxFoWHDF4weUx-tocHUm0J3QdnCd0ryeNTXYasrG8hv4kiBotXNpwVRkaW-R5t5K6BNMWZ-Z7QvTeE7pP7n4hiYM84IZOmSDgR-sXY50jugtZJo3NSbElxNz5jYTkq8wLpNCipMVaDwbVtIPCgfQBKixqMBVoXNQxM9NHIM3tC7yMwY1b0TZ1pozFTUodrdtIBLJ6t6YJAl2hI5wK-c06aYvqlvy50BtjZg9TOM6Ug-zGx0lJ_Z9mYbKGYPoFSHZwIXRO6zm7uXz3_iUPIgkM7Ap-kB6GMRsiyDs--J9W2hN77syPVHaF7Qvcn6fvAc2GGWwanEp2t-Y7Cj0ibTezlxGDzxx-39chj4pqtueog-_ru8IgF2Tb1w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