summaryrefslogtreecommitdiff
path: root/dev-libs/rocm-comgr/files/rocm-comgr-5.1.3-Find-CLANG_RESOURCE_DIR.patch
blob: 362f5fcf16ca558b4f37ce8cce883d5cbd55ee00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
From 4c01c63a49af5748a8ee698553aa107803b60362 Mon Sep 17 00:00:00 2001
From: Yiyang Wu <xgreenlandforwyy@gmail.com>
Date: Tue, 14 Jun 2022 20:21:22 +0800
Subject: [PATCH] Find CLANG_RESOURCE_DIR using clang -print-resource-dir

Suggested-By: https://reviews.llvm.org/D49486
Signed-off-by: Yiyang Wu <xgreenlandforwyy@gmail.com>
---
 lib/comgr/cmake/opencl_pch.cmake | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)

Index: comgr/cmake/opencl_pch.cmake
===================================================================
--- comgr.orig/cmake/opencl_pch.cmake
+++ comgr/cmake/opencl_pch.cmake
@@ -1,26 +1,8 @@
 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   find_package(Clang REQUIRED CONFIG)
-
-  # FIXME: CLANG_CMAKE_DIR seems like the most stable way to find this, but
-  # really there is no way to reliably discover this header.
-  #
-  # We effectively back up to the Clang output directory (for the case of a build
-  # tree) or install prefix (for the case of an installed copy), and then search
-  # for a file named opencl-c.h anywhere below that. We take the first result in
-  # the case where there are multiple (e.g. if there is an installed copy nested
-  # in a build directory). This is a bit imprecise, but it covers cases like MSVC
-  # adding some additional configuration-specific subdirectories to the build
-  # tree but not to an installed copy.
-  file(GLOB_RECURSE OPENCL_C_H_LIST "${CLANG_CMAKE_DIR}/../../../*/opencl-c.h")
-
-  list(GET OPENCL_C_H_LIST 0 OPENCL_C_H)
-
-  if (NOT EXISTS "${OPENCL_C_H}" OR IS_DIRECTORY "${OPENCL_C_H}")
-    message(FATAL_ERROR "Unable to locate opencl-c.h from the supplied Clang. The path '${CLANG_CMAKE_DIR}/../../../*' was searched.")
-  endif()
-else()
-  get_target_property(clang_build_header_dir clang-resource-headers RUNTIME_OUTPUT_DIRECTORY)
-  set(OPENCL_C_H "${clang_build_header_dir}/opencl-c.h")
+  execute_process(COMMAND "${CLANG_INSTALL_PREFIX}/bin/clang" -print-resource-dir OUTPUT_VARIABLE CLANG_RESOURCE_DIR)
+  string(STRIP ${CLANG_RESOURCE_DIR} CLANG_RESOURCE_DIR)
+  set(OPENCL_C_H "${CLANG_RESOURCE_DIR}/include/opencl-c.h")
 endif()
 
 # Macro to create and install a custom target for generating PCH for given
Index: comgr/src/comgr-compiler.cpp
===================================================================
--- comgr.orig/src/comgr-compiler.cpp
+++ comgr/src/comgr-compiler.cpp
@@ -42,6 +42,7 @@
 #include "lld/Common/Driver.h"
 #include "clang/Basic/Version.h"
 #include "clang/CodeGen/CodeGenAction.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Job.h"
@@ -988,11 +989,8 @@ amd_comgr_status_t AMDGPUCompiler::addCo
   HIPIncludePath = (Twine(env::getHIPPath()) + "/include").str();
   // HIP headers depend on hsa.h which is in ROCM_DIR/include.
   ROCMIncludePath = (Twine(env::getROCMPath()) + "/include").str();
-  ClangIncludePath =
-      (Twine(env::getLLVMPath()) + "/lib/clang/" + CLANG_VERSION_STRING).str();
-  ClangIncludePath2 = (Twine(env::getLLVMPath()) + "/lib/clang/" +
-                       CLANG_VERSION_STRING + "/include")
-                          .str();
+  ClangIncludePath = (Twine(env::getLLVMPath()) + "/bin/" + CLANG_RESOURCE_DIR).str();
+  ClangIncludePath2 = (Twine(env::getLLVMPath()) + "/bin/" + CLANG_RESOURCE_DIR + "/include").str();
 
   Args.push_back("-x");