• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright © Microsoft Corporation
2
3# Permission is hereby granted, free of charge, to any person obtaining a
4# copy of this software and associated documentation files (the "Software"),
5# to deal in the Software without restriction, including without limitation
6# the rights to use, copy, modify, merge, publish, distribute, sublicense,
7# and/or sell copies of the Software, and to permit persons to whom the
8# Software is furnished to do so, subject to the following conditions:
9
10# The above copyright notice and this permission notice (including the next
11# paragraph) shall be included in all copies or substantial portions of the
12# Software.
13
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20# IN THE SOFTWARE.
21
22
23files_libmesaclc = files(
24  'clc.c',
25  'clc_helpers.cpp',
26  'nir_load_libclc.c',
27)
28
29_libmesaclc_c_args = []
30_libmesaclc_cpp_args = ['-DLLVM_LIB_DIR="@0@"'.format(llvm_libdir)]
31_libmesaclc_sources = []
32
33if not _shared_llvm
34  # LLVM 16 moved clang header path from using full version to only major version
35  if dep_llvm.version().version_compare('< 16')
36    # Prior to LLVM 16, this path used a full version
37    clang_version_dir = dep_llvm.version()
38  else
39    # LLVM 16 changed to only using a major version
40    clang_version_dir = dep_llvm.version().split('.')[0]
41  endif
42  clang_resource_dir = join_paths(llvm_libdir, 'clang', clang_version_dir, 'include')
43
44  opencl_c_base_h = custom_target(
45    'opencl-c-base.h',
46    input : [files_xxd, join_paths(clang_resource_dir, 'opencl-c-base.h')],
47    output : 'opencl-c-base.h.h',
48    command : [prog_python, '@INPUT@', '@OUTPUT@', '-n', 'opencl_c_base_source'],
49  )
50
51  opencl_c_h = custom_target(
52    'opencl-c.h',
53    input : [files_xxd, join_paths(clang_resource_dir, 'opencl-c.h')],
54    output : 'opencl-c.h.h',
55    command : [prog_python, '@INPUT@', '@OUTPUT@', '-n', 'opencl_c_source'],
56  )
57
58  _libmesaclc_sources += [opencl_c_base_h, opencl_c_h]
59  _libmesaclc_cpp_args += ['-DUSE_STATIC_OPENCL_C_H=1']
60endif
61
62_basedir = dep_clc.get_variable(pkgconfig : 'libexecdir')
63
64_static_libclc = get_option('static-libclc')
65if _static_libclc.length() > 0
66  if _static_libclc.contains('all')
67    _static_libclc = ['spirv', 'spirv64']
68  endif
69  prog_zstd = find_program('zstd', required : false, native : true)
70  _zstd_static_libclc = dep_zstd.found() and prog_zstd.found()
71  if _zstd_static_libclc
72    _libmesaclc_c_args += '-DHAVE_STATIC_LIBCLC_ZSTD'
73  endif
74  foreach s : _static_libclc
75    _libmesaclc_c_args += '-DHAVE_STATIC_LIBCLC_@0@'.format(s.to_upper())
76    f = '@0@-mesa3d-.spv'.format(s)
77    _libclc_file = _basedir / f
78    if _zstd_static_libclc
79      _libclc_file = custom_target(
80        '@0@.zstd'.format(f),
81        command : [prog_zstd, '-f', '@INPUT@', '-o', '@OUTPUT@'],
82        input : [_libclc_file],
83        output : '@0@.zstd'.format(f),
84      )
85    endif
86    files_libmesaclc += custom_target(
87      '@0@.h'.format(f),
88      command : [
89        prog_python, files_xxd, '-b', '@INPUT@', '@OUTPUT@',
90        '-n', 'libclc_@0@_mesa3d_spv'.format(s),
91      ],
92      input : [_libclc_file],
93      output : '@0@.h'.format(f),
94      depend_files : files_xxd,
95    )
96  endforeach
97else
98  _libmesaclc_c_args += ['-DDYNAMIC_LIBCLC_PATH="@0@/"'.format(_basedir)]
99  if not cc.has_function('mmap')
100    error('mmap required for dynamic libCLC loading')
101  endif
102endif
103
104_libmesaclc = static_library(
105  'libmesaclc',
106  files_libmesaclc,
107  sources: _libmesaclc_sources,
108  include_directories : [inc_include, inc_src, inc_spirv],
109  c_args : _libmesaclc_c_args,
110  cpp_args : [_libmesaclc_cpp_args, _libmesaclc_c_args],
111  dependencies: [idep_nir, dep_clang, dep_llvm, dep_llvmspirvlib,
112                 idep_mesautil, dep_spirv_tools, idep_vtn]
113)
114
115_idep_mesaclc_link_args = []
116if _shared_llvm
117  _idep_mesaclc_link_args += cc.get_supported_link_arguments('-fPIC')
118endif
119
120idep_mesaclc = declare_dependency(
121  link_with : _libmesaclc,
122  include_directories : include_directories('.'),
123  link_args : _idep_mesaclc_link_args,
124)
125