From 3712a7c33d813ecd3d577dbb39010e6ec78c2229 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Tue, 11 May 2021 15:08:13 +0200
Subject: [PATCH 5/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 e3bc4b468fb6..078a45a1ce69 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)
