1# Copyright © 2017 Intel Corporation 2 3# Permission is hereby granted, free of charge, to any person obtaining a copy 4# of this software and associated documentation files (the "Software"), to deal 5# in the Software without restriction, including without limitation the rights 6# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7# copies of the Software, and to permit persons to whom the Software is 8# furnished to do so, subject to the following conditions: 9 10# The above copyright notice and this permission notice shall be included in 11# all copies or substantial portions of the Software. 12 13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19# SOFTWARE. 20 21opencl_link_args = [] 22opencl_link_deps = [] 23opencl_version = '1' 24 25if with_ld_version_script 26 opencl_link_args += [ 27 '-Wl,--version-script', join_paths(meson.current_source_dir(), 'opencl.sym') 28 ] 29 opencl_link_deps += files('opencl.sym') 30endif 31 32llvm_libdir = dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir') 33opencl_libname = with_opencl_icd ? 'MesaOpenCL' : 'OpenCL' 34 35polly_dep = null_dep 36polly_isl_dep = null_dep 37if dep_llvm.version().version_compare('>=10.0.0') 38 polly_dep = cpp.find_library('Polly', dirs : llvm_libdir, required : false) 39 polly_isl_dep = cpp.find_library('PollyISL', dirs : llvm_libdir, required : false) 40endif 41 42dep_clang = cpp.find_library('clang-cpp', dirs : llvm_libdir, required : false) 43 44# meson will return clang-cpp from system dirs if it's not found in llvm_libdir 45linker_rpath_arg = '-Wl,--rpath=@0@'.format(llvm_libdir) 46clang_test_code = ''' 47 #include <clang/Basic/Version.h> 48 int main (void) { 49 size_t found_pos = clang::getClangFullVersion().find(CLANG_VERSION_STRING); 50 return found_pos == ::std::string::npos ? 1 : 0; 51 } 52''' 53can_check_clang = (not meson.is_cross_build() or meson.has_exe_wrapper()) and cpp.has_link_argument(linker_rpath_arg) 54if can_check_clang 55 test_run = cpp.run(clang_test_code, name : 'dep-clang-usable', 56 dependencies : [dep_llvm, dep_clang], args : linker_rpath_arg) 57 dep_clang_usable = test_run.compiled() and test_run.returncode() == 0 58else 59 dep_clang_usable = true 60endif 61if not (dep_clang.found() and dep_clang_usable) 62 dep_clang = [ 63 cpp.find_library('clangCodeGen', dirs : llvm_libdir), 64 cpp.find_library('clangFrontendTool', dirs : llvm_libdir), 65 cpp.find_library('clangFrontend', dirs : llvm_libdir), 66 cpp.find_library('clangDriver', dirs : llvm_libdir), 67 cpp.find_library('clangSerialization', dirs : llvm_libdir), 68 cpp.find_library('clangParse', dirs : llvm_libdir), 69 cpp.find_library('clangSema', dirs : llvm_libdir), 70 cpp.find_library('clangAnalysis', dirs : llvm_libdir), 71 cpp.find_library('clangAST', dirs : llvm_libdir), 72 cpp.find_library('clangASTMatchers', dirs : llvm_libdir), 73 cpp.find_library('clangEdit', dirs : llvm_libdir), 74 cpp.find_library('clangLex', dirs : llvm_libdir), 75 cpp.find_library('clangBasic', dirs : llvm_libdir), 76 polly_dep, polly_isl_dep, 77 ] 78 # check clang once more 79 if can_check_clang 80 test_run = cpp.run(clang_test_code, name : 'dep-clang-usable', 81 dependencies : [dep_llvm, dep_clang], args : linker_rpath_arg) 82 if not test_run.compiled() or test_run.returncode() != 0 83 error('No usable clang found!') 84 endif 85 endif 86endif 87 88ocldef = files(opencl_libname + '.def')[0] 89 90libopencl = shared_library( 91 opencl_libname, 92 [], 93 vs_module_defs : ocldef, 94 link_args : [ld_args_gc_sections, opencl_link_args], 95 link_depends : opencl_link_deps, 96 link_whole : libclover, 97 link_with : [libpipe_loader_dynamic, libgallium], 98 dependencies : [ 99 idep_mesautil, 100 dep_clock, dep_dl, dep_unwind, dep_elf, dep_clang, dep_version 101 ], 102 version : '@0@.0.0'.format(opencl_version), 103 install : true, 104) 105 106if with_opencl_icd 107 _config = configuration_data() 108 _config.set('OPENCL_LIBNAME', 'MesaOpenCL') 109 _config.set('OPENCL_VERSION', opencl_version) 110 configure_file( 111 configuration : _config, 112 input : 'mesa.icd.in', 113 output : 'mesa.icd', 114 install : true, 115 install_dir : join_paths(get_option('sysconfdir'), 'OpenCL', 'vendors'), 116 ) 117endif 118