1# Copyright © 2017 Intel Corporation 2# SPDX-License-Identifier: MIT 3 4opencl_link_args = [] 5opencl_link_deps = [] 6opencl_version = '1' 7 8if with_ld_version_script 9 opencl_link_args += [ 10 '-Wl,--version-script', join_paths(meson.current_source_dir(), 'opencl.sym') 11 ] 12 opencl_link_deps += files('opencl.sym') 13endif 14 15llvm_libdir = dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir') 16opencl_libname = with_opencl_icd ? 'MesaOpenCL' : 'OpenCL' 17 18polly_dep = null_dep 19polly_isl_dep = null_dep 20if dep_llvm.version().version_compare('>=10.0.0') 21 polly_dep = cpp.find_library('Polly', dirs : llvm_libdir, required : false) 22 polly_isl_dep = cpp.find_library('PollyISL', dirs : llvm_libdir, required : false) 23endif 24 25dep_clang = cpp.find_library('clang-cpp', dirs : llvm_libdir, required : false) 26 27# meson will return clang-cpp from system dirs if it's not found in llvm_libdir 28linker_rpath_arg = '-Wl,--rpath=@0@'.format(llvm_libdir) 29clang_test_code = ''' 30 #include <clang/Basic/Version.h> 31 int main (void) { 32 size_t found_pos = clang::getClangFullVersion().find(CLANG_VERSION_STRING); 33 return found_pos == ::std::string::npos ? 1 : 0; 34 } 35''' 36can_check_clang = (not meson.is_cross_build() or meson.can_run_host_binaries()) and cpp.has_link_argument(linker_rpath_arg) 37if can_check_clang 38 test_run = cpp.run(clang_test_code, name : 'dep-clang-usable', 39 dependencies : [dep_llvm, dep_clang], args : linker_rpath_arg) 40 dep_clang_usable = test_run.compiled() and test_run.returncode() == 0 41else 42 dep_clang_usable = true 43endif 44if not _shared_llvm or not (dep_clang.found() and dep_clang_usable) 45 dep_clang = [ 46 cpp.find_library('clangCodeGen', dirs : llvm_libdir), 47 cpp.find_library('clangFrontendTool', dirs : llvm_libdir), 48 cpp.find_library('clangFrontend', dirs : llvm_libdir), 49 cpp.find_library('clangDriver', dirs : llvm_libdir), 50 cpp.find_library('clangSerialization', dirs : llvm_libdir), 51 cpp.find_library('clangParse', dirs : llvm_libdir), 52 cpp.find_library('clangSema', dirs : llvm_libdir), 53 cpp.find_library('clangAnalysis', dirs : llvm_libdir), 54 cpp.find_library('clangAST', dirs : llvm_libdir), 55 cpp.find_library('clangASTMatchers', dirs : llvm_libdir), 56 cpp.find_library('clangEdit', dirs : llvm_libdir), 57 cpp.find_library('clangLex', dirs : llvm_libdir), 58 cpp.find_library('clangBasic', dirs : llvm_libdir), 59 polly_dep, polly_isl_dep, 60 ] 61 if dep_llvm.version().version_compare('>= 15.0') 62 dep_clang += cpp.find_library('clangSupport', dirs : llvm_libdir) 63 endif 64 65 # check clang once more 66 if can_check_clang 67 test_run = cpp.run(clang_test_code, name : 'dep-clang-usable', 68 dependencies : [dep_llvm, dep_clang], args : linker_rpath_arg) 69 if not test_run.compiled() or test_run.returncode() != 0 70 error('No usable clang found!') 71 endif 72 endif 73endif 74 75ocldef_in = files(opencl_libname + '.def.in')[0] 76ocldef = custom_target( 77 'ocldef.def', 78 input: ocldef_in, 79 output : 'ocldef.def', 80 command : gen_vs_module_defs_normal_command, 81) 82 83libopencl = shared_library( 84 opencl_libname, 85 [], 86 vs_module_defs : ocldef, 87 link_args : [ld_args_gc_sections, opencl_link_args], 88 link_depends : opencl_link_deps, 89 link_whole : libclover, 90 link_with : [libpipe_loader_dynamic, libgallium], 91 dependencies : [ 92 idep_mesautil, 93 dep_clock, dep_dl, dep_unwind, dep_elf, dep_clang, dep_version 94 ], 95 name_prefix : host_machine.system() == 'windows' ? '' : [], # otherwise mingw will create libOpenCL-1.dll or libMesaOpenCL-1.dll 96 version : '@[email protected]'.format(opencl_version), 97 soversion : host_machine.system() == 'windows' ? '' : opencl_version, 98 install : true, 99) 100 101if with_opencl_icd 102 _config = configuration_data() 103 _config.set('OPENCL_LIBNAME', 'MesaOpenCL') 104 _config.set('OPENCL_VERSION', opencl_version) 105 configure_file( 106 configuration : _config, 107 input : 'mesa.icd.in', 108 output : 'mesa.icd', 109 install : true, 110 install_tag : 'runtime', 111 install_dir : join_paths(get_option('sysconfdir'), 'OpenCL', 'vendors'), 112 ) 113 114 # .so is hardcoded in the icd as well 115 devenv.prepend( 116 'OCL_ICD_FILENAMES', 117 meson.current_build_dir() / 'libMesaOpenCL.so.@0@'.format(opencl_version) 118 ) 119endif 120