1# Copyright © Microsoft Corporation 2# SPDX-License-Identifier: MIT 3 4files_libmesaclc = files( 5 'clc.c', 6 'clc_helpers.cpp', 7 'nir_load_libclc.c', 8) 9 10_libmesaclc_c_args = [] 11_libmesaclc_cpp_args = ['-DLLVM_LIB_DIR="@0@"'.format(llvm_libdir)] 12_libmesaclc_sources = [] 13 14if not _shared_llvm 15 # LLVM 16 moved clang header path from using full version to only major version 16 if dep_llvm.version().version_compare('< 16') 17 # Prior to LLVM 16, this path used a full version 18 clang_version_dir = dep_llvm.version() 19 else 20 # LLVM 16 changed to only using a major version 21 clang_version_dir = dep_llvm.version().split('.')[0] 22 endif 23 clang_resource_dir = join_paths(llvm_libdir, 'clang', clang_version_dir, 'include') 24 25 opencl_c_base_h = custom_target( 26 'opencl-c-base.h', 27 input : [files_xxd, join_paths(clang_resource_dir, 'opencl-c-base.h')], 28 output : 'opencl-c-base.h.h', 29 command : [prog_python, '@INPUT@', '@OUTPUT@', '-n', 'opencl_c_base_source'], 30 ) 31 32 opencl_c_h = custom_target( 33 'opencl-c.h', 34 input : [files_xxd, join_paths(clang_resource_dir, 'opencl-c.h')], 35 output : 'opencl-c.h.h', 36 command : [prog_python, '@INPUT@', '@OUTPUT@', '-n', 'opencl_c_source'], 37 ) 38 39 _libmesaclc_sources += [opencl_c_base_h, opencl_c_h] 40 _libmesaclc_cpp_args += ['-DUSE_STATIC_OPENCL_C_H=1'] 41endif 42 43_basedir = dep_clc.get_variable(pkgconfig : 'libexecdir') 44 45_static_libclc = get_option('static-libclc') 46if _static_libclc.length() > 0 47 if _static_libclc.contains('all') 48 _static_libclc = ['spirv', 'spirv64'] 49 endif 50 prog_zstd = find_program('zstd', required : false, native : true) 51 _zstd_static_libclc = dep_zstd.found() and prog_zstd.found() 52 if _zstd_static_libclc 53 _libmesaclc_c_args += '-DHAVE_STATIC_LIBCLC_ZSTD' 54 endif 55 foreach s : _static_libclc 56 _libmesaclc_c_args += '-DHAVE_STATIC_LIBCLC_@0@'.format(s.to_upper()) 57 f = '@[email protected]'.format(s) 58 _libclc_file = _basedir / f 59 if _zstd_static_libclc 60 _libclc_file = custom_target( 61 '@[email protected]'.format(f), 62 command : [prog_zstd, '-f', '@INPUT@', '-o', '@OUTPUT@'], 63 input : [_libclc_file], 64 output : '@[email protected]'.format(f), 65 ) 66 endif 67 files_libmesaclc += custom_target( 68 '@[email protected]'.format(f), 69 command : [ 70 prog_python, files_xxd, '-b', '@INPUT@', '@OUTPUT@', 71 '-n', 'libclc_@0@_mesa3d_spv'.format(s), 72 ], 73 input : [_libclc_file], 74 output : '@[email protected]'.format(f), 75 depend_files : files_xxd, 76 ) 77 endforeach 78else 79 _libmesaclc_c_args += ['-DDYNAMIC_LIBCLC_PATH="@0@/"'.format(_basedir)] 80 if not cc.has_function('mmap') 81 error('mmap required for dynamic libCLC loading') 82 endif 83endif 84 85has_spirv_link_workaround = cpp.has_member( 86 'spvtools::LinkerOptions', 87 'SetAllowPtrTypeMismatch(true)', 88 prefix : [ 89 '#include <spirv-tools/linker.hpp>', 90 ], 91 dependencies : dep_spirv_tools, 92) 93 94if has_spirv_link_workaround 95 _libmesaclc_c_args += ['-DHAS_SPIRV_LINK_LLVM_WORKAROUND=1'] 96endif 97 98_libmesaclc = static_library( 99 'libmesaclc', 100 files_libmesaclc, 101 sources: _libmesaclc_sources, 102 include_directories : [inc_include, inc_src, inc_spirv], 103 c_args : _libmesaclc_c_args, 104 cpp_args : [_libmesaclc_cpp_args, _libmesaclc_c_args], 105 dependencies: [idep_nir, dep_clang, dep_llvm, dep_llvmspirvlib, 106 idep_mesautil, dep_spirv_tools, idep_vtn] 107) 108 109_idep_mesaclc_link_args = [] 110if _shared_llvm 111 _idep_mesaclc_link_args += cc.get_supported_link_arguments('-fPIC') 112endif 113 114idep_mesaclc = declare_dependency( 115 link_with : _libmesaclc, 116 include_directories : include_directories('.'), 117 link_args : _idep_mesaclc_link_args, 118) 119