101e04c3fSmrg# Copyright © 2017 Intel Corporation 201e04c3fSmrg 301e04c3fSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 401e04c3fSmrg# of this software and associated documentation files (the "Software"), to deal 501e04c3fSmrg# in the Software without restriction, including without limitation the rights 601e04c3fSmrg# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 701e04c3fSmrg# copies of the Software, and to permit persons to whom the Software is 801e04c3fSmrg# furnished to do so, subject to the following conditions: 901e04c3fSmrg 1001e04c3fSmrg# The above copyright notice and this permission notice shall be included in 1101e04c3fSmrg# all copies or substantial portions of the Software. 1201e04c3fSmrg 1301e04c3fSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1401e04c3fSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1501e04c3fSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1601e04c3fSmrg# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1701e04c3fSmrg# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1801e04c3fSmrg# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 1901e04c3fSmrg# SOFTWARE. 2001e04c3fSmrg 2101e04c3fSmrgopencl_link_args = [] 2201e04c3fSmrgopencl_link_deps = [] 2301e04c3fSmrgopencl_version = '1' 2401e04c3fSmrg 2501e04c3fSmrgif with_ld_version_script 2601e04c3fSmrg opencl_link_args += [ 2701e04c3fSmrg '-Wl,--version-script', join_paths(meson.current_source_dir(), 'opencl.sym') 2801e04c3fSmrg ] 2901e04c3fSmrg opencl_link_deps += files('opencl.sym') 3001e04c3fSmrgendif 3101e04c3fSmrg 327ec681f3Smrgllvm_libdir = dep_llvm.get_variable(cmake : 'LLVM_LIBRARY_DIR', configtool: 'libdir') 3301e04c3fSmrgopencl_libname = with_opencl_icd ? 'MesaOpenCL' : 'OpenCL' 3401e04c3fSmrg 357ec681f3Smrgpolly_dep = null_dep 367ec681f3Smrgpolly_isl_dep = null_dep 377ec681f3Smrgif dep_llvm.version().version_compare('>=10.0.0') 387ec681f3Smrg polly_dep = cpp.find_library('Polly', dirs : llvm_libdir, required : false) 397ec681f3Smrg polly_isl_dep = cpp.find_library('PollyISL', dirs : llvm_libdir, required : false) 407ec681f3Smrgendif 417ec681f3Smrg 427ec681f3Smrgdep_clang = cpp.find_library('clang-cpp', dirs : llvm_libdir, required : false) 437ec681f3Smrg 447ec681f3Smrg# meson will return clang-cpp from system dirs if it's not found in llvm_libdir 457ec681f3Smrglinker_rpath_arg = '-Wl,--rpath=@0@'.format(llvm_libdir) 467ec681f3Smrgclang_test_code = ''' 477ec681f3Smrg #include <clang/Basic/Version.h> 487ec681f3Smrg int main (void) { 497ec681f3Smrg size_t found_pos = clang::getClangFullVersion().find(CLANG_VERSION_STRING); 507ec681f3Smrg return found_pos == ::std::string::npos ? 1 : 0; 517ec681f3Smrg } 527ec681f3Smrg''' 537ec681f3Smrgcan_check_clang = (not meson.is_cross_build() or meson.has_exe_wrapper()) and cpp.has_link_argument(linker_rpath_arg) 547ec681f3Smrgif can_check_clang 557ec681f3Smrg test_run = cpp.run(clang_test_code, name : 'dep-clang-usable', 567ec681f3Smrg dependencies : [dep_llvm, dep_clang], args : linker_rpath_arg) 577ec681f3Smrg dep_clang_usable = test_run.compiled() and test_run.returncode() == 0 587ec681f3Smrgelse 597ec681f3Smrg dep_clang_usable = true 607ec681f3Smrgendif 617ec681f3Smrgif not (dep_clang.found() and dep_clang_usable) 627ec681f3Smrg dep_clang = [ 6301e04c3fSmrg cpp.find_library('clangCodeGen', dirs : llvm_libdir), 6401e04c3fSmrg cpp.find_library('clangFrontendTool', dirs : llvm_libdir), 6501e04c3fSmrg cpp.find_library('clangFrontend', dirs : llvm_libdir), 6601e04c3fSmrg cpp.find_library('clangDriver', dirs : llvm_libdir), 6701e04c3fSmrg cpp.find_library('clangSerialization', dirs : llvm_libdir), 6801e04c3fSmrg cpp.find_library('clangParse', dirs : llvm_libdir), 6901e04c3fSmrg cpp.find_library('clangSema', dirs : llvm_libdir), 7001e04c3fSmrg cpp.find_library('clangAnalysis', dirs : llvm_libdir), 7101e04c3fSmrg cpp.find_library('clangAST', dirs : llvm_libdir), 727ec681f3Smrg cpp.find_library('clangASTMatchers', dirs : llvm_libdir), 7301e04c3fSmrg cpp.find_library('clangEdit', dirs : llvm_libdir), 7401e04c3fSmrg cpp.find_library('clangLex', dirs : llvm_libdir), 7501e04c3fSmrg cpp.find_library('clangBasic', dirs : llvm_libdir), 767ec681f3Smrg polly_dep, polly_isl_dep, 777ec681f3Smrg ] 787ec681f3Smrg # check clang once more 797ec681f3Smrg if can_check_clang 807ec681f3Smrg test_run = cpp.run(clang_test_code, name : 'dep-clang-usable', 817ec681f3Smrg dependencies : [dep_llvm, dep_clang], args : linker_rpath_arg) 827ec681f3Smrg if not test_run.compiled() or test_run.returncode() != 0 837ec681f3Smrg error('No usable clang found!') 847ec681f3Smrg endif 857ec681f3Smrg endif 867ec681f3Smrgendif 877ec681f3Smrg 887ec681f3Smrgocldef = files(opencl_libname + '.def')[0] 897ec681f3Smrg 907ec681f3Smrglibopencl = shared_library( 917ec681f3Smrg opencl_libname, 927ec681f3Smrg [], 937ec681f3Smrg vs_module_defs : ocldef, 947ec681f3Smrg link_args : [ld_args_gc_sections, opencl_link_args], 957ec681f3Smrg link_depends : opencl_link_deps, 967ec681f3Smrg link_whole : libclover, 977ec681f3Smrg link_with : [libpipe_loader_dynamic, libgallium], 987ec681f3Smrg dependencies : [ 997ec681f3Smrg idep_mesautil, 1007ec681f3Smrg dep_clock, dep_dl, dep_unwind, dep_elf, dep_clang, dep_version 10101e04c3fSmrg ], 10201e04c3fSmrg version : '@0@.0.0'.format(opencl_version), 10301e04c3fSmrg install : true, 10401e04c3fSmrg) 10501e04c3fSmrg 10601e04c3fSmrgif with_opencl_icd 10701e04c3fSmrg _config = configuration_data() 10801e04c3fSmrg _config.set('OPENCL_LIBNAME', 'MesaOpenCL') 10901e04c3fSmrg _config.set('OPENCL_VERSION', opencl_version) 11001e04c3fSmrg configure_file( 11101e04c3fSmrg configuration : _config, 11201e04c3fSmrg input : 'mesa.icd.in', 11301e04c3fSmrg output : 'mesa.icd', 11401e04c3fSmrg install : true, 11501e04c3fSmrg install_dir : join_paths(get_option('sysconfdir'), 'OpenCL', 'vendors'), 11601e04c3fSmrg ) 11701e04c3fSmrgendif 118