Mesa (master): clover: Check if the detected clang libraries are usable

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Apr 16 16:49:42 UTC 2020


Module: Mesa
Branch: master
Commit: 8cbeb13704a59034ffe19a7ffef7b3856a1733e8
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8cbeb13704a59034ffe19a7ffef7b3856a1733e8

Author: Jan Vesely <jano.vesely at gmail.com>
Date:   Sat Apr  4 14:59:35 2020 -0400

clover: Check if the detected clang libraries are usable

clang-cpp.so is broken in LLVM-9 and doesn't exist in LLVM<9,
however meson will find and try to use system libraries in these cases.

v2: Use helper variable to dedpulicate test code
    Move second test inside the condition to avoid testing good clang-cpp twice
v3: Check for cross compilation
v4: style fixes

Fixes: ff1a3a00cb37d84ab9a563f0aa241714876f56b4
Signed-off-by: Jan Vesely <jano.vesely at gmail.com>
Tested-by: Karol Herbst <kherbst at redhat.com>
Acked-by: Karol Herbst <kherbst at redhat.com>
Reviewed-by: Dylan Baker <dylan at pnwbakers.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4457>

---

 src/gallium/targets/opencl/meson.build | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/gallium/targets/opencl/meson.build b/src/gallium/targets/opencl/meson.build
index 6ce01025d0b..c3029953bb0 100644
--- a/src/gallium/targets/opencl/meson.build
+++ b/src/gallium/targets/opencl/meson.build
@@ -30,11 +30,28 @@ if with_ld_version_script
 endif
 
 llvm_libdir = dep_llvm.get_configtool_variable('libdir')
-
 opencl_libname = with_opencl_icd ? 'MesaOpenCL' : 'OpenCL'
 
 dep_clang = cpp.find_library('clang-cpp', dirs : llvm_libdir, required : false)
-if not dep_clang.found()
+
+# meson will return clang-cpp from system dirs if it's not found in llvm_libdir
+linker_rpath_arg = '-Wl,--rpath=@0@'.format(llvm_libdir)
+clang_test_code = '''
+  #include <clang/Basic/Version.h>
+  int main (void) {
+    size_t found_pos = clang::getClangFullVersion().find(CLANG_VERSION_STRING);
+    return found_pos == ::std::string::npos ? 1 : 0;
+  }
+'''
+can_check_clang = (not meson.is_cross_build() or meson.has_exe_wrapper()) and cpp.has_link_argument(linker_rpath_arg)
+if can_check_clang
+  test_run = cpp.run(clang_test_code, name : 'dep-clang-usable',
+                     dependencies : [dep_llvm, dep_clang], args : linker_rpath_arg)
+  dep_clang_usable = test_run.compiled() and test_run.returncode() == 0
+else
+  dep_clang_usable = true
+endif
+if not (dep_clang.found() and dep_clang_usable)
   dep_clang = [
     cpp.find_library('clangCodeGen', dirs : llvm_libdir),
     cpp.find_library('clangFrontendTool', dirs : llvm_libdir),
@@ -50,6 +67,14 @@ if not dep_clang.found()
     cpp.find_library('clangLex', dirs : llvm_libdir),
     cpp.find_library('clangBasic', dirs : llvm_libdir),
   ]
+  # check clang once more
+  if can_check_clang
+    test_run = cpp.run(clang_test_code, name : 'dep-clang-usable',
+                       dependencies : [dep_llvm, dep_clang], args : linker_rpath_arg)
+    if not test_run.compiled() or test_run.returncode() != 0
+      error('No usable clang found!')
+    endif
+  endif
 endif
 
 libopencl = shared_library(



More information about the mesa-commit mailing list