The current cmake script attempts to add the path containing clangs various runtime systems by getting the resource directory and then appending the hardcoded value /lib/windows to it. This works for a normal clang-cl build but fails for a build of clang using LLVM_ENABLE_PER_TARGET_RUNTIME_DIR, such as the builds from llvm/runtimes.
This patch instead uses -print-libgcc-file-name in conjunction with --rtlib=compiler-rt, and instead adds the containing directory as library path.
For non per-target runtime directory builds, such as the release builds, there is no change. Even if the builtins library were to be deleted or moved it would output the same path as before.
For per-target runtime builds that also have the builtins library, this now finds the correct directory containing all of clang runtime libraries.
Only case still not handled by this change, is if a per-target runtime directory build is used, but the builtins library was not built.
I believe that is the best we can do for now however, without modifying clang.
Example command line outputs:
LLVM 11 binaries distributed by LLVM:
C:\Program Files\LLVM\bin>clang-cl /clang:-print-libgcc-file-name /clang:--rtlib=compiler-rt C:\Program Files\LLVM\lib\clang\11.0.1\lib\windows\clang_rt.builtins-x86_64.lib
Per-target runtime dir build of clang:
clang-cl /clang:-print-libgcc-file-name /clang:--rtlib=compiler-rt C:\clang\Default\lib\clang\11.1.0\lib\x86_64-pc-windows-msvc\clang_rt.builtins.lib