From f921795451a491ba8fdd8d9d69ce61d727bdd259 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Tue, 11 May 2021 15:08:13 +0200
Subject: [PATCH 6/8] Fix crosscompiling LLVM tools

---
 clang/CMakeLists.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 937a8467df1d..79e310c636b0 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -114,6 +114,16 @@ if(CLANG_BUILT_STANDALONE)
   option(LLVM_ENABLE_LIBXML2 "Use libxml2 if available." ON)
 
   include(AddLLVM)
+  if(CMAKE_CROSSCOMPILING)
+    set(LLVM_USE_HOST_TOOLS ON)
+    include(CrossCompile)
+    if (NOT NATIVE_LLVM_DIR)
+      message(FATAL_ERROR
+       "Crosscompiling standalone requires the variable NATIVE_LLVM_DIR
+       for building the native lldb-tblgen used during the build process.")
+    endif()
+    llvm_create_cross_target(Clang NATIVE "" Release -DLLVM_DIR=${NATIVE_LLVM_DIR})
+  endif()
   include(TableGen)
   include(HandleLLVMOptions)
   include(VersionFromVCS)
-- 
2.35.3.windows.1

