From 728e023a8d2dc85402fbe1295e87023fdb7c4c1b Mon Sep 17 00:00:00 2001
From: Ovidiu Panait <ovidiu.panait@windriver.com>
Date: Fri, 31 Jan 2020 10:56:11 +0200
Subject: [PATCH] clang,llvm: cmake: Fix configure for packages using
 find_package()

Currently, when a package (i.e. bcc [https://github.com/iovisor/bcc.git])
that depends on LLVM/Clang tries to run cmake find_package() during
do_configure, it will fail with a similar error:

|   The imported target "llvm-tblgen" references the file
|      ".../recipe-sysroot/usr/bin/llvm-tblgen"
|
|   but this file does not exist.  Possible reasons include:
|   * The file was deleted, renamed, or moved to another location.
|   * An install or uninstall procedure did not complete successfully.
|   * The installation package was faulty and contained
|      ".../recipe-sysroot/usr/lib/cmake/LLVMExports.cmake"
|   but not all the files it references.

This is due to the fact that currently the cmake scripts look for target
binaries in sysroot. Work around this by not exporting the target binaries in
Exports-* cmake files.

Upstream-Status: Innapropriate [oe-specific]

Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
---
 clang/cmake/modules/AddClang.cmake | 2 --
 llvm/cmake/modules/AddLLVM.cmake   | 6 ------
 llvm/cmake/modules/TableGen.cmake  | 7 -------
 3 files changed, 15 deletions(-)

diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake
index 9bbbfc032b7d..7ee5170bbc71 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -159,7 +159,6 @@ macro(add_clang_tool name)
   if (CLANG_BUILD_TOOLS)
     get_target_export_arg(${name} Clang export_to_clangtargets)
     install(TARGETS ${name}
-      ${export_to_clangtargets}
       RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
       COMPONENT ${name})
 
@@ -168,7 +167,6 @@ macro(add_clang_tool name)
                                DEPENDS ${name}
                                COMPONENT ${name})
     endif()
-    set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
   endif()
 endmacro()
 
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 37bc98f9e021..d34083fa52ec 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1251,7 +1251,6 @@ macro(add_llvm_tool name)
     if( LLVM_BUILD_TOOLS )
       get_target_export_arg(${name} LLVM export_to_llvmexports)
       install(TARGETS ${name}
-              ${export_to_llvmexports}
               RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR}
               COMPONENT ${name})
 
@@ -1262,9 +1261,6 @@ macro(add_llvm_tool name)
       endif()
     endif()
   endif()
-  if( LLVM_BUILD_TOOLS )
-    set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
-  endif()
   set_target_properties(${name} PROPERTIES FOLDER "Tools")
 endmacro(add_llvm_tool name)
 
@@ -1304,7 +1300,6 @@ macro(add_llvm_utility name)
     if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS)
       get_target_export_arg(${name} LLVM export_to_llvmexports)
       install(TARGETS ${name}
-              ${export_to_llvmexports}
               RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR}
               COMPONENT ${name})
 
@@ -1313,7 +1308,6 @@ macro(add_llvm_utility name)
                                  DEPENDS ${name}
                                  COMPONENT ${name})
       endif()
-      set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
     elseif(LLVM_BUILD_UTILS)
       set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name})
     endif()
diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake
index 59fd0d3b0733..3b9ac56ed37f 100644
--- a/llvm/cmake/modules/TableGen.cmake
+++ b/llvm/cmake/modules/TableGen.cmake
@@ -183,14 +183,8 @@ macro(add_tablegen target project)
   endif()
 
   if ((${project} STREQUAL LLVM OR ${project} STREQUAL MLIR) AND NOT LLVM_INSTALL_TOOLCHAIN_ONLY AND LLVM_BUILD_UTILS)
-    set(export_to_llvmexports)
-    if(${target} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
-        NOT LLVM_DISTRIBUTION_COMPONENTS)
-      set(export_to_llvmexports EXPORT LLVMExports)
-    endif()
 
     install(TARGETS ${target}
-            ${export_to_llvmexports}
             COMPONENT ${target}
             RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR})
     if(NOT LLVM_ENABLE_IDE)
@@ -199,5 +193,4 @@ macro(add_tablegen target project)
                                COMPONENT ${target})
     endif()
   endif()
-  set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${target})
 endmacro()
