1bf215546Sopenharmony_ci# Copyright © Microsoft Corporation
2bf215546Sopenharmony_ci
3bf215546Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a
4bf215546Sopenharmony_ci# copy of this software and associated documentation files (the "Software"),
5bf215546Sopenharmony_ci# to deal in the Software without restriction, including without limitation
6bf215546Sopenharmony_ci# the rights to use, copy, modify, merge, publish, distribute, sublicense,
7bf215546Sopenharmony_ci# and/or sell copies of the Software, and to permit persons to whom the
8bf215546Sopenharmony_ci# Software is furnished to do so, subject to the following conditions:
9bf215546Sopenharmony_ci
10bf215546Sopenharmony_ci# The above copyright notice and this permission notice (including the next
11bf215546Sopenharmony_ci# paragraph) shall be included in all copies or substantial portions of the
12bf215546Sopenharmony_ci# Software.
13bf215546Sopenharmony_ci
14bf215546Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15bf215546Sopenharmony_ci# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16bf215546Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17bf215546Sopenharmony_ci# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18bf215546Sopenharmony_ci# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19bf215546Sopenharmony_ci# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20bf215546Sopenharmony_ci# IN THE SOFTWARE.
21bf215546Sopenharmony_ci
22bf215546Sopenharmony_ciclang_resource_dir = join_paths(llvm_libdir, 'clang', dep_llvm.version(), 'include')
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ciif dep_llvm.version().version_compare('< 15.0')
25bf215546Sopenharmony_ci  opencl_c_h = custom_target(
26bf215546Sopenharmony_ci    'opencl-c.h',
27bf215546Sopenharmony_ci    input : [files_xxd, join_paths(clang_resource_dir, 'opencl-c.h')],
28bf215546Sopenharmony_ci    output : 'opencl-c.h.h',
29bf215546Sopenharmony_ci    command : [prog_python, '@INPUT@', '@OUTPUT@', '-n', 'opencl_c_source'],
30bf215546Sopenharmony_ci  )
31bf215546Sopenharmony_ciendif
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ciopencl_c_base_h = custom_target(
34bf215546Sopenharmony_ci  'opencl-c-base.h',
35bf215546Sopenharmony_ci  input : [files_xxd, join_paths(clang_resource_dir, 'opencl-c-base.h')],
36bf215546Sopenharmony_ci  output : 'opencl-c-base.h.h',
37bf215546Sopenharmony_ci  command : [prog_python, '@INPUT@', '@OUTPUT@', '-n', 'opencl_c_base_source'],
38bf215546Sopenharmony_ci)
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci_libclc_sources = [opencl_c_base_h]
41bf215546Sopenharmony_ciif dep_llvm.version().version_compare('< 15.0')
42bf215546Sopenharmony_ci  _libclc_sources += [opencl_c_h]
43bf215546Sopenharmony_ciendif
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_cifiles_libclc = files(
46bf215546Sopenharmony_ci  'clc.c',
47bf215546Sopenharmony_ci  'clc_helpers.cpp',
48bf215546Sopenharmony_ci)
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci_libclc_cpp_args = ['-DCLANG_RESOURCE_DIR="@0@"'.format(clang_resource_dir)]
51bf215546Sopenharmony_ciif with_microsoft_clc
52bf215546Sopenharmony_ci  _libclc_cpp_args += ['-DUSE_STATIC_OPENCL_C_H=1']
53bf215546Sopenharmony_ciendif
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci# Supported added for SPIRV 1.4 in a version that required LLVM 14.
56bf215546Sopenharmony_ciif dep_llvm.version().version_compare('>= 14.0')
57bf215546Sopenharmony_ci  _libclc_cpp_args += ['-DHAS_SPIRV_1_4=1']
58bf215546Sopenharmony_ciendif
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci_libclc = static_library(
61bf215546Sopenharmony_ci  'libclc',
62bf215546Sopenharmony_ci  files_libclc,
63bf215546Sopenharmony_ci  sources: _libclc_sources,
64bf215546Sopenharmony_ci  include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_compiler, inc_spirv],
65bf215546Sopenharmony_ci  cpp_args : _libclc_cpp_args,
66bf215546Sopenharmony_ci  dependencies: [idep_nir_headers, dep_clang, dep_llvm, dep_llvmspirvlib,
67bf215546Sopenharmony_ci                 idep_mesautil, idep_nir, dep_spirv_tools]
68bf215546Sopenharmony_ci)
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ciidep_clc = declare_dependency(
71bf215546Sopenharmony_ci  link_with : _libclc,
72bf215546Sopenharmony_ci  include_directories : include_directories('.'),
73bf215546Sopenharmony_ci)
74